]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Use more concise syntax to check responses in rpzextra tests
authorTom Krizek <tkrizek@isc.org>
Thu, 23 Mar 2023 13:41:05 +0000 (14:41 +0100)
committerOndřej Surý <ondrej@isc.org>
Tue, 4 Apr 2023 14:27:48 +0000 (16:27 +0200)
All the answers are expected to have exactly one resource record. Check
it directly instead of iterating over all (possible) records.

(cherry picked from commit 2ed26609b86b3748c1254789616fa8a4893a054e)

bin/tests/system/rpzextra/tests_rpz_multiple_views.py
bin/tests/system/rpzextra/tests_rpz_passthru_logging.py

index d39eb2cf5cc340a5005773b9b08310d85d151c8a..a948cbc27b51d46bcbb51e7948acfc15bed7c7f7 100644 (file)
@@ -15,7 +15,7 @@ import time
 
 import pytest
 
-pytest.importorskip("dns")
+pytest.importorskip("dns", minversion="2.0.0")
 import dns.resolver
 
 
@@ -53,8 +53,7 @@ def test_rpz_multiple_views(named_port):
         resolver.resolve("baddomain.", "A", source="10.53.0.1")
 
     ans = resolver.resolve("gooddomain.", "A", source="10.53.0.1")
-    for rd in ans:
-        assert rd.address == "10.53.0.2"
+    assert ans[0].address == "10.53.0.2"
 
     ans = resolver.resolve("allowed.", "A", source="10.53.0.1")
     assert ans[0].address == "10.53.0.2"
@@ -64,12 +63,10 @@ def test_rpz_multiple_views(named_port):
     # - baddomain.com is allowed
     # - gooddomain.com is allowed
     ans = resolver.resolve("baddomain.", "A", source="10.53.0.2")
-    for rd in ans:
-        assert rd.address == "10.53.0.2"
+    assert ans[0].address == "10.53.0.2"
 
     ans = resolver.resolve("gooddomain.", "A", source="10.53.0.2")
-    for rd in ans:
-        assert rd.address == "10.53.0.2"
+    assert ans[0].address == "10.53.0.2"
 
     with pytest.raises(dns.resolver.NXDOMAIN):
         resolver.resolve("allowed.", "A", source="10.53.0.2")
@@ -79,12 +76,10 @@ def test_rpz_multiple_views(named_port):
     # - baddomain.com is allowed
     # - allowed. is allowed
     ans = resolver.resolve("baddomain.", "A", source="10.53.0.3")
-    for rd in ans:
-        assert rd.address == "10.53.0.2"
+    assert ans[0].address == "10.53.0.2"
 
     ans = resolver.resolve("gooddomain.", "A", source="10.53.0.3")
-    for rd in ans:
-        assert rd.address == "10.53.0.2"
+    assert ans[0].address == "10.53.0.2"
 
     ans = resolver.resolve("allowed.", "A", source="10.53.0.3")
     assert ans[0].address == "10.53.0.2"
@@ -107,8 +102,7 @@ def test_rpz_multiple_views(named_port):
     # - gooddomain.com isn't allowed (CNAME .), should return NXDOMAIN
     # - allowed.com isn't allowed (CNAME .), should return NXDOMAIN
     ans = resolver.resolve("baddomain.", "A", source="10.53.0.5")
-    for rd in ans:
-        assert rd.address == "10.53.0.2"
+    assert ans[0].address == "10.53.0.2"
 
     with pytest.raises(dns.resolver.NXDOMAIN):
         resolver.resolve("gooddomain.", "A", source="10.53.0.5")
index 65cd3c5b1046a5490e4d6be5a8e571786fc66b74..f5776bd967b98045fde43cb8668065d94fc0b75f 100755 (executable)
@@ -15,7 +15,7 @@ import os
 
 import pytest
 
-pytest.importorskip("dns")
+pytest.importorskip("dns", minversion="2.0.0")
 import dns.resolver
 
 
@@ -26,8 +26,7 @@ def test_rpz_passthru_logging(named_port):
 
     # Should generate a log entry into rpz_passthru.txt
     ans = resolver.resolve("allowed.", "A", source="10.53.0.1")
-    for rd in ans:
-        assert rd.address == "10.53.0.2"
+    assert ans[0].address == "10.53.0.2"
 
     # baddomain.com isn't allowed (CNAME .), should return NXDOMAIN
     # Should generate a log entry into rpz.txt