2020-09-28 17:18:21 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHP version 7.3
|
|
|
|
*
|
|
|
|
* @category RequestSigner
|
|
|
|
* @package RetailCrm\Tests\Service
|
|
|
|
* @author RetailCRM <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see http://help.retailcrm.ru
|
|
|
|
*/
|
|
|
|
namespace RetailCrm\Tests\Service;
|
|
|
|
|
|
|
|
use RetailCrm\Component\AppData;
|
|
|
|
use RetailCrm\Component\Constants;
|
|
|
|
use RetailCrm\Interfaces\AppDataInterface;
|
|
|
|
use RetailCrm\Interfaces\RequestSignerInterface;
|
|
|
|
use RetailCrm\Test\TestCase;
|
|
|
|
use RetailCrm\Test\TestSignerRequest;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RequestSigner
|
|
|
|
*
|
|
|
|
* @category RequestSigner
|
|
|
|
* @package RetailCrm\Tests\Service
|
|
|
|
* @author RetailDriver LLC <integration@retailcrm.ru>
|
|
|
|
* @license MIT
|
|
|
|
* @link http://retailcrm.ru
|
|
|
|
* @see https://help.retailcrm.ru
|
|
|
|
*/
|
|
|
|
class RequestSignerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider signDataProvider
|
|
|
|
*
|
|
|
|
* @param \RetailCrm\Test\TestSignerRequest $request
|
|
|
|
* @param \RetailCrm\Interfaces\AppDataInterface $appData
|
|
|
|
* @param string $expectedHash
|
|
|
|
*/
|
|
|
|
public function testSign(TestSignerRequest $request, AppDataInterface $appData, string $expectedHash): void
|
|
|
|
{
|
|
|
|
/** @var RequestSignerInterface $signer */
|
2020-09-29 15:18:03 +03:00
|
|
|
$signer = $this->getContainer()->get(RequestSignerInterface::class);
|
2020-09-28 17:18:21 +03:00
|
|
|
$signer->sign($request, $appData);
|
|
|
|
|
|
|
|
self::assertEquals($expectedHash, $request->sign);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function signDataProvider(): array
|
|
|
|
{
|
2020-09-29 13:10:54 +03:00
|
|
|
$appData = $this->getAppData();
|
2020-09-28 17:18:21 +03:00
|
|
|
|
|
|
|
return [
|
|
|
|
[
|
2020-09-29 13:10:54 +03:00
|
|
|
$this->getTestRequest(Constants::SIGN_TYPE_MD5),
|
2020-09-28 17:18:21 +03:00
|
|
|
$appData,
|
2020-09-30 17:50:44 +03:00
|
|
|
'468BF7C95925C187D0DFD7D042072EB4'
|
2020-09-28 17:18:21 +03:00
|
|
|
],
|
|
|
|
[
|
2020-09-29 13:10:54 +03:00
|
|
|
$this->getTestRequest(Constants::SIGN_TYPE_HMAC),
|
|
|
|
$appData,
|
2020-09-30 17:50:44 +03:00
|
|
|
'5EF5C76D5C158BFFA9F35BAAA712A879'
|
2020-09-29 13:10:54 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
$this->getTestRequest(Constants::SIGN_TYPE_MD5, true),
|
|
|
|
$appData,
|
2020-09-30 17:50:44 +03:00
|
|
|
'468BF7C95925C187D0DFD7D042072EB4'
|
2020-09-29 13:10:54 +03:00
|
|
|
],
|
|
|
|
[
|
|
|
|
$this->getTestRequest(Constants::SIGN_TYPE_HMAC, true),
|
2020-09-28 17:18:21 +03:00
|
|
|
$appData,
|
2020-09-30 17:50:44 +03:00
|
|
|
'5EF5C76D5C158BFFA9F35BAAA712A879'
|
2020-09-28 17:18:21 +03:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|