Skip to content

Commit

Permalink
add X-Ca-Stage support
Browse files Browse the repository at this point in the history
  • Loading branch information
IonBazan committed Apr 28, 2020
1 parent 5f33294 commit dfd3d50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/tests export-ignore
/.github export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs.dist export-ignore
phpunit.xml.dist export-ignore
6 changes: 4 additions & 2 deletions src/RequestSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ class RequestSigner
public const HEADER_X_CA_SIGNATURE_METHOD = 'X-Ca-SignatureMethod';
public const HEADER_X_CA_SIGNATURE_HEADERS = 'X-Ca-Signature-Headers';
public const HEADER_X_CA_TIMESTAMP = 'X-Ca-Timestamp';
public const HEADER_DATE = 'Date';
public const HEADER_CONTENT_MD5 = 'Content-MD5';
public const HEADER_X_CA_NONCE = 'X-Ca-Nonce';
public const HEADER_X_CA_KEY = 'X-Ca-Key';
public const HEADER_X_CA_STAGE = 'X-Ca-Stage';
public const HEADER_DATE = 'Date';
public const HEADER_CONTENT_MD5 = 'Content-MD5';

/** @var Key */
private $key;
Expand All @@ -33,6 +34,7 @@ class RequestSigner
self::HEADER_X_CA_NONCE,
self::HEADER_X_CA_SIGNATURE_METHOD,
self::HEADER_X_CA_TIMESTAMP,
self::HEADER_X_CA_STAGE,
];

public function __construct(Key $key, ?DigestInterface $digest = null)
Expand Down
12 changes: 9 additions & 3 deletions tests/RequestSignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,27 @@ public function requestDataProvider(): array
];
}

public function testRequestSignatureWithFixedNonceAndDate(): void
public function testRequestSignatureWithFixedNonceAndDateWithStage(): void
{
$requestSigner = new RequestSigner(new Key('1234', '5678'));
$request = new Request(
'https://example.com/v1.0/category/123/products?page=10',
'GET',
'php://memory',
['Accept' => '*/*', 'Content-Type' => 'application/json']
[
'Accept' => '*/*',
'Content-Type' => 'application/json',
'X-Ca-Stage' => 'test',
]
);
$signedRequest = $requestSigner->signRequest($request, new DateTime('2020-04-30'), '');
$this->assertSignedRequest(
$signedRequest,
'',
1588204800000,
'YqDp37hUo5bxAL7lg53iabau7qhMYRMCwQKklZpZuMc='
'VoQMES7AM9S8GpXH8xMi9kl7E5/Xb4wsdL+jhNTnO08=',
'',
'x-ca-key,x-ca-nonce,x-ca-signaturemethod,x-ca-stage,x-ca-timestamp'
);
}

Expand Down

0 comments on commit dfd3d50

Please sign in to comment.