git » spf » commit 54e4d8f

test: Add tests for NXDOMAIN responses

author Alberto Bertogli
2022-08-01 19:45:19 UTC
committer Alberto Bertogli
2022-08-01 20:43:52 UTC
parent 4cb0f61d754493b299493f6a574cb26688bdbb5f

test: Add tests for NXDOMAIN responses

The RFC is clear that NXDOMAIN errors should be treated as if the server
returned zero answers: https://datatracker.ietf.org/doc/html/rfc7208#section-5

Based on that, some specific behaviour is expected; for example on how
to handle non-existing MX records, or a non-existing redirect target.

This patch adds tests for some of those behaviours (the ones we already
handle correctly and are not otherwise covered), to prevent future
regressions.

Thanks to Matthias Schneider <ms@wck.biz> for reporting these issues in
https://github.com/albertito/spf/issues/5.

testdata/blitirispf-tests.yml +42 -0

diff --git a/testdata/blitirispf-tests.yml b/testdata/blitirispf-tests.yml
index 5730dc4..5da8fa4 100644
--- a/testdata/blitirispf-tests.yml
+++ b/testdata/blitirispf-tests.yml
@@ -257,3 +257,45 @@ zonedata:
     - MX: [1, blah1]
     - MX: [2, blah2]
     - MX: [3, blah3]
+---
+description: NXDOMAIN tests
+tests:
+  all-mx-not-found:
+    description: |
+      Check that if none of the MXs is not found, we continue evaluating the
+      rest of the terms.
+    mailfrom: "foo@d01"
+    host: 1.2.3.4
+    result: pass
+  domain-not-found:
+    description: |
+      Check if the top-level domain is not found (which is different that it
+      existing but having no TXT record).
+    mailfrom: "foo@doesnotexist"
+    host: 1.2.3.4
+    result: none
+  include-not-found:
+    description: |
+      For include, if the recursive check returns None, it should make the
+      evaluation return PermError.
+    mailfrom: "foo@d02"
+    host: 1.2.3.4
+    result: permerror
+  redirect-not-found:
+    description: |
+      For redirect, if the recursive check returns None, it should make the
+      evaluation return PermError.
+    mailfrom: "foo@d03"
+    host: 1.2.3.4
+    result: permerror
+zonedata:
+  d01:
+    - SPF: v=spf1 mx ip4:1.2.3.4 -all
+    - MX: [10, "doesnotexist"]
+    - MX: [20, "doesnotexist"]
+  d02:
+    - SPF: v=spf1 include:doesnotexist all
+  d03:
+    - SPF: v=spf1 redirect=doesnotexist
+  sender:
+    - A: 1.2.3.4