From 7ae2c1bb2e297453e390f7364f3ea3a8bdb9d06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 25 Apr 2025 14:13:22 +0200 Subject: [PATCH] Fix more tests --- .../Modules/Proxy/Http/Rules/API/Create.php | 4 ++++ .../Modules/Proxy/Http/Rules/Function/Create.php | 4 ++++ .../Modules/Proxy/Http/Rules/Redirect/Create.php | 4 ++++ tests/e2e/Services/Proxy/ProxyCustomServerTest.php | 13 ++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) 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 b59fe64020..417812ef10 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -101,6 +101,10 @@ 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.'); + } try { $domain = new Domain($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 647568c7f4..9f9a0446d5 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -107,6 +107,10 @@ class Create extends Action 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.'); + } + 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 026b8792a9..ee591ab268 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -105,6 +105,10 @@ 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.'); + } try { $domain = new Domain($domain); diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index 0ac2d9c186..e0d0dfb26d 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -63,13 +63,20 @@ class ProxyCustomServerTest extends Scope { $domain = \uniqid() . '-vcs.myapp.com'; - $rule = $this->createAPIRule('commit-' . $domain); + $setup = $this->setupSite(); + $siteId = $setup['siteId']; + $deploymentId = $setup['deploymentId']; + + $this->assertNotEmpty($siteId); + $this->assertNotEmpty($deploymentId); + + $rule = $this->createSiteRule('commit-' . $domain, $siteId); $this->assertEquals(400, $rule['headers']['status-code']); - $rule = $this->createAPIRule('branch-' . $domain); + $rule = $this->createSiteRule('branch-' . $domain, $siteId); $this->assertEquals(400, $rule['headers']['status-code']); - $rule = $this->createAPIRule('anything-' . $domain); + $rule = $this->createSiteRule('anything-' . $domain, $siteId); $this->assertEquals(201, $rule['headers']['status-code']); $this->cleanupRule($rule['body']['$id']); }