Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T-005: Generate the timestamp in the specified format and ensure it's in GMT/UTC #14

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Api/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function sendRequest(
string $endpoint,
array $data = []
): mixed {
$dateTime = new DateTime('now', new DateTimeZone('America/New_York'));
$timestamp = $dateTime->format('c');
// Generate the timestamp in the specified format and ensure it's in GMT/UTC
$timestamp = gmdate('Y-m-d\TH:i:s');
$authKey = $this->generateAuthHmac($timestamp, $this->apiSecurityKey);
$hashedPassword = $this->generateAuthHmac($this->apiPassword, $authKey);

Expand All @@ -88,7 +88,6 @@ public function sendRequest(
'User' => $this->apiUser,
'Password' => $hashedPassword,
], $data);

try {
$response = $this->client->request($method, $endpoint, [
'json' => $data,
Expand Down
8 changes: 4 additions & 4 deletions tests/Api/ApiClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public function testWSLoginSuccess() {

// Use PHPUnit assertions to check for successful login
// Display the response for debugging purposes
// (usually done during development only)
// (usually done during development only).
echo "Response: ";
var_dump($response);

// Assert the response indicates a successful login
// Assert the response indicates a successful login.
$this->assertArrayHasKey(
'AccessCode', $response, "Response does not contain AccessCode"
);
Expand All @@ -48,7 +48,7 @@ public function testWSLoginSuccess() {
// In production or CI environments, it might be better to log this error
// or handle it accordingly.
echo "Error during WSLogin request: ".$e->getMessage();
// Fail the test if an exception is caught
// Fail the test if an exception is caught.
$this->fail(
"WSLogin request failed with an exception: ".$e->getMessage()
);
Expand All @@ -66,7 +66,7 @@ public function testWSLoginFailure() {
'Password' => 'incorrectPassword',
]);

// Debugging output (use sparingly)
// Debugging output (use sparingly).
echo "Response: ";
var_dump($response);

Expand Down
Loading