From e508f049bfc7edec7df91cab236fa2d3ec189e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 12 Sep 2025 20:37:36 +0200 Subject: [PATCH 1/4] Prepare coreDNS for proxy tests --- .env | 4 ++-- docker-compose.yml | 22 +++++++++++++++++++ .../Services/Proxy/ProxyCustomServerTest.php | 11 ++++++++++ tests/resources/coredns/Corefile | 15 +++++++++++++ tests/resources/coredns/webapp.com.zone | 19 ++++++++++++++++ .../resources/coredns/wrong-a-webapp.com.zone | 8 +++++++ 6 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 tests/resources/coredns/Corefile create mode 100644 tests/resources/coredns/webapp.com.zone create mode 100644 tests/resources/coredns/wrong-a-webapp.com.zone diff --git a/.env b/.env index bb21aa50f2..c276540f41 100644 --- a/.env +++ b/.env @@ -26,8 +26,8 @@ _APP_DOMAIN=traefik _APP_CONSOLE_DOMAIN=localhost _APP_DOMAIN_FUNCTIONS=functions.localhost _APP_DOMAIN_SITES=sites.localhost -_APP_DOMAIN_TARGET_CNAME=test.l -_APP_DOMAIN_TARGET_A=127.0.0.1 +_APP_DOMAIN_TARGET_CNAME=cname.tests.appwrite.io +_APP_DOMAIN_TARGET_A=203.0.0.1 _APP_DOMAIN_TARGET_AAAA=::1 _APP_DOMAIN_TARGET_CAA=digicert.com _APP_RULES_FORMAT=md5 diff --git a/docker-compose.yml b/docker-compose.yml index 5e65122256..86c88a3b27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -89,9 +89,12 @@ services: - ./public:/usr/src/code/public - ./src:/usr/src/code/src - ./dev:/usr/src/code/dev + dns: + - 172.16.238.100 depends_on: - mariadb - redis + - coredns # - clamav entrypoint: - php @@ -524,9 +527,12 @@ services: image: appwrite-dev networks: - appwrite + dns: + - 172.16.238.100 depends_on: - redis - mariadb + - coredns volumes: - appwrite-config:/storage/config:rw - appwrite-certificates:/storage/certificates:rw @@ -1068,6 +1074,19 @@ services: - appwrite volumes: - appwrite-redis:/data:rw + + coredns: # DNS server for testing purposes (Proxy APIs) + image: coredns/coredns:1.12.4 + container_name: appwrite-coredns + <<: *x-logging + command: ["-conf", "/mnt/resources/Corefile"] + ports: + - "1053:1053" + networks: + appwrite: + ipv4_address: 172.16.238.100 + volumes: + - ./tests/resources/coredns:/mnt/resources:ro # Dev Tools Start ------------------------------------------------------------------------------------------ # @@ -1146,6 +1165,9 @@ networks: name: gateway appwrite: name: appwrite + ipam: + config: + - subnet: 172.16.238.0/24 runtimes: name: runtimes diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index 5a1cd1dea6..4778e5e69f 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -540,4 +540,15 @@ class ProxyCustomServerTest extends Scope $this->assertEquals(0, $rules['body']['total']); $this->assertCount(0, $rules['body']['rules']); } + + public function testRuleVerification(): void + { + // TODO: Implement + // wrong-a-webapp.com + // webapp.com + // stage.webapp.com + // stage-wrong-cname.webapp.com + // stage-wrong-caa.webapp.com + // stage-correct-caa.webapp.com + } } diff --git a/tests/resources/coredns/Corefile b/tests/resources/coredns/Corefile new file mode 100644 index 0000000000..591291aed3 --- /dev/null +++ b/tests/resources/coredns/Corefile @@ -0,0 +1,15 @@ +# Re-use public resolver to answer unknown queries +. { + forward . 1.1.1.1 +} + +# Zones configuration +webapp.com { + file /mnt/resources/webapp.com.zone +} + +# Zones configuration +wrong-a-webapp.com { + file /mnt/resources/wrong-a-webapp.com.zone +} + diff --git a/tests/resources/coredns/webapp.com.zone b/tests/resources/coredns/webapp.com.zone new file mode 100644 index 0000000000..46ca9b65b2 --- /dev/null +++ b/tests/resources/coredns/webapp.com.zone @@ -0,0 +1,19 @@ +; Nessessary setup +$ORIGIN webapp.com. +@ IN SOA ns1.webapp.com. hostmaster.webapp.com. (2025091201 7200 3600 1209600 3600) +@ IN NS ns1.webapp.com. +ns1 IN A 127.0.0.1 + +; Custom DNS records +@ IN A 203.0.0.1 + +stage IN CNAME cname.tests.appwrite.io +; No CAA record intentionally + +stage-wrong-cname IN CNAME cname-wrong.tests.appwrite.io + +stage-wrong-caa IN CNAME cname.tests.appwrite.io +stage-wrong-caa IN CAA 0 issue "unknown-issuer.org" + +stage-correct-caa IN CNAME cname.tests.appwrite.io +stage-correct-caa IN CAA 0 issue "digicert.com" diff --git a/tests/resources/coredns/wrong-a-webapp.com.zone b/tests/resources/coredns/wrong-a-webapp.com.zone new file mode 100644 index 0000000000..d4997419b4 --- /dev/null +++ b/tests/resources/coredns/wrong-a-webapp.com.zone @@ -0,0 +1,8 @@ +; Nessessary setup +$ORIGIN wrong-a-webapp.com.zone. +@ IN SOA ns1.wrong-a-webapp.com.zone. hostmaster.wrong-a-webapp.com.zone. (2025091201 7200 3600 1209600 3600) +@ IN NS ns1.wrong-a-webapp.com.zone. +ns1 IN A 127.0.0.1 + +; Custom DNS records +@ IN A 203.0.0.5 From cf0838d75bc2ac72fdfe1fb2f6a753d272f979b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 12 Sep 2025 20:37:46 +0200 Subject: [PATCH 2/4] Formatting fix --- tests/e2e/Services/Proxy/ProxyCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index 4778e5e69f..32f8e96a3f 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -540,7 +540,7 @@ class ProxyCustomServerTest extends Scope $this->assertEquals(0, $rules['body']['total']); $this->assertCount(0, $rules['body']['rules']); } - + public function testRuleVerification(): void { // TODO: Implement From 636ce72e522556cdc3b2ffee51d6601045eff2ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 12 Sep 2025 21:19:36 +0200 Subject: [PATCH 3/4] Implement E2E proxy tests --- .env | 2 +- docker-compose.yml | 1 + .../Services/Proxy/ProxyCustomServerTest.php | 115 ++++++++++++++++-- tests/resources/coredns/webapp.com.zone | 10 +- 4 files changed, 117 insertions(+), 11 deletions(-) diff --git a/.env b/.env index c276540f41..3f46179f0f 100644 --- a/.env +++ b/.env @@ -26,7 +26,7 @@ _APP_DOMAIN=traefik _APP_CONSOLE_DOMAIN=localhost _APP_DOMAIN_FUNCTIONS=functions.localhost _APP_DOMAIN_SITES=sites.localhost -_APP_DOMAIN_TARGET_CNAME=cname.tests.appwrite.io +_APP_DOMAIN_TARGET_CNAME=cname.localhost _APP_DOMAIN_TARGET_A=203.0.0.1 _APP_DOMAIN_TARGET_AAAA=::1 _APP_DOMAIN_TARGET_CAA=digicert.com diff --git a/docker-compose.yml b/docker-compose.yml index 86c88a3b27..804435ab36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1078,6 +1078,7 @@ services: coredns: # DNS server for testing purposes (Proxy APIs) image: coredns/coredns:1.12.4 container_name: appwrite-coredns + restart: unless-stopped <<: *x-logging command: ["-conf", "/mnt/resources/Corefile"] ports: diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index 32f8e96a3f..1e321f9ce8 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -543,12 +543,113 @@ class ProxyCustomServerTest extends Scope public function testRuleVerification(): void { - // TODO: Implement - // wrong-a-webapp.com - // webapp.com - // stage.webapp.com - // stage-wrong-cname.webapp.com - // stage-wrong-caa.webapp.com - // stage-correct-caa.webapp.com + // Site rule can verify + $setup = $this->setupSite(); + $siteId = $setup['siteId']; + + $rule = $this->createSiteRule('stage-site.webapp.com', $siteId); + \var_dump($rule); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['validationLogs']); + + $this->cleanupRule($rule['body']['$id']); + $this->cleanupSite($siteId); + + // Function rule can verify + $setup = $this->setupFunction(); + $functionId = $setup['functionId']; + + $rule = $this->createFunctionRule('stage-function.webapp.com', $functionId); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + + $rule2 = $this->createAPIRule('stage-site.webapp.com'); + $this->assertEquals(201, $rule2['headers']['status-code']); + $this->assertEquals('created', $rule2['body']['status']); + $this->assertStringContainsString('has incorrect A value', implode(' ', $rule2['body']['validationLogs'])); + + $this->cleanupRule($rule['body']['$id']); + $this->cleanupRule($rule2['body']['$id']); + $this->cleanupFunction($functionId); + + // 3. Wrong A record fails to verify + $rule = $this->createAPIRule('wrong-a-webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('has incorrect A value', implode(' ', $rule['body']['validationLogs'])); + + $ruleId = $rule['body']['$id']; + $updatedRule = $this->updateRuleVerification($ruleId); + $this->assertEquals(200, $updatedRule['headers']['status-code']); + $this->assertEquals('created', $updatedRule['body']['status']); + $this->assertStringContainsString('has incorrect A value', implode(' ', $updatedRule['body']['validationLogs'])); + + $this->cleanupRule($ruleId); + + // 4. Correct A record can verify + $rule = $this->createAPIRule('webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['validationLogs']); + + $this->cleanupRule($rule['body']['$id']); + + // 5. Correct CNAME record can verify (no CAA record) + $rule = $this->createAPIRule('stage.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + $this->assertEmpty($rule['body']['validationLogs']); + + $this->cleanupRule($rule['body']['$id']); + + // 6. Missing CNAME record fails to verify + $rule = $this->createAPIRule('stage-missing-cname.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('is missing CNAME record', implode(' ', $rule['body']['validationLogs'])); + + $ruleId = $rule['body']['$id']; + $updatedRule = $this->updateRuleVerification($ruleId); + $this->assertEquals(200, $updatedRule['headers']['status-code']); + $this->assertEquals('created', $updatedRule['body']['status']); + $this->assertStringContainsString('is missing CNAME record', implode(' ', $updatedRule['body']['validationLogs'])); + + $this->cleanupRule($ruleId); + + // 7. Wrong CNAME record fails to verify + $rule = $this->createAPIRule('stage-wrong-cname.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('has incorrect CNAME value', implode(' ', $rule['body']['validationLogs'])); + + $ruleId = $rule['body']['$id']; + $updatedRule = $this->updateRuleVerification($ruleId); + $this->assertEquals(200, $updatedRule['headers']['status-code']); + $this->assertEquals('created', $updatedRule['body']['status']); + $this->assertStringContainsString('has incorrect CNAME value', implode(' ', $updatedRule['body']['validationLogs'])); + + $this->cleanupRule($ruleId); + + // 8. Wrong CAA record fails to verify + $rule = $this->createAPIRule('stage-wrong-caa.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('has incorrect CAA value', implode(' ', $rule['body']['validationLogs'])); + + $ruleId = $rule['body']['$id']; + $updatedRule = $this->updateRuleVerification($ruleId); + $this->assertEquals(200, $updatedRule['headers']['status-code']); + $this->assertEquals('created', $updatedRule['body']['status']); + $this->assertStringContainsString('has incorrect CAA value', implode(' ', $updatedRule['body']['validationLogs'])); + + $this->cleanupRule($ruleId); + + // 9. Correct CAA record can verify + $rule = $this->createAPIRule('stage-correct-caa.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('verifying', $rule['body']['status']); + + $this->cleanupRule($rule['body']['$id']); } } diff --git a/tests/resources/coredns/webapp.com.zone b/tests/resources/coredns/webapp.com.zone index 46ca9b65b2..e35c7b9eae 100644 --- a/tests/resources/coredns/webapp.com.zone +++ b/tests/resources/coredns/webapp.com.zone @@ -7,13 +7,17 @@ ns1 IN A 127.0.0.1 ; Custom DNS records @ IN A 203.0.0.1 -stage IN CNAME cname.tests.appwrite.io +stage-site IN CNAME sites.localhost + +stage-function IN CNAME functions.localhost + +stage IN CNAME cname.localhost ; No CAA record intentionally stage-wrong-cname IN CNAME cname-wrong.tests.appwrite.io -stage-wrong-caa IN CNAME cname.tests.appwrite.io +stage-wrong-caa IN CNAME cname.localhost stage-wrong-caa IN CAA 0 issue "unknown-issuer.org" -stage-correct-caa IN CNAME cname.tests.appwrite.io +stage-correct-caa IN CNAME cname.localhost stage-correct-caa IN CAA 0 issue "digicert.com" From 6463892ba9a64ad7694cc45073cb27ce2bd69ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 13 Sep 2025 11:33:48 +0200 Subject: [PATCH 4/4] Fix tests --- .env | 2 +- .../Platform/Modules/Proxy/Http/Rules/Get.php | 13 +- .../Proxy/Http/Rules/Verification/Update.php | 13 +- .../Modules/Proxy/Http/Rules/XList.php | 13 +- .../Services/Proxy/ProxyCustomServerTest.php | 146 ++++++++++++------ tests/resources/coredns/webapp.com.zone | 12 +- 6 files changed, 135 insertions(+), 64 deletions(-) diff --git a/.env b/.env index 3f46179f0f..b9e5bc9732 100644 --- a/.env +++ b/.env @@ -21,7 +21,7 @@ _APP_OPTIONS_ROUTER_PROTECTION=disabled _APP_OPTIONS_FORCE_HTTPS=disabled _APP_OPTIONS_ROUTER_FORCE_HTTPS=disabled _APP_OPENSSL_KEY_V1=your-secret-key -_APP_DNS=8.8.8.8,1.1.1.1 +_APP_DNS=172.16.238.100 # CoreDNS _APP_DOMAIN=traefik _APP_CONSOLE_DOMAIN=localhost _APP_DOMAIN_FUNCTIONS=functions.localhost diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php index 70d27328a7..97b668a943 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Get.php @@ -68,8 +68,17 @@ class Get extends Action $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); $rule->setAttribute('logs', $certificate->getAttribute('logs', '')); $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); - if (new \DateTime($certificate->getUpdatedAt()) > new \DateTime($rule->getUpdatedAt())) { - $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + + $certificateHasUpdatedAt = $certificate->getUpdatedAt() !== null; + $ruleHasUpdatedAt = $rule->getUpdatedAt() !== null; + if ($certificateHasUpdatedAt) { + if ($ruleHasUpdatedAt) { + if (new \DateTime($certificate->getUpdatedAt()) > new \DateTime($rule->getUpdatedAt())) { + $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + } + } else { + $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + } } $response->dynamic($rule, Response::MODEL_PROXY_RULE); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php index 1024f870a7..55138b49d7 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/Verification/Update.php @@ -110,8 +110,17 @@ class Update extends Action $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); $rule->setAttribute('logs', $certificate->getAttribute('logs', '')); $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); - if (new \DateTime($certificate->getUpdatedAt()) > new \DateTime($rule->getUpdatedAt())) { - $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + + $certificateHasUpdatedAt = $certificate->getUpdatedAt() !== null; + $ruleHasUpdatedAt = $rule->getUpdatedAt() !== null; + if ($certificateHasUpdatedAt) { + if ($ruleHasUpdatedAt) { + if (new \DateTime($certificate->getUpdatedAt()) > new \DateTime($rule->getUpdatedAt())) { + $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + } + } else { + $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + } } $response->dynamic($rule, Response::MODEL_PROXY_RULE); diff --git a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php index bef7b31881..065c5a0b95 100644 --- a/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php +++ b/src/Appwrite/Platform/Modules/Proxy/Http/Rules/XList.php @@ -110,8 +110,17 @@ class XList extends Action $certificate = $dbForPlatform->getDocument('certificates', $rule->getAttribute('certificateId', '')); $rule->setAttribute('logs', $certificate->getAttribute('logs', '')); $rule->setAttribute('renewAt', $certificate->getAttribute('renewDate', '')); - if (new \DateTime($certificate->getUpdatedAt()) > new \DateTime($rule->getUpdatedAt())) { - $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + + $certificateHasUpdatedAt = $certificate->getUpdatedAt() !== null; + $ruleHasUpdatedAt = $rule->getUpdatedAt() !== null; + if ($certificateHasUpdatedAt) { + if ($ruleHasUpdatedAt) { + if (new \DateTime($certificate->getUpdatedAt()) > new \DateTime($rule->getUpdatedAt())) { + $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + } + } else { + $rule->setAttribute('$updatedAt', $certificate->getUpdatedAt()); + } } } diff --git a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php index 1e321f9ce8..50d978902f 100644 --- a/tests/e2e/Services/Proxy/ProxyCustomServerTest.php +++ b/tests/e2e/Services/Proxy/ProxyCustomServerTest.php @@ -15,6 +15,36 @@ class ProxyCustomServerTest extends Scope use ProjectCustom; use SideServer; + protected function tearDown(): void + { + // Cleanup for testRuleVerification test + // Required as it uses static domain name + $rules = $this->listRules([ + 'queries' => [ + Query::endsWith('domain', 'webapp.com')->toString(), + Query::limit(1000)->toString(), + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + foreach ($rules['body']['rules'] as $rule) { + $ruleId = $rule['$id']; + $response = $this->deleteRule($ruleId); + $this->assertEquals(204, $response['headers']['status-code']); + } + + if ($rules['body']['total'] > 0) { + $rules = $this->listRules([ + 'queries' => [ + Query::endsWith('domain', 'webapp.com')->toString(), + Query::limit(1) + ] + ]); + $this->assertEquals(200, $rules['headers']['status-code']); + $this->assertEquals(0, count($rules['body']['rules'])); + $this->assertEquals(0, $rules['body']['total']); + } + } + public function testCreateRule(): void { $domain = \uniqid() . '-api.myapp.com'; @@ -543,113 +573,127 @@ class ProxyCustomServerTest extends Scope public function testRuleVerification(): void { - // Site rule can verify - $setup = $this->setupSite(); - $siteId = $setup['siteId']; - + + // 1. Site rule can verify + $site = $this->setupSite(); + $siteId = $site['siteId']; + $rule = $this->createSiteRule('stage-site.webapp.com', $siteId); - \var_dump($rule); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['validationLogs']); - + $this->assertEmpty($rule['body']['verificationLogs']); + $this->cleanupRule($rule['body']['$id']); $this->cleanupSite($siteId); - // Function rule can verify - $setup = $this->setupFunction(); - $functionId = $setup['functionId']; - + // 2. Function rule can verify + $function = $this->setupFunction(); + $functionId = $function['functionId']; + $rule = $this->createFunctionRule('stage-function.webapp.com', $functionId); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); - - $rule2 = $this->createAPIRule('stage-site.webapp.com'); - $this->assertEquals(201, $rule2['headers']['status-code']); - $this->assertEquals('created', $rule2['body']['status']); - $this->assertStringContainsString('has incorrect A value', implode(' ', $rule2['body']['validationLogs'])); - + $this->assertEmpty($rule['body']['verificationLogs']); $this->cleanupRule($rule['body']['$id']); - $this->cleanupRule($rule2['body']['$id']); + + $rule = $this->createAPIRule('stage-site.webapp.com'); + $this->assertEquals(201, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['verificationLogs']); + $this->cleanupRule($rule['body']['$id']); + $this->cleanupFunction($functionId); // 3. Wrong A record fails to verify $rule = $this->createAPIRule('wrong-a-webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('has incorrect A value', implode(' ', $rule['body']['validationLogs'])); - + $this->assertStringContainsString('is missing CNAME record', $rule['body']['verificationLogs']); + $ruleId = $rule['body']['$id']; - $updatedRule = $this->updateRuleVerification($ruleId); - $this->assertEquals(200, $updatedRule['headers']['status-code']); - $this->assertEquals('created', $updatedRule['body']['status']); - $this->assertStringContainsString('has incorrect A value', implode(' ', $updatedRule['body']['validationLogs'])); - + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->cleanupRule($ruleId); // 4. Correct A record can verify $rule = $this->createAPIRule('webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['validationLogs']); - + $this->assertEmpty($rule['body']['verificationLogs']); + $this->cleanupRule($rule['body']['$id']); // 5. Correct CNAME record can verify (no CAA record) $rule = $this->createAPIRule('stage.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); - $this->assertEmpty($rule['body']['validationLogs']); - + $this->assertEmpty($rule['body']['verificationLogs']); + $this->cleanupRule($rule['body']['$id']); // 6. Missing CNAME record fails to verify $rule = $this->createAPIRule('stage-missing-cname.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('is missing CNAME record', implode(' ', $rule['body']['validationLogs'])); - + $this->assertStringContainsString('is missing CNAME record', $rule['body']['verificationLogs']); + $ruleId = $rule['body']['$id']; - $updatedRule = $this->updateRuleVerification($ruleId); - $this->assertEquals(200, $updatedRule['headers']['status-code']); - $this->assertEquals('created', $updatedRule['body']['status']); - $this->assertStringContainsString('is missing CNAME record', implode(' ', $updatedRule['body']['validationLogs'])); - + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('is missing CNAME record', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->cleanupRule($ruleId); // 7. Wrong CNAME record fails to verify $rule = $this->createAPIRule('stage-wrong-cname.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('has incorrect CNAME value', implode(' ', $rule['body']['validationLogs'])); - + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['verificationLogs']); + $ruleId = $rule['body']['$id']; - $updatedRule = $this->updateRuleVerification($ruleId); - $this->assertEquals(200, $updatedRule['headers']['status-code']); - $this->assertEquals('created', $updatedRule['body']['status']); - $this->assertStringContainsString('has incorrect CNAME value', implode(' ', $updatedRule['body']['validationLogs'])); - + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('has incorrect CNAME value', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->cleanupRule($ruleId); // 8. Wrong CAA record fails to verify $rule = $this->createAPIRule('stage-wrong-caa.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('created', $rule['body']['status']); - $this->assertStringContainsString('has incorrect CAA value', implode(' ', $rule['body']['validationLogs'])); - + $this->assertStringContainsString('has incorrect CAA value', $rule['body']['verificationLogs']); + $ruleId = $rule['body']['$id']; - $updatedRule = $this->updateRuleVerification($ruleId); - $this->assertEquals(200, $updatedRule['headers']['status-code']); - $this->assertEquals('created', $updatedRule['body']['status']); - $this->assertStringContainsString('has incorrect CAA value', implode(' ', $updatedRule['body']['validationLogs'])); - + $rule = $this->updateRuleVerification($ruleId); + $this->assertEquals(400, $rule['headers']['status-code']); + $this->assertStringContainsString('has incorrect CAA value', $rule['body']['message']); + + $rule = $this->getRule($ruleId); + $this->assertEquals(200, $rule['headers']['status-code']); + $this->assertEquals('created', $rule['body']['status']); + $this->cleanupRule($ruleId); // 9. Correct CAA record can verify $rule = $this->createAPIRule('stage-correct-caa.webapp.com'); $this->assertEquals(201, $rule['headers']['status-code']); $this->assertEquals('verifying', $rule['body']['status']); - + $this->assertEmpty($rule['body']['verificationLogs']); + $this->cleanupRule($rule['body']['$id']); } } diff --git a/tests/resources/coredns/webapp.com.zone b/tests/resources/coredns/webapp.com.zone index e35c7b9eae..55026ca94b 100644 --- a/tests/resources/coredns/webapp.com.zone +++ b/tests/resources/coredns/webapp.com.zone @@ -7,17 +7,17 @@ ns1 IN A 127.0.0.1 ; Custom DNS records @ IN A 203.0.0.1 -stage-site IN CNAME sites.localhost +stage-site IN CNAME sites.localhost. -stage-function IN CNAME functions.localhost +stage-function IN CNAME functions.localhost. -stage IN CNAME cname.localhost +stage IN CNAME cname.localhost. ; No CAA record intentionally -stage-wrong-cname IN CNAME cname-wrong.tests.appwrite.io +stage-wrong-cname IN CNAME cname-wrong.tests.appwrite.io. -stage-wrong-caa IN CNAME cname.localhost +stage-wrong-caa IN A 203.0.0.1 stage-wrong-caa IN CAA 0 issue "unknown-issuer.org" -stage-correct-caa IN CNAME cname.localhost +stage-correct-caa IN CNAME cname.localhost. stage-correct-caa IN CAA 0 issue "digicert.com"