diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 54bdb358d2..6211faf90e 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -18,8 +18,8 @@ use Utopia\Config\Config; use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; -use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Duplicate; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; diff --git a/app/controllers/general.php b/app/controllers/general.php index 55db28a6ea..889571fe62 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -856,7 +856,7 @@ App::init() if (!empty($functionsDomainFallback) && \str_ends_with($host, $functionsDomainFallback)) { $functionsDomain = $functionsDomainFallback; } - + if ( (!empty($functionsDomain) && \str_ends_with($domain->get(), $functionsDomain)) || (!empty($siteDomain) && \str_ends_with($domain->get(), $siteDomain)) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index ce980530f5..8c15f27acc 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -254,7 +254,7 @@ App::init() } $accessedAt = $dbKey->getAttribute('accessedAt', 0); - + if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCESS)) > $accessedAt) { $dbKey->setAttribute('accessedAt', DateTime::now()); $dbForPlatform->updateDocument('keys', $dbKey->getId(), $dbKey); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php index 7b556a395a..38f1f38e89 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Deployments/XList.php @@ -10,6 +10,7 @@ use Appwrite\Utopia\Database\Validator\Queries\Deployments; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; @@ -17,7 +18,6 @@ use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\Text; -use Utopia\Database\Exception\Order as OrderException; class XList extends Action { @@ -120,7 +120,7 @@ class XList extends Action } catch (OrderException $e) { throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - + $response->dynamic(new Document([ 'deployments' => $results, 'total' => $total, diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php index dd01cb20e9..a31e95b1c8 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/XList.php @@ -12,6 +12,7 @@ use Appwrite\Utopia\Database\Validator\Queries\Executions; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; @@ -19,7 +20,6 @@ use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; -use Utopia\Database\Exception\Order as OrderException; class XList extends Base { @@ -112,7 +112,7 @@ class XList extends Base } $filterQueries = Query::groupByType($queries)['filters']; - + try { $results = $dbForProject->find('executions', $queries); $total = $dbForProject->count('executions', $filterQueries, APP_LIMIT_COUNT); diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php index e764fb6b3b..cd0eba2c50 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/XList.php @@ -11,13 +11,13 @@ use Appwrite\Utopia\Database\Validator\Queries\Functions; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\Text; -use Utopia\Database\Exception\Order as OrderException; class XList extends Base { @@ -108,7 +108,7 @@ class XList extends Base } catch (OrderException $e) { throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - + $response->dynamic(new Document([ 'functions' => $functions, 'total' => $total, 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 859c343a9c..2d912c8ca2 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/API/Create.php @@ -75,25 +75,27 @@ class Create extends Action 'localhost', APP_HOSTNAME_INTERNAL ]; - + $mainDomain = System::getEnv('_APP_DOMAIN', ''); $deniedDomains[] = $mainDomain; - + $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); - if(!empty($functionsDomain)) { - $deniedDomains[] = $functionsDomain; + if (!empty($sitesDomain)) { + $deniedDomains[] = $sitesDomain; } - + $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); - if(!empty($functionsDomain)) { + if (!empty($functionsDomain)) { $deniedDomains[] = $functionsDomain; } - + $denyListDomains = System::getEnv('_APP_CUSTOM_DOMAIN_DENY_LIST', ''); $denyListDomains = \array_map('trim', explode(',', $denyListDomains)); - foreach($denyListDomains as $domain) { - if(empty($domain)) continue; - $deniedDomains[] = $domain; + foreach ($denyListDomains as $denyListDomain) { + if (empty($denyListDomain)) { + continue; + } + $deniedDomains[] = $denyListDomain; } if (\in_array($domain, $deniedDomains)) { @@ -143,7 +145,7 @@ class Create extends Action ) { $owner = 'Appwrite'; } - + $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), 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 1cebed5fec..647568c7f4 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Function/Create.php @@ -80,25 +80,27 @@ class Create extends Action 'localhost', APP_HOSTNAME_INTERNAL ]; - + $mainDomain = System::getEnv('_APP_DOMAIN', ''); $deniedDomains[] = $mainDomain; - + $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); - if(!empty($functionsDomain)) { - $deniedDomains[] = $functionsDomain; + if (!empty($sitesDomain)) { + $deniedDomains[] = $sitesDomain; } - + $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); - if(!empty($functionsDomain)) { + if (!empty($functionsDomain)) { $deniedDomains[] = $functionsDomain; } - + $denyListDomains = System::getEnv('_APP_CUSTOM_DOMAIN_DENY_LIST', ''); $denyListDomains = \array_map('trim', explode(',', $denyListDomains)); - foreach($denyListDomains as $domain) { - if(empty($domain)) continue; - $deniedDomains[] = $domain; + foreach ($denyListDomains as $denyListDomain) { + if (empty($denyListDomain)) { + continue; + } + $deniedDomains[] = $denyListDomain; } if (\in_array($domain, $deniedDomains)) { 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 d7f5e8806f..026b8792a9 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Redirect/Create.php @@ -79,25 +79,27 @@ class Create extends Action 'localhost', APP_HOSTNAME_INTERNAL ]; - + $mainDomain = System::getEnv('_APP_DOMAIN', ''); $deniedDomains[] = $mainDomain; - + $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); - if(!empty($functionsDomain)) { - $deniedDomains[] = $functionsDomain; + if (!empty($sitesDomain)) { + $deniedDomains[] = $sitesDomain; } - + $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); - if(!empty($functionsDomain)) { + if (!empty($functionsDomain)) { $deniedDomains[] = $functionsDomain; } - + $denyListDomains = System::getEnv('_APP_CUSTOM_DOMAIN_DENY_LIST', ''); $denyListDomains = \array_map('trim', explode(',', $denyListDomains)); - foreach($denyListDomains as $domain) { - if(empty($domain)) continue; - $deniedDomains[] = $domain; + foreach ($denyListDomains as $denyListDomain) { + if (empty($denyListDomain)) { + continue; + } + $deniedDomains[] = $denyListDomain; } if (\in_array($domain, $deniedDomains)) { diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php index 0740a22dea..2cce4144c5 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Site/Create.php @@ -80,24 +80,26 @@ class Create extends Action 'localhost', APP_HOSTNAME_INTERNAL ]; - + $mainDomain = System::getEnv('_APP_DOMAIN', ''); $deniedDomains[] = $mainDomain; - + $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', ''); - if(!empty($functionsDomain)) { - $deniedDomains[] = $functionsDomain; + if (!empty($sitesDomain)) { + $deniedDomains[] = $sitesDomain; } - + $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); - if(!empty($functionsDomain)) { + if (!empty($functionsDomain)) { $deniedDomains[] = $functionsDomain; } - + $denyListDomains = System::getEnv('_APP_CUSTOM_DOMAIN_DENY_LIST', ''); $denyListDomains = \array_map('trim', explode(',', $denyListDomains)); - foreach($denyListDomains as $domain) { - if(empty($domain)) continue; + foreach ($denyListDomains as $domain) { + if (empty($domain)) { + continue; + } $deniedDomains[] = $domain; } diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php index 8ae3feeda6..d7cfc1d3ad 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/XList.php @@ -10,6 +10,7 @@ use Appwrite\Utopia\Database\Validator\Queries\Deployments; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; @@ -17,7 +18,6 @@ use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\Text; -use Utopia\Database\Exception\Order as OrderException; class XList extends Action { diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php index 09d694a5b2..a873d32603 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Logs/XList.php @@ -12,13 +12,13 @@ use Appwrite\Utopia\Database\Validator\Queries\Logs; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; -use Utopia\Database\Exception\Order as OrderException; class XList extends Base { @@ -104,7 +104,7 @@ class XList extends Base } $filterQueries = Query::groupByType($queries)['filters']; - + try { $results = $dbForProject->find('executions', $queries); $total = $dbForProject->count('executions', $filterQueries, APP_LIMIT_COUNT); diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php index 4f8ccab505..0a3b257f59 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/XList.php @@ -11,13 +11,13 @@ use Appwrite\Utopia\Database\Validator\Queries\Sites; use Appwrite\Utopia\Response; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Exception\Order as OrderException; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Platform\Action; use Utopia\Platform\Scope\HTTP; use Utopia\Validator\Text; -use Utopia\Database\Exception\Order as OrderException; class XList extends Base { @@ -104,7 +104,7 @@ class XList extends Base } catch (OrderException $e) { throw new Exception(Exception::DATABASE_QUERY_ORDER_NULL, "The order attribute '{$e->getAttribute()}' had a null value. Cursor pagination requires all documents order attribute values are non-null."); } - + $response->dynamic(new Document([ 'sites' => $sites, 'total' => $total, diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index ddfa403300..5549ef800d 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -15,7 +15,6 @@ use Tests\E2E\Services\Sites\SitesBase; use Utopia\Database\Helpers\ID; use Utopia\Database\Helpers\Permission; use Utopia\Database\Helpers\Role; -use Utopia\Database\Query; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\System\System; diff --git a/tests/e2e/Services/Projects/ProjectsCustomServerTest.php b/tests/e2e/Services/Projects/ProjectsCustomServerTest.php index 6d9431290f..1b4ff414b1 100644 --- a/tests/e2e/Services/Projects/ProjectsCustomServerTest.php +++ b/tests/e2e/Services/Projects/ProjectsCustomServerTest.php @@ -17,6 +17,8 @@ class ProjectsCustomServerTest extends Scope public function testCreateProjectRule() { + $testId = \uniqid(); + $headers = array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -25,21 +27,23 @@ class ProjectsCustomServerTest extends Scope ]); $response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [ - 'domain' => 'api.appwrite.test', + 'domain' => $testId . '-api.appwrite.test', ]); + \var_dump($response); + $this->assertEquals(201, $response['headers']['status-code']); $response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [ 'resourceType' => 'api', - 'domain' => 'abc.test.io', + 'domain' => $testId . '-abc.test.io', ]); - + $this->assertEquals(201, $response['headers']['status-code']); // duplicate rule $response2 = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [ - 'domain' => 'abc.test.io', + 'domain' => $testId . '-abc.test.io', ]); $this->assertEquals(409, $response2['headers']['status-code']);