Skip to content

Commit

Permalink
Merge pull request #83 from stackkit/master
Browse files Browse the repository at this point in the history
3.x
  • Loading branch information
marickvantuil authored Nov 19, 2022
2 parents c4664b3 + dee9d6b commit eebe0d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ public static function getHandler($handler): string
));
}

// When the application is running behind a proxy and the TrustedProxy middleware has not been set up yet,
// an error like [HttpRequest.url must start with 'https'] could be thrown. Since the handler URL must
// always be https, we will provide a little extra information on how to fix this.
if ($parse['scheme'] !== 'https') {
throw new Exception(sprintf(
'Unable to push task to Cloud Tasks because the hander URL is not https. Google Cloud Tasks ' .
'will only call safe (https) URLs. If you are running Laravel behind a proxy (e.g. Ngrok, Expose), make sure it is ' .
'as a trusted proxy. To quickly fix this, add the following to the [app/Http/Middleware/TrustProxies] middleware: ' .
'protected $proxies = \'*\';'
));
}

// Versions 1.x and 2.x required the full path (e.g. my-app.com/handle-task). In 3.x and beyond
// it is no longer necessary to also include the path and simply setting the handler
// URL is enough. If someone upgrades and forgets we will warn them here.
Expand Down
6 changes: 3 additions & 3 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function a_http_request_with_the_handler_url_is_made()

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8080/handle-task';
return $task->getHttpRequest()->getUrl() === 'https://docker.for.mac.localhost:8080/handle-task';
});
}

Expand All @@ -69,15 +69,15 @@ public function it_posts_to_the_handler()
public function it_posts_to_the_correct_handler_url()
{
// Arrange
$this->setConfigValue('handler', 'http://docker.for.mac.localhost:8081');
$this->setConfigValue('handler', 'https://docker.for.mac.localhost:8081');
CloudTasksApi::fake();

// Act
$this->dispatch(new SimpleJob());

// Assert
CloudTasksApi::assertTaskCreated(function (Task $task): bool {
return $task->getHttpRequest()->getUrl() === 'http://docker.for.mac.localhost:8081/handle-task';
return $task->getHttpRequest()->getUrl() === 'https://docker.for.mac.localhost:8081/handle-task';
});
}

Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function getEnvironmentSetUp($app)
'queue' => 'barbequeue',
'project' => 'my-test-project',
'location' => 'europe-west6',
'handler' => env('CLOUD_TASKS_HANDLER', 'http://docker.for.mac.localhost:8080'),
'handler' => env('CLOUD_TASKS_HANDLER', 'https://docker.for.mac.localhost:8080'),
'service_account_email' => '[email protected]',
]);
$app['config']->set('queue.failed.driver', 'database-uuids');
Expand Down Expand Up @@ -216,7 +216,7 @@ protected function addIdTokenToHeader(?Closure $closure = null): void
{
$base = [
'iss' => 'https://accounts.google.com',
'aud' => 'http://docker.for.mac.localhost:8080',
'aud' => 'https://docker.for.mac.localhost:8080',
'exp' => time() + 10,
];

Expand Down

0 comments on commit eebe0d6

Please sign in to comment.