diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Callback/Base.php b/src/Appwrite/Platform/Modules/VCS/Http/Callback/Base.php index 55f9ee1d2f..1b5d697c1d 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Callback/Base.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Callback/Base.php @@ -101,13 +101,12 @@ abstract class Base extends Action return; } - $region = $project->getAttribute('region', 'default'); $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; $hostname = $platform['consoleHostname'] ?? ''; $defaultState = [ - 'success' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations", - 'failure' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations", + 'success' => ($platform['consoleUrl'] ?? '') . "/projects/$projectId/settings", + 'failure' => ($platform['consoleUrl'] ?? '') . "/projects/$projectId/settings", ]; $redirectSuccess = empty($state['success']) ? $defaultState['success'] : $state['success']; diff --git a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php index eb53da9857..2b17642924 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/GitHub/Callback/Get.php @@ -98,13 +98,9 @@ class Get extends Action throw new Exception(Exception::PROJECT_NOT_FOUND, $error); } - $region = $project->getAttribute('region', 'default'); - $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; - $hostname = $platform['consoleHostname'] ?? ''; - $defaultState = [ - 'success' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations", - 'failure' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations", + 'success' => ($platform['consoleUrl'] ?? '') . "/projects/$projectId/settings", + 'failure' => ($platform['consoleUrl'] ?? '') . "/projects/$projectId/settings", ]; $redirectSuccess = empty($state['success']) ? $defaultState['success'] : $state['success']; diff --git a/src/Appwrite/Platform/Modules/VCS/Http/Origin/Callback/Get.php b/src/Appwrite/Platform/Modules/VCS/Http/Origin/Callback/Get.php index 9488a34343..5ed3364133 100644 --- a/src/Appwrite/Platform/Modules/VCS/Http/Origin/Callback/Get.php +++ b/src/Appwrite/Platform/Modules/VCS/Http/Origin/Callback/Get.php @@ -104,13 +104,9 @@ class Get extends Action return; } - $region = $project->getAttribute('region', 'default'); - $protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https'; - $hostname = $platform['consoleHostname'] ?? ''; - $defaultState = [ - 'success' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations", - 'failure' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations", + 'success' => ($platform['consoleUrl'] ?? '') . "/projects/$projectId/settings", + 'failure' => ($platform['consoleUrl'] ?? '') . "/projects/$projectId/settings", ]; $state = \array_merge($defaultState, \array_filter($state)); diff --git a/tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php b/tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php index baa2805529..8db0756915 100644 --- a/tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php +++ b/tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php @@ -238,7 +238,7 @@ final class VCSGiteaConsoleClientTest extends Scope /** @var array $cookies */ $cookies = []; $this->giteaCookies = $cookies; - $consoleUrl = $this->gitInstallationsUrl($projectId); + $consoleUrl = $this->settingsUrl($projectId); $authorize = $this->client->call(Client::METHOD_GET, '/vcs/gitea/authorize', \array_merge([ 'x-appwrite-project' => $projectId, @@ -490,7 +490,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithTamperedState(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = $this->gitInstallationsUrl($projectId); + $consoleUrl = $this->settingsUrl($projectId); $state = \json_decode($this->buildGiteaState($projectId, $consoleUrl, $consoleUrl), true); $state['projectId'] = 'victim-project'; @@ -506,7 +506,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithoutCode(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = $this->gitInstallationsUrl($projectId); + $consoleUrl = $this->settingsUrl($projectId); // Signed state, no code: the failure redirect carries the error as a query string $response = $this->callGiteaCallbackHelper([ @@ -529,7 +529,7 @@ final class VCSGiteaConsoleClientTest extends Scope ]); $this->assertEquals(301, $response['headers']['status-code']); - $this->assertStringStartsWith($this->gitInstallationsUrl($projectId) . '?error=', (string) $response['headers']['location']); + $this->assertStringStartsWith($this->settingsUrl($projectId) . '?error=', (string) $response['headers']['location']); } public function testCreateInstallationWithInvalidState(): void @@ -541,7 +541,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithUnknownProject(): void { - $consoleUrl = $this->gitInstallationsUrl('missing'); + $consoleUrl = $this->settingsUrl('missing'); $response = $this->callGiteaCallbackHelper([ 'code' => 'unused', @@ -555,7 +555,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithLongState(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = $this->gitInstallationsUrl($projectId); + $consoleUrl = $this->settingsUrl($projectId); // Past the old 2048 cap: redirect URLs are not length-limited, so the // authorize endpoint can produce a state this size itself. @@ -579,16 +579,9 @@ final class VCSGiteaConsoleClientTest extends Scope $this->assertNotEmpty($installation['$id']); } - /** - * The callback builds its fallback redirect from the project's region, so the - * expected URL follows the region the scope's project was created in: Cloud - * CI creates projects in a region other than default. - */ - private function gitInstallationsUrl(string $projectId): string + private function settingsUrl(string $projectId): string { - $region = $this->getProject()['region']; - - return "http://localhost/console/project-{$region}-{$projectId}/settings/git-installations"; + return "http://localhost/projects/{$projectId}/settings"; } /** @@ -834,7 +827,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithUnsignedState(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = 'http://localhost/console/project-default-' . $projectId . '/settings/git-installations'; + $consoleUrl = 'http://localhost/projects/' . $projectId . '/settings'; $state = \json_decode($this->buildGiteaState($projectId, $consoleUrl, $consoleUrl), true); unset($state['signature']); @@ -847,7 +840,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithTamperedRedirects(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = 'http://localhost/console/project-default-' . $projectId . '/settings/git-installations'; + $consoleUrl = 'http://localhost/projects/' . $projectId . '/settings'; foreach (['success', 'failure'] as $field) { $state = \json_decode($this->buildGiteaState($projectId, $consoleUrl, $consoleUrl), true); @@ -862,7 +855,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithReplayedSignature(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = 'http://localhost/console/project-default-' . $projectId . '/settings/git-installations'; + $consoleUrl = 'http://localhost/projects/' . $projectId . '/settings'; $state = \json_decode($this->buildGiteaState($projectId, $consoleUrl, $consoleUrl), true); $state['signature'] = \json_decode($this->buildGiteaState('victim-project', $consoleUrl, $consoleUrl), true)['signature']; @@ -875,7 +868,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithNonStringSignature(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = 'http://localhost/console/project-default-' . $projectId . '/settings/git-installations'; + $consoleUrl = 'http://localhost/projects/' . $projectId . '/settings'; $state = \json_decode($this->buildGiteaState($projectId, $consoleUrl, $consoleUrl), true); $state['signature'] = 1234; @@ -890,7 +883,7 @@ final class VCSGiteaConsoleClientTest extends Scope public function testCreateInstallationWithOversizedRedirects(): void { $projectId = $this->getProject()['$id']; - $consoleUrl = 'http://localhost/console/project-default-' . $projectId . '/settings/git-installations'; + $consoleUrl = 'http://localhost/projects/' . $projectId . '/settings'; // Authorize must refuse rather than mint a state its own callback would reject. $authorize = $this->client->call(Client::METHOD_GET, '/vcs/gitea/authorize', \array_merge([