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"