Remove unrelated changes to site deletion

This commit is contained in:
Khushboo Verma 2025-01-09 17:41:45 +05:30
parent 426bcffd1a
commit 8a260ceece
4 changed files with 2 additions and 374 deletions

View file

@ -21,7 +21,6 @@ use Utopia\Database\Document;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\Roles;
use Utopia\Platform\Action;
@ -90,7 +89,6 @@ class CreateFunction extends Base
App::getEnv('_APP_COMPUTE_CPUS', APP_COMPUTE_CPUS_DEFAULT),
App::getEnv('_APP_COMPUTE_MEMORY', APP_COMPUTE_MEMORY_DEFAULT)
), 'Runtime specification for the function and builds.', true, ['plan'])
->param('subdomain', '', new CustomId(), 'Unique custom sub-domain. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.', true)
->inject('request')
->inject('response')
->inject('dbForProject')
@ -103,27 +101,8 @@ class CreateFunction extends Base
->callback([$this, 'action']);
}
public function action(string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, array $scopes, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, string $subdomain, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github)
public function action(string $functionId, string $name, string $runtime, array $execute, array $events, string $schedule, int $timeout, bool $enabled, bool $logging, string $entrypoint, string $commands, array $scopes, string $installationId, string $providerRepositoryId, string $providerBranch, bool $providerSilentMode, string $providerRootDirectory, string $templateRepository, string $templateOwner, string $templateRootDirectory, string $templateVersion, string $specification, Request $request, Response $response, Database $dbForProject, Document $project, Document $user, Event $queueForEvents, Build $queueForBuilds, Database $dbForConsole, GitHub $github)
{
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
$ruleId = '';
$routeSubdomain = '';
$domain = '';
if (!empty($functionsDomain)) {
$ruleId = ID::unique();
$routeSubdomain = $subdomain ?: ID::unique();
$domain = "{$routeSubdomain}.{$functionsDomain}";
$subdomain = Authorization::skip(fn () => $dbForConsole->findOne('rules', [
Query::equal('domain', [$domain])
]));
if (!empty($subdomain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Subdomain already exists. Please choose a different subdomain.');
}
}
$functionId = ($functionId == 'unique()') ? ID::unique() : $functionId;
$allowList = \array_filter(\explode(',', System::getEnv('_APP_FUNCTIONS_RUNTIMES', '')));
@ -263,6 +242,7 @@ class CreateFunction extends Base
->setTemplate($template);
}
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
if (!empty($functionsDomain)) {
$routeSubdomain = ID::unique();
$domain = "{$routeSubdomain}.{$functionsDomain}";

View file

@ -36,7 +36,6 @@ class FunctionsCustomServerTest extends Scope
'buckets.*.delete',
],
'timeout' => 10,
'subdomain' => 'test'
]);
$functionId = $functionId = $function['body']['$id'] ?? '';
@ -73,24 +72,6 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(201, $variable2['headers']['status-code']);
$this->assertEquals(201, $variable3['headers']['status-code']);
/**
* Test for FAILURE
*/
$function2 = $this->createFunction([
'functionId' => ID::unique(),
'name' => 'Test',
'runtime' => 'php-8.0',
'entrypoint' => 'index.php',
'events' => [
'buckets.*.create',
'buckets.*.delete',
],
'timeout' => 10,
'subdomain' => 'test'
]);
$this->assertEquals(400, $function2['headers']['status-code']);
return [
'functionId' => $functionId,
];

View file

