Skip to content
Open
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
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ services:
- _APP_LOGGING_CONFIG
- _APP_LOGGING_FORMAT
- _APP_DATABASE_SHARED_TABLES
- _APP_OPTIONS_FORCE_HTTPS
- _APP_DOMAIN
- _APP_CONSOLE_DOMAIN
- _APP_CONSOLE_URL_SCHEME=root
extra_hosts:
- host.docker.internal:host-gateway

Expand Down
8 changes: 6 additions & 2 deletions src/Appwrite/Platform/Modules/VCS/Http/Callback/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ public function action(
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
$hostname = $platform['consoleHostname'] ?? '';

$defaultRedirect = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root'
? $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations"
: $protocol . '://' . $hostname . "/projects/$projectId/settings";

$defaultState = [
'success' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations",
'failure' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations",
'success' => $defaultRedirect,
'failure' => $defaultRedirect,
];

$redirectSuccess = empty($state['success']) ? $defaultState['success'] : $state['success'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ public function action(
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
$hostname = $platform['consoleHostname'] ?? '';

$defaultRedirect = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root'
? $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations"
: $protocol . '://' . $hostname . "/projects/$projectId/settings";

$defaultState = [
'success' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations",
'failure' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations",
'success' => $defaultRedirect,
'failure' => $defaultRedirect,
];

$redirectSuccess = empty($state['success']) ? $defaultState['success'] : $state['success'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ public function action(
$protocol = System::getEnv('_APP_OPTIONS_FORCE_HTTPS') === 'disabled' ? 'http' : 'https';
$hostname = $platform['consoleHostname'] ?? '';

$defaultRedirect = System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root'
? $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations"
: $protocol . '://' . $hostname . "/projects/$projectId/settings";

$defaultState = [
'success' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations",
'failure' => $protocol . '://' . $hostname . "/console/project-$region-$projectId/settings/git-installations",
'success' => $defaultRedirect,
'failure' => $defaultRedirect,
];

$state = \array_merge($defaultState, \array_filter($state));
Expand Down
25 changes: 20 additions & 5 deletions tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,10 @@ private function createInstallationHelper(?string $projectId = null, ?array $hea
], true, false);

$this->assertEquals(301, $callback['headers']['status-code']);
$this->assertEquals($consoleUrl, $callback['headers']['location'] ?? '');
$this->assertSame(
$redirects ? $consoleUrl : $this->defaultRedirectUrl($projectId),
(string) ($callback['headers']['location'] ?? '')
);

$installations = $this->client->call(Client::METHOD_GET, '/vcs/installations', \array_merge([
'x-appwrite-project' => $projectId,
Expand Down Expand Up @@ -529,7 +532,7 @@ public function testCreateInstallationWithEmptyRedirects(): void
]);

$this->assertEquals(301, $response['headers']['status-code']);
$this->assertStringStartsWith($this->gitInstallationsUrl($projectId) . '?error=', (string) $response['headers']['location']);
$this->assertStringStartsWith($this->defaultRedirectUrl($projectId) . '?error=', (string) $response['headers']['location']);
}

public function testCreateInstallationWithInvalidState(): void
Expand Down Expand Up @@ -580,9 +583,21 @@ public function testCreateInstallationWithoutRedirects(): void
}

/**
* 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.
* The redirect the callback falls back to when state carries no URLs. The
* suite runs under both schemes -- server-ce sets root, cloud leaves the
* default -- and the tests share the appwrite container's environment.
*/
private function defaultRedirectUrl(string $projectId): string
{
return System::getEnv('_APP_CONSOLE_URL_SCHEME', 'legacy') !== 'root'
? $this->gitInstallationsUrl($projectId)
: "http://localhost/projects/{$projectId}/settings";
}

/**
* A console git-installations URL of the shape the console signs into state.
* It carries the project's region, which Cloud CI sets to something other
* than default.
*/
private function gitInstallationsUrl(string $projectId): string
{
Expand Down
Loading