]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
ede: add pytest coverage
authorTomas Krizek <tomas.krizek@nic.cz>
Mon, 20 Dec 2021 14:16:38 +0000 (15:16 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 21 Dec 2021 14:02:09 +0000 (15:02 +0100)
ci/debian-11/Dockerfile
tests/pytests/templates/kresd.conf.j2
tests/pytests/test_edns.py [new file with mode: 0644]
tests/pytests/utils.py

index 4b6db61d6318787c66b1ee061dce4413b003c878..49deb5e8f297827100ee1592d37479c2c7a7d911 100644 (file)
@@ -36,8 +36,10 @@ RUN pip3 install --upgrade pip
 RUN pip3 install pylint
 RUN pip3 install pep8
 RUN pip3 install pytest-xdist
+# FIXME replace with dnspython >= 2.2.0 once released
+RUN pip3 install git+git://github.com/bwelling/dnspython.git@72348d4698a8f8b209fbdf9e72738904ad31b930
 # tests/pytest dependencies: skip over broken versions
-RUN pip3 install 'dnspython != 2.0.0' jinja2 'pytest != 6.0.0' pytest-html pytest-xdist
+RUN pip3 install jinja2 'pytest != 6.0.0' pytest-html pytest-xdist
 # apkg for packaging
 RUN pip3 install apkg
 
index 550c224779c357481ccc74e50d4b986e7706e2fa..b87515c9b563be2f81777278ffe4ba155aa2b0cc 100644 (file)
@@ -46,6 +46,11 @@ policy.add(policy.all(
 policy.add(policy.suffix(policy.PASS, {todname('test.')}))
 {% endif %}
 
+-- EDNS EDE tests
+policy.add(policy.suffix(policy.DENY, {todname('deny.test.')}))
+policy.add(policy.suffix(policy.REFUSE, {todname('refuse.test.')}))
+policy.add(policy.suffix(policy.ANSWER({ [kres.type.A] = { rdata=kres.str2ip('192.0.2.7'), ttl=300 } }), {todname('forge.test.')}))
+
 -- make sure DNSSEC is turned off for tests
 trust_anchors.remove('.')
 modules.unload("ta_update")
diff --git a/tests/pytests/test_edns.py b/tests/pytests/test_edns.py
new file mode 100644 (file)
index 0000000..b19af37
--- /dev/null
@@ -0,0 +1,22 @@
+# SPDX-License-Identifier: GPL-3.0-or-later
+"""EDNS tests"""
+
+import dns
+import pytest
+
+import utils
+
+
+@pytest.mark.parametrize('dname, code, text', [
+    ('deny.test.', dns.edns.EDECode.BLOCKED, 'CR36'),
+    ('refuse.test.', dns.edns.EDECode.PROHIBITED, 'EIM4'),
+    ('forge.test.', dns.edns.EDECode.FORGED_ANSWER, '5DO5'),
+])
+def test_edns_ede(kresd_sock, dname, code, text):
+    """Check that kresd responds with EDNS EDE codes in selected cases."""
+    buff, msgid = utils.get_msgbuff(dname)
+    kresd_sock.sendall(buff)
+    answer = utils.receive_parse_answer(kresd_sock)
+    assert answer.id == msgid
+    assert answer.options[0].code == code
+    assert answer.options[0].text == text
index 812b6f3ce61ed66cce82a03b5d676f3f77aadfb2..4b995d4bba51aa396a65c46d50547455927d328f 100644 (file)
@@ -50,7 +50,7 @@ def prepare_wire(
         qclass=dns.rdataclass.IN,
         msgid=None):
     """Utility function to generate DNS wire format message"""
-    msg = dns.message.make_query(qname, qtype, qclass)
+    msg = dns.message.make_query(qname, qtype, qclass, use_edns=True)
     if msgid is not None:
         msg.id = msgid
     return msg.to_wire(), msg.id