Skip to content
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
2 changes: 1 addition & 1 deletion app/Http/Middleware/VerifyHMAC.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function handle(Request $request, Closure $next) {
abort(Response::HTTP_UNAUTHORIZED, 'Unauthorized.');
}

$datetime = $request->header('X-Time');
$datetime = $request->header('X-Timestamp');
if (empty($datetime)) {
abort(Response::HTTP_UNAUTHORIZED, 'Unauthorized.');
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/Public/Middleware/VerifyHMACTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function aborts_without_timestamp(): void {
public function aborts_with_garbage_timestamp(): void {
$response = $this->post(route('hook.health'), [], [
'X-Signature' => 'some-signature',
'X-Time' => 'not-a-timestamp',
'X-Timestamp' => 'not-a-timestamp',
]);

$response->assertStatus(Response::HTTP_UNAUTHORIZED);
Expand All @@ -44,7 +44,7 @@ public function aborts_with_garbage_timestamp(): void {
public function aborts_with_expired_timestamp(): void {
$response = $this->post(route('hook.health'), [], [
'X-Signature' => 'some-signature',
'X-Time' => Carbon::now('UTC')->subMinutes(VerifyHMAC::VALID_MINUTES)->toIso8601String(),
'X-Timestamp' => Carbon::now('UTC')->subMinutes(VerifyHMAC::VALID_MINUTES)->toIso8601String(),
]);

$response->assertStatus(Response::HTTP_UNAUTHORIZED);
Expand All @@ -54,7 +54,7 @@ public function aborts_with_expired_timestamp(): void {
public function aborts_with_future_timestamp(): void {
$response = $this->post(route('hook.health'), [], [
'X-Signature' => 'some-signature',
'X-Time' => Carbon::now('UTC')->addSeconds(VerifyHMAC::VALID_SECONDS + 5)->toIso8601String(),
'X-Timestamp' => Carbon::now('UTC')->addSeconds(VerifyHMAC::VALID_SECONDS + 5)->toIso8601String(),
]);

$response->assertStatus(Response::HTTP_UNAUTHORIZED);
Expand All @@ -64,7 +64,7 @@ public function aborts_with_future_timestamp(): void {
public function aborts_with_invalid_signature(): void {
$response = $this->post(route('hook.health'), [], [
'X-Signature' => 'some-signature',
'X-Time' => Carbon::now('UTC')->toIso8601String(),
'X-Timestamp' => Carbon::now('UTC')->toIso8601String(),
]);

$response->assertStatus(Response::HTTP_UNAUTHORIZED);
Expand All @@ -82,7 +82,7 @@ public function aborts_with_tampered_signature(): void {

$response = $this->post($url, ['invalid' => 'data'], [
'X-Signature' => $signature,
'X-Time' => $datetime,
'X-Timestamp' => $datetime,
]);

$response->assertStatus(Response::HTTP_UNAUTHORIZED);
Expand All @@ -101,7 +101,7 @@ public function validates_valid_post_request(): void {

$response = $this->post($url, $payload, [
'X-Signature' => $signature,
'X-Time' => $datetime,
'X-Timestamp' => $datetime,
]);

$response->assertStatus(Response::HTTP_OK);
Expand All @@ -121,7 +121,7 @@ public function validates_valid_get_request(): void {

$response = $this->get($url . '?' . http_build_query($payload), [
'X-Signature' => $signature,
'X-Time' => $datetime,
'X-Timestamp' => $datetime,
]);

$response->assertStatus(Response::HTTP_OK);
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Public/WebhooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function db_backup_route_calls_backup_command(): void {
$signature = VerifyHMAC::generateHMAC($url, $datetime, []);
$response = $this->post($url, [], [
'X-Signature' => $signature,
'X-Time' => $datetime,
'X-Timestamp' => $datetime,
]);

$response->assertStatus(Response::HTTP_OK);
Expand Down