mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
fix: revert regions.php, add mock PATCH route for project region in tests
Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
This commit is contained in:
@@ -7,10 +7,4 @@ return [
|
||||
'disabled' => false,
|
||||
'default' => true,
|
||||
],
|
||||
'fra' => [
|
||||
'$id' => 'fra',
|
||||
'name' => 'Frankfurt',
|
||||
'disabled' => false,
|
||||
'default' => false,
|
||||
],
|
||||
];
|
||||
|
||||
@@ -279,6 +279,40 @@ Http::get('/v1/mock/github/callback')
|
||||
]);
|
||||
});
|
||||
|
||||
Http::patch('/v1/mock/projects/{projectId}/region')
|
||||
->desc('Update project region (development/testing only)')
|
||||
->groups(['mock'])
|
||||
->label('scope', 'public')
|
||||
->label('docs', false)
|
||||
->label('mock', true)
|
||||
->param('projectId', '', new UID(), 'Project ID.')
|
||||
->param('region', '', new Text(64), 'Region value to set on the project document.')
|
||||
->inject('response')
|
||||
->inject('dbForPlatform')
|
||||
->action(function (string $projectId, string $region, Response $response, Database $dbForPlatform) {
|
||||
$isDevelopment = System::getEnv('_APP_ENV', 'development') === 'development';
|
||||
|
||||
if (!$isDevelopment) {
|
||||
throw new Exception(Exception::GENERAL_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
$project = $dbForPlatform->getDocument('projects', $projectId);
|
||||
|
||||
if ($project->isEmpty()) {
|
||||
throw new Exception(Exception::PROJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
$dbForPlatform->updateDocument(
|
||||
'projects',
|
||||
$project->getId(),
|
||||
$project->setAttribute('region', $region)
|
||||
);
|
||||
|
||||
$dbForPlatform->purgeCachedDocument('projects', $project->getId());
|
||||
|
||||
$response->json(['projectId' => $project->getId(), 'region' => $region]);
|
||||
});
|
||||
|
||||
Http::shutdown()
|
||||
->groups(['mock'])
|
||||
->inject('utopia')
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace Tests\E2E\Services\Realtime;
|
||||
|
||||
use Tests\E2E\Client;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\System\System;
|
||||
use WebSocket\Client as WebSocketClient;
|
||||
use WebSocket\ConnectionException;
|
||||
|
||||
@@ -156,12 +155,6 @@ trait RealtimeBase
|
||||
|
||||
public function testConnectionFailureRegionMismatch(): void
|
||||
{
|
||||
$serverRegion = System::getEnv('_APP_REGION', 'default');
|
||||
|
||||
if ($serverRegion === 'fra') {
|
||||
$this->markTestSkipped('Test requires server region to not be "fra"');
|
||||
}
|
||||
|
||||
// Create a team for the mismatched-region project
|
||||
$team = $this->client->call(Client::METHOD_POST, '/teams', [
|
||||
'origin' => 'http://localhost',
|
||||
@@ -176,7 +169,7 @@ trait RealtimeBase
|
||||
$this->assertEquals(201, $team['headers']['status-code']);
|
||||
$teamId = $team['body']['$id'];
|
||||
|
||||
// Create a project in the 'fra' region (which won't match the server's region)
|
||||
// Create a project with the default (matching) region
|
||||
$project = $this->client->call(Client::METHOD_POST, '/projects', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
@@ -184,7 +177,6 @@ trait RealtimeBase
|
||||
'x-appwrite-project' => 'console',
|
||||
], [
|
||||
'projectId' => ID::unique(),
|
||||
'region' => 'fra',
|
||||
'name' => 'Region Mismatch Project',
|
||||
'teamId' => $teamId,
|
||||
]);
|
||||
@@ -192,6 +184,17 @@ trait RealtimeBase
|
||||
$this->assertEquals(201, $project['headers']['status-code']);
|
||||
$projectId = $project['body']['$id'];
|
||||
|
||||
// Force a mismatched region directly in the DB via the mock endpoint (bypasses API validation)
|
||||
$response = $this->client->call(Client::METHOD_PATCH, '/mock/projects/' . $projectId . '/region', [
|
||||
'origin' => 'http://localhost',
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $projectId,
|
||||
], [
|
||||
'region' => 'mismatched-region',
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
* A project in a different region should be rejected with an access forbidden error.
|
||||
|
||||
Reference in New Issue
Block a user