2020-07-08 09:11:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Projects;
|
|
|
|
|
|
2024-05-05 04:56:49 +00:00
|
|
|
use Tests\E2E\Client;
|
2020-07-08 09:11:12 +00:00
|
|
|
use Tests\E2E\Scopes\ProjectCustom;
|
|
|
|
|
use Tests\E2E\Scopes\Scope;
|
|
|
|
|
use Tests\E2E\Scopes\SideServer;
|
2025-02-17 11:45:23 +00:00
|
|
|
use Utopia\System\System;
|
2020-07-08 09:11:12 +00:00
|
|
|
|
|
|
|
|
class ProjectsCustomServerTest extends Scope
|
|
|
|
|
{
|
|
|
|
|
use ProjectCustom;
|
|
|
|
|
use SideServer;
|
|
|
|
|
|
2024-05-05 04:56:49 +00:00
|
|
|
// Domains
|
|
|
|
|
|
|
|
|
|
public function testCreateProjectRule()
|
|
|
|
|
{
|
2025-04-25 10:57:45 +00:00
|
|
|
$testId = \uniqid();
|
2025-04-25 10:57:55 +00:00
|
|
|
|
2024-05-05 04:56:49 +00:00
|
|
|
$headers = array_merge([
|
|
|
|
|
'content-type' => 'application/json',
|
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
|
'x-appwrite-mode' => 'admin',
|
|
|
|
|
'cookie' => 'a_session_console=' . $this->getRoot()['session'],
|
|
|
|
|
]);
|
|
|
|
|
|
2025-02-22 17:56:51 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [
|
2025-04-25 10:57:45 +00:00
|
|
|
'domain' => $testId . '-api.appwrite.test',
|
2024-05-05 04:56:49 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
2025-02-23 16:08:12 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [
|
2025-02-18 06:42:12 +00:00
|
|
|
'resourceType' => 'api',
|
2025-04-25 10:57:45 +00:00
|
|
|
'domain' => $testId . '-abc.test.io',
|
2025-02-18 06:42:12 +00:00
|
|
|
]);
|
2025-04-25 10:57:55 +00:00
|
|
|
|
2025-02-18 06:42:12 +00:00
|
|
|
$this->assertEquals(201, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
// duplicate rule
|
2025-02-22 17:56:51 +00:00
|
|
|
$response2 = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [
|
2025-04-25 10:57:45 +00:00
|
|
|
'domain' => $testId . '-abc.test.io',
|
2025-02-18 06:42:12 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(409, $response2['headers']['status-code']);
|
|
|
|
|
|
2024-05-22 21:19:21 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_DELETE, '/proxy/rules/' . $response['body']['$id'], $headers);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(204, $response['headers']['status-code']);
|
2025-02-17 11:45:23 +00:00
|
|
|
|
2026-01-30 15:20:46 +00:00
|
|
|
$functionsDomain = \explode(',', System::getEnv('_APP_DOMAIN_FUNCTIONS', ''))[0];
|
2025-02-17 11:45:23 +00:00
|
|
|
|
2025-02-22 17:56:51 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [
|
2025-02-17 11:45:23 +00:00
|
|
|
'domain' => $functionsDomain,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
|
2026-01-30 15:20:46 +00:00
|
|
|
$sitesDomain = \explode(',', System::getEnv('_APP_DOMAIN_SITES', ''))[0];
|
2025-02-17 11:45:23 +00:00
|
|
|
|
2025-02-22 17:56:51 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [
|
2025-02-17 11:45:23 +00:00
|
|
|
'domain' => $sitesDomain,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
// prevent functions domain
|
2025-02-22 17:56:51 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/function', $headers, [
|
2025-02-17 11:45:23 +00:00
|
|
|
'domain' => $functionsDomain,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
|
|
// prevent sites domain
|
2025-02-22 17:56:51 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/site', $headers, [
|
2025-02-17 11:45:23 +00:00
|
|
|
'domain' => $sitesDomain,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2025-02-18 06:42:12 +00:00
|
|
|
|
|
|
|
|
$deniedDomains = [
|
2025-12-07 20:29:45 +00:00
|
|
|
'sites.localhost',
|
|
|
|
|
'functions.localhost',
|
|
|
|
|
'appwrite.test',
|
|
|
|
|
'localhost'
|
2025-02-18 06:42:12 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
foreach ($deniedDomains as $deniedDomain) {
|
2025-02-22 17:56:51 +00:00
|
|
|
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [
|
2025-02-18 06:42:12 +00:00
|
|
|
'domain' => $deniedDomain,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
}
|
2024-05-05 04:56:49 +00:00
|
|
|
}
|
2022-05-23 14:54:50 +00:00
|
|
|
}
|