@ -1,178 +0,0 @@
<?php
namespace Tests\E2E\Services\Sites;
use Appwrite\Tests\Async;
use CURLFile;
use Tests\E2E\Client;
use Utopia\CLI\Console;
trait SitesBase
{
use Async;
protected string $stdout = '';
protected string $stderr = '';
protected function setupSite(mixed $params): string
{
$site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]), $params);
$this->assertEquals($site['headers']['status-code'], 201, 'Setup site failed with status code: ' . $site['headers']['status-code'] . ' and response: ' . json_encode($site['body'], JSON_PRETTY_PRINT));
$siteId = $site['body']['$id'];
return $siteId;
}
protected function setupDeployment(string $siteId, mixed $params): string
{
$deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]), $params);
$this->assertEquals($deployment['headers']['status-code'], 202, 'Setup deployment failed with status code: ' . $deployment['headers']['status-code'] . ' and response: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT));
$deploymentId = $deployment['body']['$id'] ?? '';
$this->assertEventually(function () use ($siteId, $deploymentId) {
$deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]));
$this->assertEquals('ready', $deployment['body']['status'], 'Deployment status is not ready, deployment: ' . json_encode($deployment['body'], JSON_PRETTY_PRINT));
}, 50000, 500);
return $deploymentId;
}
protected function cleanupSite(string $siteId): void
{
$site = $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
]));
$this->assertEquals($site['headers']['status-code'], 204);
}
protected function createSite(mixed $params): mixed
{
$site = $this->client->call(Client::METHOD_POST, '/sites', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), $params);
return $site;
}
protected function createVariable(string $siteId, mixed $params): mixed
{
$variable = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/variables', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), $params);
return $variable;
}
protected function getSite(string $siteId): mixed
{
$site = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
return $site;
}
protected function getDeployment(string $siteId, string $deploymentId): mixed
{
$deployment = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments/' . $deploymentId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
return $deployment;
}
protected function listSites(mixed $params = []): mixed
{
$sites = $this->client->call(Client::METHOD_GET, '/sites', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), $params);
return $sites;
}
protected function listDeployments(string $siteId, $params = []): mixed
{
$deployments = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/deployments', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), $params);
return $deployments;
}
protected function packageSite(string $site): CURLFile
{
$folderPath = realpath(__DIR__ . '/../../../resources/sites') . "/$site";
$tarPath = "$folderPath/code.tar.gz";
Console::execute("cd $folderPath && tar --exclude code.tar.gz -czf code.tar.gz .", '', $this->stdout, $this->stderr);
if (filesize($tarPath) > 1024 * 1024 * 5) {
throw new \Exception('Code package is too large. Use the chunked upload method instead.');
}
return new CURLFile($tarPath, 'application/x-gzip', \basename($tarPath));
}
protected function createDeployment(string $siteId, mixed $params = []): mixed
{
$deployment = $this->client->call(Client::METHOD_POST, '/sites/' . $siteId . '/deployments', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), $params);
return $deployment;
}
protected function getSiteUsage(string $siteId, mixed $params): mixed
{
$usage = $this->client->call(Client::METHOD_GET, '/sites/' . $siteId . '/usage', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), $params);
return $usage;
}
protected function getTemplate(string $templateId)
{
$template = $this->client->call(Client::METHOD_GET, '/sites/templates/' . $templateId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
return $template;
}
protected function deleteSite(string $siteId): mixed
{
$site = $this->client->call(Client::METHOD_DELETE, '/sites/' . $siteId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
return $site;
}
}

View file

@ -1,155 +0,0 @@
<?php
namespace Tests\E2E\Services\Sites;
use Tests\E2E\Scopes\ProjectCustom;
use Tests\E2E\Scopes\Scope;
use Tests\E2E\Scopes\SideServer;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Validator\Datetime as DatetimeValidator;
class SitesCustomServerTest extends Scope
{
use SitesBase;
use ProjectCustom;
use SideServer;
public function testCreateSite(): array
{
/**
* Test for SUCCESS
*/
$site = $this->createSite([
'siteId' => ID::unique(),
'name' => 'Test',
'framework' => 'sveltekit',
'installCommand' => 'npm install --force',
'buildCommand' => 'npm run build',
'outputDirectory' => './build',
'buildRuntime' => 'node-22',
'serveRuntime' => 'static-1',
'subdomain' => 'test'
]);
$siteId = $site['body']['$id'] ?? '';
$dateValidator = new DatetimeValidator();
$this->assertEquals(201, $site['headers']['status-code']);
$this->assertNotEmpty($site['body']['$id']);
$this->assertEquals('Test', $site['body']['name']);
$this->assertEquals('sveltekit', $site['body']['framework']);
$this->assertEquals(true, $dateValidator->isValid($site['body']['$createdAt']));
$this->assertEquals(true, $dateValidator->isValid($site['body']['$updatedAt']));
$this->assertEquals('npm install --force', $site['body']['installCommand']);
$this->assertEquals('npm run build', $site['body']['buildCommand']);
$this->assertEquals('./build', $site['body']['outputDirectory']);
$this->assertEquals('node-22', $site['body']['buildRuntime']);
$this->assertEquals('static-1', $site['body']['serveRuntime']);
$variable = $this->createVariable($siteId, [
'key' => 'siteKey1',
'value' => 'siteValue1',
]);
$variable2 = $this->createVariable($siteId, [
'key' => 'siteKey2',
'value' => 'siteValue2',
]);
$variable3 = $this->createVariable($siteId, [
'key' => 'siteKey3',
'value' => 'siteValue3',
]);
$this->assertEquals(201, $variable['headers']['status-code']);
$this->assertEquals(201, $variable2['headers']['status-code']);
$this->assertEquals(201, $variable3['headers']['status-code']);
return [
'siteId' => $siteId,
];
}
/**
* @depends testCreateSite
*/
public function testGetSite(array $data): array
{
/**
* Test for SUCCESS
*/
$site = $this->getSite($data['siteId']);
$this->assertEquals($site['headers']['status-code'], 200);
$this->assertEquals($site['body']['name'], 'Test');
/**
* Test for FAILURE
*/
$site = $this->getSite('x');
$this->assertEquals($site['headers']['status-code'], 404);
return $data;
}
/**
* @depends testGetSite
*/
public function testDeleteSite(array $data): array
{
/**
* Test for SUCCESS
*/
$site = $this->deleteSite($data['siteId']);
$this->assertEquals(204, $site['headers']['status-code']);
$this->assertEmpty($site['body']);
$site = $this->getSite($data['siteId']);
$this->assertEquals(404, $site['headers']['status-code']);
return $data;
}
/**
* @depends testGetSite
*/
public function testUniqueSubdomain(array $data): void
{
/**
* Test for SUCCESS
*/
$site = $this->createSite([
'siteId' => ID::unique(),
'name' => 'Test',
'framework' => 'sveltekit',
'installCommand' => 'npm install --force',
'buildCommand' => 'npm run build',
'outputDirectory' => './build',
'buildRuntime' => 'node-22',
'serveRuntime' => 'static-1',
'subdomain' => 'test'
]);
$this->assertEquals(201, $site['headers']['status-code']);
/**
* Test for FAILURE
*/
$site = $this->createSite([
'siteId' => ID::unique(),
'name' => 'Test2',
'framework' => 'sveltekit',
'installCommand' => 'npm install --force',
'buildCommand' => 'npm run build',
'outputDirectory' => './build',
'buildRuntime' => 'node-22',
'serveRuntime' => 'static-1',
'subdomain' => 'test'
]);
$this->assertEquals(400, $site['headers']['status-code']);
return;
}
}