From 9cc152d17343b8e65229cc18932fa62713c2b7ae Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Fri, 14 Nov 2025 16:23:14 +0530 Subject: [PATCH] Change param to accept only array --- src/Appwrite/Network/Validator/DNS.php | 32 +++---------------- .../Platform/Modules/Proxy/Action.php | 16 ++-------- tests/unit/Network/Validators/DNSTest.php | 2 +- 3 files changed, 8 insertions(+), 42 deletions(-) diff --git a/src/Appwrite/Network/Validator/DNS.php b/src/Appwrite/Network/Validator/DNS.php index e6c05c1892..b1e3e63730 100644 --- a/src/Appwrite/Network/Validator/DNS.php +++ b/src/Appwrite/Network/Validator/DNS.php @@ -18,13 +18,13 @@ class DNS extends BaseDNS * @param int $type Type of DNS record to validate * For value, use const from Record, such as Record::TYPE_A * When using CAA type, you can provide exact match, or just issuer domain as $target - * @param string|array $dnsServers DNS server IP(s) or domain(s) to use for validation + * @param array $dnsServers DNS server IP(s) or domain(s) to use for validation */ - public function __construct(string $target, int $type = Record::TYPE_CNAME, string|array $dnsServers = self::DEFAULT_DNS_SERVER) + public function __construct(string $target, int $type = Record::TYPE_CNAME, array $dnsServers = []) { - parent::__construct($target, $type, is_array($dnsServers) ? $dnsServers[0] : $dnsServers); + parent::__construct($target, $type, $dnsServers[0] ?? self::DEFAULT_DNS_SERVER); - $this->dnsServers = is_array($dnsServers) ? $dnsServers : [$dnsServers]; + $this->dnsServers = $dnsServers; } /** @@ -35,10 +35,6 @@ class DNS extends BaseDNS */ public function isValid(mixed $value): bool { - if (\count($this->dnsServers) === 1) { - return $this->isValidWithDNSServer($value, $this->dnsServers[0]); - } - $wg = new WaitGroup(); $failedValidator = null; @@ -71,24 +67,4 @@ class DNS extends BaseDNS return true; } - - /** - * Validate with a specific DNS server - * - * @param mixed $value - * @param string $dnsServer - * @return bool - */ - protected function isValidWithDNSServer(mixed $value, string $dnsServer): bool - { - $validator = new BaseDNS($this->target, $this->type, $dnsServer); - $result = $validator->isValid($value); - - $this->count = $validator->count; - $this->value = $validator->value; - $this->reason = $validator->reason; - $this->records = $validator->records; - - return $result; - } } diff --git a/src/Appwrite/Platform/Modules/Proxy/Action.php b/src/Appwrite/Platform/Modules/Proxy/Action.php index 2d365d8334..340913b1c0 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Action.php +++ b/src/Appwrite/Platform/Modules/Proxy/Action.php @@ -19,18 +19,6 @@ class Action extends PlatformAction { } - /** - * Parse DNS servers from environment variable - * - * @return array - */ - protected function getDNSServers(): array - { - $dnsEnv = System::getEnv('_APP_DNS', '8.8.8.8'); - $servers = \array_map('trim', \explode(',', $dnsEnv)); - return \array_filter($servers, fn ($server) => !empty($server)); - } - /** * Verify or re-verify a rule * @@ -43,7 +31,9 @@ class Action extends PlatformAction public function verifyRule(Document $rule, ?Log $log = null, ?string $verificationDomainAPI = null, ?string $verificationDomainFunction = null): void { $dnsValidatorClass = $this->dnsValidatorClass; - $dnsServers = $this->getDNSServers(); + $dnsEnv = System::getEnv('_APP_DNS', '8.8.8.8'); + $servers = \array_map('trim', \explode(',', $dnsEnv)); + $dnsServers = \array_filter($servers, fn ($server) => !empty($server)); $domain = new Domain($rule->getAttribute('domain', '')); diff --git a/tests/unit/Network/Validators/DNSTest.php b/tests/unit/Network/Validators/DNSTest.php index f00f1799de..6e4a78022f 100644 --- a/tests/unit/Network/Validators/DNSTest.php +++ b/tests/unit/Network/Validators/DNSTest.php @@ -10,7 +10,7 @@ class DNSTest extends TestCase { public function testSingleDNSServer(): void { - $validator = new DNS('appwrite.io', Record::TYPE_CNAME, '8.8.8.8'); + $validator = new DNS('appwrite.io', Record::TYPE_CNAME, ['8.8.8.8']); $this->assertEquals(false, $validator->isValid('')); $this->assertEquals(false, $validator->isValid(null));