From 1030dc7d4305d17645bae5440d3497d005c425a8 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Thu, 4 Aug 2022 17:33:30 +0200 Subject: [PATCH] Fix flake8 --- test/src/tests/dns.py | 88 ++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/test/src/tests/dns.py b/test/src/tests/dns.py index 317ea78..01b24b4 100644 --- a/test/src/tests/dns.py +++ b/test/src/tests/dns.py @@ -14,27 +14,20 @@ # You should have received a copy of the GNU General Public License # along with Masscanned. If not, see . -from socket import AF_INET6 -import struct - from scapy.compat import raw from scapy.layers.dns import DNS, DNSQR from scapy.layers.inet import IP, UDP -from scapy.layers.inet6 import IPv6 from scapy.layers.l2 import Ether -from scapy.packet import Raw -from scapy.pton_ntop import inet_pton from scapy.sendrecv import srp1 -from ..conf import IPV4_ADDR, IPV6_ADDR, MAC_ADDR -from ..core import test, check_ip_checksum, check_ipv6_checksum +from ..conf import IPV4_ADDR, MAC_ADDR +from ..core import test, check_ip_checksum @test def test_ipv4_udp_dns_in_a(): sports = [53, 13274, 0] dports = [53, 5353, 80, 161, 24732] - payload = DNS() for sport in sports: for dport in dports: for domain in ["example.com", "www.example.com", "masscan.ned"]: @@ -53,41 +46,41 @@ def test_ipv4_udp_dns_in_a(): udp = resp[UDP] assert udp.sport == dport, "unexpected UDP sport: {}".format(udp.sport) assert udp.dport == sport, "unexpected UDP dport: {}".format(udp.dport) - if not DNS in udp: + if DNS not in udp: try: dns_rep = DNS(udp.load) except Exception: raise AssertionError("no DNS layer found") else: dns_rep = udp[DNS] - assert dns_rep.id == 1234, f"unexpected id value: {rr.id}" - assert dns_rep.qr == True, f"unexpected qr value" - assert dns_rep.opcode == 0, f"unexpected opcode value" - assert dns_rep.aa == True, f"unexpected aa value" - assert dns_rep.tc == False, f"unexpected tc value" - assert dns_rep.rd == False, f"unexpected rd value" - assert dns_rep.ra == False, f"unexpected ra value" - assert dns_rep.z == 0, f"unexpected z value" - assert dns_rep.rcode == 0, f"unexpected rcode value" - assert dns_rep.qdcount == 1, f"unexpected qdcount value" - assert dns_rep.ancount == 1, f"unexpected ancount value" - assert dns_rep.nscount == 0, f"unexpected nscount value" - assert dns_rep.arcount == 0, f"unexpected arcount value" + assert dns_rep.id == 1234, f"unexpected id value: {dns_rep.id}" + assert dns_rep.qr, "unexpected qr value" + assert dns_rep.opcode == 0, "unexpected opcode value" + assert dns_rep.aa, "unexpected aa value" + assert not dns_rep.tc, "unexpected tc value" + assert not dns_rep.rd, "unexpected rd value" + assert not dns_rep.ra, "unexpected ra value" + assert dns_rep.z == 0, "unexpected z value" + assert dns_rep.rcode == 0, "unexpected rcode value" + assert dns_rep.qdcount == 1, "unexpected qdcount value" + assert dns_rep.ancount == 1, "unexpected ancount value" + assert dns_rep.nscount == 0, "unexpected nscount value" + assert dns_rep.arcount == 0, "unexpected arcount value" assert raw(dns_rep.qd[0]) == raw( dns_req.qd[0] - ), f"query in request and response do not match" + ), "query in request and response do not match" assert raw(dns_rep.qd[0].qname) == raw( dns_req.qd[0].qname + b"." - ), f"if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" + ), "if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" assert ( dns_rep.an[0].rrname == dns_req.qd[0].qname + b"." - ), f"if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" + ), "if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" assert ( dns_rep.an[0].rclass == dns_req.qd[0].qclass - ), f"class in answer does not match query" + ), "class in answer does not match query" assert ( dns_rep.an[0].type == dns_req.qd[0].qtype - ), f"type in answer does not match query" + ), "type in answer does not match query" assert dns_rep.an[0].rdata == IPV4_ADDR @@ -95,7 +88,6 @@ def test_ipv4_udp_dns_in_a(): def test_ipv4_udp_dns_in_a_multiple_queries(): sports = [53, 13274, 12198, 888, 0] dports = [53, 5353, 80, 161, 24732] - payload = DNS() for sport in sports: for dport in dports: qd = ( @@ -117,40 +109,40 @@ def test_ipv4_udp_dns_in_a_multiple_queries(): udp = resp[UDP] assert udp.sport == dport, "unexpected UDP sport: {}".format(udp.sport) assert udp.dport == sport, "unexpected UDP dport: {}".format(udp.dport) - if not DNS in udp: + if DNS not in udp: try: dns_rep = DNS(udp.load) except Exception: raise AssertionError("no DNS layer found") else: dns_rep = udp[DNS] - assert dns_rep.id == 1234, f"unexpected id value: {rr.id}" - assert dns_rep.qr == True, f"unexpected qr value" - assert dns_rep.opcode == 0, f"unexpected opcode value" - assert dns_rep.aa == True, f"unexpected aa value" - assert dns_rep.tc == False, f"unexpected tc value" - assert dns_rep.rd == False, f"unexpected rd value" - assert dns_rep.ra == False, f"unexpected ra value" - assert dns_rep.z == 0, f"unexpected z value" - assert dns_rep.rcode == 0, f"unexpected rcode value" - assert dns_rep.qdcount == 3, f"unexpected qdcount value" - assert dns_rep.ancount == 3, f"unexpected ancount value" - assert dns_rep.nscount == 0, f"unexpected nscount value" - assert dns_rep.arcount == 0, f"unexpected arcount value" + assert dns_rep.id == 1234, f"unexpected id value: {dns_rep.id}" + assert dns_rep.qr, "unexpected qr value" + assert dns_rep.opcode == 0, "unexpected opcode value" + assert dns_rep.aa, "unexpected aa value" + assert not dns_rep.tc, "unexpected tc value" + assert not dns_rep.rd, "unexpected rd value" + assert not dns_rep.ra, "unexpected ra value" + assert dns_rep.z == 0, "unexpected z value" + assert dns_rep.rcode == 0, "unexpected rcode value" + assert dns_rep.qdcount == 3, "unexpected qdcount value" + assert dns_rep.ancount == 3, "unexpected ancount value" + assert dns_rep.nscount == 0, "unexpected nscount value" + assert dns_rep.arcount == 0, "unexpected arcount value" for i, q in enumerate(qd): assert raw(dns_rep.qd[i]) == raw( dns_req.qd[i] - ), f"query in request and response do not match" + ), "query in request and response do not match" assert raw(dns_rep.qd[i].qname) == raw( dns_req.qd[i].qname + b"." - ), f"if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" + ), "if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" assert ( dns_rep.an[i].rrname == dns_req.qd[i].qname + b"." - ), f"if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" + ), "if this test fails, it may mean that scapy fixed the bug in dns.py L134 - if that is so, remove \" + b'.'\" in the test" assert ( dns_rep.an[i].rclass == dns_req.qd[i].qclass - ), f"class in answer does not match query" + ), "class in answer does not match query" assert ( dns_rep.an[i].type == dns_req.qd[i].qtype - ), f"type in answer does not match query" + ), "type in answer does not match query" assert dns_rep.an[i].rdata == IPV4_ADDR