diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 5e3d3900d7..2f24001acc 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2252,7 +2252,7 @@ Http::post('/v1/account/tokens/magic-url') ->inject('proofForPassword') ->inject('platform') ->inject('authorization') - ->action(function (string $userId, string $email, string $url, bool $phrase, Request $request, Response $response, Document $user, Document $project, Database $dbForProject, Locale $locale, Event $queueForEvents, MailPublisher $publisherForMails, array $plan, ProofsPassword $proofForPassword, array $platform, Authorization $authorization) { + ->action(function (string $userId, string $email, string $url, bool $phrase, Request $request, Response $response, Document $user, Document $project, Database $dbForProject, Locale $locale, Event $queueForEvents, MailPublisher $publisherForMails, array $plan, ProofsPassword $proofForPassword, array $platform, Authorization $authorization) use ($legacyConsolePaths) { if (empty(System::getEnv('_APP_SMTP_HOST'))) { throw new Exception(Exception::GENERAL_SMTP_DISABLED, 'SMTP disabled'); } @@ -2398,7 +2398,7 @@ Http::post('/v1/account/tokens/magic-url') } elseif ($protocol === 'http' && $port !== '80') { $callbackBase .= ':' . $port; } - $url = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root' + $url = $legacyConsolePaths ? "{$callbackBase}/console/auth/magic-url" : "{$callbackBase}/auth/magic-url"; } diff --git a/tests/unit/Platform/Workers/WebhooksTest.php b/tests/unit/Platform/Workers/WebhooksTest.php index 9065aef41c..636ca0d899 100644 --- a/tests/unit/Platform/Workers/WebhooksTest.php +++ b/tests/unit/Platform/Workers/WebhooksTest.php @@ -32,7 +32,7 @@ final class WebhooksTest extends TestCase $publisherForNotifications = new NotificationPublisher($publisher, new Queue('v1-notifications')); $worker = new Webhooks(); - $worker->sendAlert( + $this->withConsoleUrlScheme('legacy', fn () => $worker->sendAlert( attempts: 10, statusCode: 500, webhook: new Document([ @@ -51,7 +51,7 @@ final class WebhooksTest extends TestCase dbForPlatform: $database, publisherForNotifications: $publisherForNotifications, plan: [] - ); + )); $events = $publisher->getEvents('v1-notifications'); @@ -105,32 +105,26 @@ final class WebhooksTest extends TestCase $publisherForNotifications = new NotificationPublisher($publisher, new Queue('v1-notifications')); $worker = new Webhooks(); - \putenv('_APP_CONSOLE_URL_SCHEME=root'); - - try { - $worker->sendAlert( - attempts: 10, - statusCode: 500, - webhook: new Document([ - '$id' => 'webhook-1', - '$updatedAt' => '2026-01-01T00:00:00.000+00:00', - 'name' => 'Payments', - 'url' => 'https://example.test/webhook', - ]), - project: new Document([ - '$id' => 'project-1', - '$sequence' => 'project-internal-1', - 'name' => 'Production', - 'teamInternalId' => 'team-internal-1', - 'region' => 'fra', - ]), - dbForPlatform: $database, - publisherForNotifications: $publisherForNotifications, - plan: [] - ); - } finally { - \putenv('_APP_CONSOLE_URL_SCHEME'); - } + $this->withConsoleUrlScheme('root', fn () => $worker->sendAlert( + attempts: 10, + statusCode: 500, + webhook: new Document([ + '$id' => 'webhook-1', + '$updatedAt' => '2026-01-01T00:00:00.000+00:00', + 'name' => 'Payments', + 'url' => 'https://example.test/webhook', + ]), + project: new Document([ + '$id' => 'project-1', + '$sequence' => 'project-internal-1', + 'name' => 'Production', + 'teamInternalId' => 'team-internal-1', + 'region' => 'fra', + ]), + dbForPlatform: $database, + publisherForNotifications: $publisherForNotifications, + plan: [] + )); $events = $publisher->getEvents('v1-notifications'); @@ -266,6 +260,18 @@ final class WebhooksTest extends TestCase yield 'invalid roles' => [null, false]; } + private function withConsoleUrlScheme(string $scheme, callable $callback): void + { + $original = \getenv('_APP_CONSOLE_URL_SCHEME'); + \putenv("_APP_CONSOLE_URL_SCHEME={$scheme}"); + + try { + $callback(); + } finally { + \putenv($original === false ? '_APP_CONSOLE_URL_SCHEME' : "_APP_CONSOLE_URL_SCHEME={$original}"); + } + } + private function createPlatformDatabase(): Database { $authorization = new Authorization();