diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php index 417812ef10..443a5db35e 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -101,7 +101,7 @@ class Create extends Action if (\in_array($domain, $deniedDomains)) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } - + if (\str_starts_with($domain, 'commit-') || \str_starts_with($domain, 'branch-')) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php index 9f9a0446d5..039f583150 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -110,7 +110,7 @@ class Create extends Action if (\str_starts_with($domain, 'commit-') || \str_starts_with($domain, 'branch-')) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } - + try { $domain = new Domain($domain); } catch (\Throwable) { diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php index ee591ab268..a693e3ec30 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -105,7 +105,7 @@ class Create extends Action if (\in_array($domain, $deniedDomains)) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } - + if (\str_starts_with($domain, 'commit-') || \str_starts_with($domain, 'branch-')) { throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please use a different domain.'); } diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index e0d0dfb26d..3f7099e703 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -69,7 +69,7 @@ class ProxyCustomServerTest extends Scope $this->assertNotEmpty($siteId); $this->assertNotEmpty($deploymentId); - + $rule = $this->createSiteRule('commit-' . $domain, $siteId); $this->assertEquals(400, $rule['headers']['status-code']); diff --git a/tests/e2e/Services/Sites/SitesConsoleClientTest.php b/tests/e2e/Services/Sites/SitesConsoleClientTest.php new file mode 100644 index 0000000000..3b9243ee77 --- /dev/null +++ b/tests/e2e/Services/Sites/SitesConsoleClientTest.php @@ -0,0 +1,101 @@ +setupSite([ + 'siteId' => ID::unique(), + 'name' => 'Themed site', + 'framework' => 'other', + 'adapter' => 'static', + 'buildRuntime' => 'static-1', + 'outputDirectory' => './', + 'buildCommand' => '', + 'installCommand' => '', + 'fallbackFile' => '', + ]); + + $this->assertNotEmpty($siteId); + + $domain = $this->setupSiteDomain($siteId); + + $deploymentId = $this->setupDeployment($siteId, [ + 'code' => $this->packageSite('static-themed'), + 'activate' => 'true' + ]); + + $this->assertNotEmpty($deploymentId); + + $domain = $this->getSiteDomain($siteId); + $this->assertNotEmpty($domain); + + $proxyClient = new Client(); + $proxyClient->setEndpoint('http://' . $domain); + + $response = $proxyClient->call(Client::METHOD_GET, '/'); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertStringContainsString("Themed website", $response['body']); + $this->assertStringContainsString("@media (prefers-color-scheme: dark)", $response['body']); + + $deployment = $this->getDeployment($siteId, $deploymentId); + $this->assertEquals(200, $deployment['headers']['status-code']); + $this->assertNotEmpty($deployment['body']['screenshotLight']); + $this->assertNotEmpty($deployment['body']['screenshotDark']); + + $site = $this->getSite($siteId); + $this->assertEquals(200, $site['headers']['status-code']); + $this->assertEquals($deployment['body']['screenshotLight'], $site['body']['deploymentScreenshotLight']); + $this->assertEquals($deployment['body']['screenshotDark'], $site['body']['deploymentScreenshotDark']); + + $screenshotId = $deployment['body']['screenshotLight']; + $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console", array_merge($this->getHeaders(), [ + 'x-appwrite-mode' => 'default' // NOT ADMIN! + ])); + + $this->assertEquals(200, $file['headers']['status-code']); + $this->assertNotEmpty(200, $file['body']); + $this->assertGreaterThan(1, $file['headers']['content-length']); + $this->assertEquals('image/png', $file['headers']['content-type']); + + $screenshotHash = \md5($file['body']); + $this->assertNotEmpty($screenshotHash); + + $screenshotId = $deployment['body']['screenshotDark']; + $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console", array_merge($this->getHeaders(), [ + 'x-appwrite-mode' => 'default' // NOT ADMIN! + ])); + + $this->assertEquals(200, $file['headers']['status-code']); + $this->assertNotEmpty(200, $file['body']); + $this->assertGreaterThan(1, $file['headers']['content-length']); + $this->assertEquals('image/png', $file['headers']['content-type']); + + $screenshotDarkHash = \md5($file['body']); + $this->assertNotEmpty($screenshotDarkHash); + + $this->assertNotEquals($screenshotDarkHash, $screenshotHash); + + $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console"); + $this->assertEquals(404, $file['headers']['status-code']); + + $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console"); + $this->assertEquals(404, $file['headers']['status-code']); + + $this->cleanupSite($siteId); + } +} diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index eea93a7e0d..5866bf2e27 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1805,88 +1805,6 @@ class SitesCustomServerTest extends Scope $this->assertEquals('http://localhost', $response['headers']['access-control-allow-origin']); } - public function testSiteScreenshot(): void - { - $siteId = $this->setupSite([ - 'siteId' => ID::unique(), - 'name' => 'Themed site', - 'framework' => 'other', - 'adapter' => 'static', - 'buildRuntime' => 'static-1', - 'outputDirectory' => './', - 'buildCommand' => '', - 'installCommand' => '', - 'fallbackFile' => '', - ]); - - $this->assertNotEmpty($siteId); - - $domain = $this->setupSiteDomain($siteId); - - $deploymentId = $this->setupDeployment($siteId, [ - 'code' => $this->packageSite('static-themed'), - 'activate' => 'true' - ]); - - $this->assertNotEmpty($deploymentId); - - $domain = $this->getSiteDomain($siteId); - $this->assertNotEmpty($domain); - - $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $domain); - - $response = $proxyClient->call(Client::METHOD_GET, '/'); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertStringContainsString("Themed website", $response['body']); - $this->assertStringContainsString("@media (prefers-color-scheme: dark)", $response['body']); - - $deployment = $this->getDeployment($siteId, $deploymentId); - $this->assertEquals(200, $deployment['headers']['status-code']); - $this->assertNotEmpty($deployment['body']['screenshotLight']); - $this->assertNotEmpty($deployment['body']['screenshotDark']); - - $site = $this->getSite($siteId); - $this->assertEquals(200, $site['headers']['status-code']); - $this->assertEquals($deployment['body']['screenshotLight'], $site['body']['deploymentScreenshotLight']); - $this->assertEquals($deployment['body']['screenshotDark'], $site['body']['deploymentScreenshotDark']); - - $screenshotId = $deployment['body']['screenshotLight']; - $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console", array_merge([ - ], $this->getHeaders())); - - $this->assertEquals(200, $file['headers']['status-code']); - $this->assertNotEmpty(200, $file['body']); - $this->assertGreaterThan(1, $file['headers']['content-length']); - $this->assertEquals('image/png', $file['headers']['content-type']); - - $screenshotHash = \md5($file['body']); - $this->assertNotEmpty($screenshotHash); - - $screenshotId = $deployment['body']['screenshotDark']; - $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console", array_merge([ - ], $this->getHeaders())); - - $this->assertEquals(200, $file['headers']['status-code']); - $this->assertNotEmpty(200, $file['body']); - $this->assertGreaterThan(1, $file['headers']['content-length']); - $this->assertEquals('image/png', $file['headers']['content-type']); - - $screenshotDarkHash = \md5($file['body']); - $this->assertNotEmpty($screenshotDarkHash); - - $this->assertNotEquals($screenshotDarkHash, $screenshotHash); - - $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console"); - $this->assertEquals(404, $file['headers']['status-code']); - - $file = $this->client->call(Client::METHOD_GET, "/storage/buckets/screenshots/files/$screenshotId/view?project=console"); - $this->assertEquals(404, $file['headers']['status-code']); - - $this->cleanupSite($siteId); - } - public function testSiteDownload(): void { $siteId = $this->setupSite([