fix:hit and trial

This commit is contained in:
Harsh Mahajan committed 2025-07-28 17:33:39 +05:30
1 parent 0dc3708a95
commit 1d40e6597f
6 files changed
+53 -33

No files matched your search

@@ -14,6 +14,7 @@ use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\System\System;
use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
@@ -68,9 +69,12 @@ class Get extends Action
) {
if ($type === 'rules') {
// Validate domain format and appwrite.network specific rules
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($value)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain) && \str_ends_with($value, '.' . ltrim($sitesDomain, '.'))) {
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($value)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
}
}
$document = Authorization::skip(fn () => $dbForPlatform->findOne('rules', [
@@ -80,10 +80,11 @@ class Create extends Action
$mainDomain = System::getEnv('_APP_DOMAIN', '');
$deniedDomains[] = $mainDomain;
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain)) {
$deniedDomains[] = $sitesDomain;
}
// Don't add sites domain to denied list - it should be allowed for subdomains
// $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
// if (!empty($sitesDomain)) {
// $deniedDomains[] = $sitesDomain;
// }
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
if (!empty($functionsDomain)) {
@@ -108,15 +109,18 @@ class Create extends Action
}
// Validate domain format and appwrite.network specific rules
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain) && \str_ends_with($domain, '.' . ltrim($sitesDomain, '.'))) {
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
}
}
// Create domain object for further processing
try {
$domain = new Domain($domain);
} catch (\Throwable) {
} catch (\Throwable $e) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.');
}
@@ -85,10 +85,11 @@ class Create extends Action
$mainDomain = System::getEnv('_APP_DOMAIN', '');
$deniedDomains[] = $mainDomain;
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain)) {
$deniedDomains[] = $sitesDomain;
}
// Don't add sites domain to denied list - it should be allowed for subdomains
// $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
// if (!empty($sitesDomain)) {
// $deniedDomains[] = $sitesDomain;
// }
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
if (!empty($functionsDomain)) {
@@ -113,9 +114,12 @@ class Create extends Action
}
// Validate domain format and appwrite.network specific rules
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain) && \str_ends_with($domain, '.' . ltrim($sitesDomain, '.'))) {
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
}
}
// Create domain object for further processing
@@ -88,10 +88,11 @@ class Create extends Action
$mainDomain = System::getEnv('_APP_DOMAIN', '');
$deniedDomains[] = $mainDomain;
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain)) {
$deniedDomains[] = $sitesDomain;
}
// Don't add sites domain to denied list - it should be allowed for subdomains
// $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
// if (!empty($sitesDomain)) {
// $deniedDomains[] = $sitesDomain;
// }
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
if (!empty($functionsDomain)) {
@@ -116,9 +117,12 @@ class Create extends Action
}
// Validate domain format and appwrite.network specific rules
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain) && \str_ends_with($domain, '.' . ltrim($sitesDomain, '.'))) {
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
}
}
// Create domain object for further processing
@@ -85,10 +85,11 @@ class Create extends Action
$mainDomain = System::getEnv('_APP_DOMAIN', '');
$deniedDomains[] = $mainDomain;
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain)) {
$deniedDomains[] = $sitesDomain;
}
// Don't add sites domain to denied list - it should be allowed for subdomains
// $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
// if (!empty($sitesDomain)) {
// $deniedDomains[] = $sitesDomain;
// }
$functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', '');
if (!empty($functionsDomain)) {
@@ -113,9 +114,12 @@ class Create extends Action
}
// Validate domain format and appwrite.network specific rules
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
if (!empty($sitesDomain) && \str_ends_with($domain, '.' . ltrim($sitesDomain, '.'))) {
$appwriteNetworkValidator = new AppwriteDomain();
if (!$appwriteNetworkValidator->isValid($domain)) {
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, $appwriteNetworkValidator->getDescription());
}
}
// Create domain object for further processing
@@ -27,7 +27,7 @@ class ProjectsCustomServerTest extends Scope
]);
$response = $this->client->call(Client::METHOD_POST, '/proxy/rules/api', $headers, [
'domain' => $testId . '-api.appwrite.test',
'domain' => $testId . '-api.' . System::getEnv('_APP_DOMAIN_SITES', 'appwrite.network'),
]);
$this->assertEquals(201, $response['headers']['status-code']);