Skip to content

Commit 053f122

Browse files
committed
Fix 'audience does not match'
1 parent 9b8368c commit 053f122

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/CloudTasksQueue.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected function pushToCloudTasks($queue, $payload, $delay = 0)
101101
$availableAt = $this->availableAt($delay);
102102

103103
$httpRequest = $this->createHttpRequest();
104-
$httpRequest->setUrl(Config::getHandler($this->config['handler']));
104+
$httpRequest->setUrl($this->getHandler());
105105
$httpRequest->setHttpMethod(HttpMethod::POST);
106106
$httpRequest->setBody(
107107
// Laravel 7+ jobs have a uuid, but Laravel 6 doesn't have it.
@@ -183,4 +183,9 @@ private function createTask(): Task
183183
{
184184
return app(Task::class);
185185
}
186+
187+
public function getHandler(): string
188+
{
189+
return Config::getHandler($this->config['handler']);
190+
}
186191
}

src/OpenIdVerificatorConcrete.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function verify(?string $token, array $config): void
1818
(new AccessToken())->verify(
1919
$token,
2020
[
21-
'audience' => $config['handler'],
21+
'audience' => app('queue')->getHandler(),
2222
'throwException' => true,
2323
]
2424
);

src/OpenIdVerificatorFake.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function verify(?string $token, array $config): void
1717
(new AccessToken())->verify(
1818
$token,
1919
[
20-
'audience' => $config['handler'],
20+
'audience' => app('queue')->getHandler(),
2121
'throwException' => true,
2222
'certsLocation' => __DIR__ . '/../tests/Support/self-signed-public-key-as-jwk.json',
2323
]

tests/QueueTest.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function a_http_request_with_the_handler_url_is_made()
2525

2626
// Assert
2727
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
28-
return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8080';
28+
return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8080/handle-task';
2929
});
3030
}
3131

@@ -46,6 +46,24 @@ public function it_posts_to_the_handler()
4646
});
4747
}
4848

49+
/**
50+
* @test
51+
*/
52+
public function it_posts_to_the_correct_handler_url()
53+
{
54+
// Arrange
55+
$this->setConfigValue('handler', 'http://docker.for.mac.localhost:8081');
56+
CloudTasksApi::fake();
57+
58+
// Act
59+
$this->dispatch(new SimpleJob());
60+
61+
// Assert
62+
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
63+
return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8081/handle-task';
64+
});
65+
}
66+
4967
/**
5068
* @test
5169
*/

0 commit comments

Comments
 (0)