forked from zmap/zdns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_tests.py
executable file
·958 lines (851 loc) · 33.2 KB
/
integration_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
#!/usr/bin/env python3
import copy
import subprocess
import json
import unittest
import tempfile
from ipaddress import ip_address
def recursiveSort(obj):
def listSort(l):
assert(type(l) == type(list()))
new_list = []
for item in l:
item = recursiveSort(item)
new_list.append(item)
if len(new_list) > 0 and type(new_list[0]) == dict:
return sorted(new_list, key=lambda x: x["name"])
else:
return sorted(new_list)
def dictSort(d):
assert(type(d) == type(dict()))
for key in d:
d[key] = recursiveSort(d[key])
return d
if type(obj) == list:
return listSort(obj)
elif type(obj) == dict:
return dictSort(obj)
else:
return obj
class Tests(unittest.TestCase):
maxDiff = None
ZDNS_EXECUTABLE = "./zdns"
def run_zdns_check_failure(self, flags, name, expected_err, executable=ZDNS_EXECUTABLE):
flags = flags + " --threads=10"
c = f"echo '{name}' | {executable} {flags}; exit 0"
o = subprocess.check_output(c, shell=True, stderr=subprocess.STDOUT)
self.assertEqual(expected_err in o.decode(), True)
def run_zdns(self, flags, name, executable=ZDNS_EXECUTABLE):
flags = flags + " --threads=10"
c = f"echo '{name}' | {executable} {flags}"
o = subprocess.check_output(c, shell=True)
return c, json.loads(o.rstrip())
def run_zdns_multiline(self, flags, names, executable=ZDNS_EXECUTABLE):
d = tempfile.mkdtemp
f = "/".join([d,"temp"])
with open(f) as fd:
for name in names:
fd.writeline(name)
flags = flags + " --threads=10"
c = f"cat '{f}' | {executable} {flags}"
o = subprocess.check_output(c, shell=True)
os.rm(f)
return c, [json.loads(l.rstrip()) for l in o]
ROOT_A = set([
"1.2.3.4",
"2.3.4.5",
"3.4.5.6",
])
ROOT_A_ANSWERS = [{"type":"A", "class":"IN", "answer":x,
"name":"zdns-testing.com"} for x in ROOT_A]
ROOT_AAAA = set([
"fd5a:3bce:8713::1",
"fde6:9bb3:dbd6::2",
"fdb3:ac76:a577::3"
])
ROOT_AAAA_ANSWERS = [{"type":"AAAA", "class":"IN", "answer":x,
"name":"zdns-testing.com"} for x in ROOT_AAAA]
MX_SERVERS = [
{"answer":"mx1.zdns-testing.com.", "preference":1, "type":"MX", "class":"IN", 'name':'zdns-testing.com'},
{"answer":"mx2.zdns-testing.com.", "preference":5, "type":"MX", "class":"IN", 'name':'zdns-testing.com'},
{"answer":"mx1.censys.io.", "preference":10, "type":"MX", "class":"IN", 'name':'zdns-testing.com'},
]
NS_SERVERS = [
{"type": "NS", "class": "IN", "name": "zdns-testing.com",
"answer": "ns-cloud-c2.googledomains.com."},
{"type": "NS", "class": "IN", "name": "zdns-testing.com",
"answer": "ns-cloud-c3.googledomains.com."},
{"type": "NS", "class": "IN", "name": "zdns-testing.com",
"answer": "ns-cloud-c1.googledomains.com."},
{"type": "NS", "class": "IN", "name": "zdns-testing.com",
"answer": "ns-cloud-c4.googledomains.com."},
]
NXDOMAIN_ANSWER = {
"name": "zdns-testing-nxdomain.com",
"class": "IN",
"status": "NXDOMAIN"
}
MX_LOOKUP_ANSWER = {
"name": "zdns-testing.com",
"class": "IN",
"status": "NOERROR",
"data": {
"exchanges": [
{
"name": "mx1.zdns-testing.com",
"type": "MX",
"class": "IN",
"preference": 1,
"ipv4_addresses": [
"1.2.3.4",
"2.3.4.5"
],
"ipv6_addresses": [
"fdb3:ac76:a577::4",
"fdb3:ac76:a577::5"
],
},
{
"name": "mx2.zdns-testing.com",
"type": "MX",
"class": "IN",
"preference": 5,
"ipv4_addresses": [
"5.6.7.8"
],
},
{
"name": "mx1.censys.io",
"type": "MX",
"class": "IN",
"preference": 10,
}
]
}
}
MX_LOOKUP_ANSWER_IPV4 = copy.deepcopy(MX_LOOKUP_ANSWER)
del MX_LOOKUP_ANSWER_IPV4["data"]["exchanges"][0]["ipv6_addresses"]
MX_LOOKUP_ANSWER_IPV6 = copy.deepcopy(MX_LOOKUP_ANSWER)
del MX_LOOKUP_ANSWER_IPV6["data"]["exchanges"][0]["ipv4_addresses"]
del MX_LOOKUP_ANSWER_IPV6["data"]["exchanges"][1]["ipv4_addresses"]
A_LOOKUP_WWW_ZDNS_TESTING = {
"name": "www.zdns-testing.com",
"class": "IN",
"status": "NOERROR",
"data": {
"ipv4_addresses": [
"1.2.3.4",
"2.3.4.5",
"3.4.5.6"
],
"ipv6_addresses": [
"fde6:9bb3:dbd6::2",
"fd5a:3bce:8713::1",
"fdb3:ac76:a577::3"
]
}
}
A_LOOKUP_IPV4_WWW_ZDNS_TESTING = copy.deepcopy(A_LOOKUP_WWW_ZDNS_TESTING)
del A_LOOKUP_IPV4_WWW_ZDNS_TESTING["data"]["ipv6_addresses"]
A_LOOKUP_IPV6_WWW_ZDNS_TESTING = copy.deepcopy(A_LOOKUP_WWW_ZDNS_TESTING)
del A_LOOKUP_IPV6_WWW_ZDNS_TESTING["data"]["ipv4_addresses"]
NS_LOOKUP_WWW_ZDNS_TESTING = {
"name": "www.zdns-testing.com",
"status": "NOERROR",
"data": {
"servers": [
{
"ipv4_addresses": [
"216.239.34.108"
],
"ipv6_addresses": [
"2001:4860:4802:34::6c"
],
"name": "ns-cloud-c2.googledomains.com",
"type": "NS"
},
{
"ipv4_addresses": [
"216.239.32.108"
],
"ipv6_addresses": [
"2001:4860:4802:32::6c"
],
"name": "ns-cloud-c1.googledomains.com",
"type": "NS"
},
{
"ipv4_addresses": [
"216.239.38.108"
],
"ipv6_addresses": [
"2001:4860:4802:38::6c"
],
"name": "ns-cloud-c4.googledomains.com",
"type": "NS"
},
{
"ipv4_addresses": [
"216.239.36.108"
],
"ipv6_addresses": [
"2001:4860:4802:36::6c"
],
"name": "ns-cloud-c3.googledomains.com",
"type": "NS"
}
]
}
}
NS_LOOKUP_IPV4_WWW_ZDNS_TESTING = copy.deepcopy(NS_LOOKUP_WWW_ZDNS_TESTING)
for server in NS_LOOKUP_IPV4_WWW_ZDNS_TESTING["data"]["servers"]:
del server["ipv6_addresses"]
NS_LOOKUP_IPV6_WWW_ZDNS_TESTING = copy.deepcopy(NS_LOOKUP_WWW_ZDNS_TESTING)
for server in NS_LOOKUP_IPV6_WWW_ZDNS_TESTING["data"]["servers"]:
del server["ipv4_addresses"]
PTR_LOOKUP_GOOGLE_PUB = [
{
"type":"PTR",
"class":"IN",
"name":"8.8.8.8.in-addr.arpa",
"answer":"dns.google."
}
]
CAA_RECORD = [
{
"type": "CAA",
"class": "IN",
"name": "zdns-testing.com",
"tag": "issue",
"value": "letsencrypt.org",
"flag": 0
}
]
TXT_RECORD = [
{
"type": "TXT",
"class": "IN",
"name": "test_txt.zdns-testing.com",
"answer": "Hello World!"
}
]
UDP_TRUNCATED_LARGE_TXT = {
"name": "large-text.zdns-testing.com",
"class": "IN",
"status": "TRUNCATED",
"timestamp": "2019-12-18T14:41:23-05:00",
"data": {
"answers": [],
"additionals": [],
"authorities": [],
"protocol": "udp",
"flags": {
"response": False,
"opcode": 0,
"authoritative": False,
"truncated": False,
"recursion_desired": False,
"recursion_available": False,
"authenticated": False,
"checking_disabled": False,
"error_code": 0
}
}
}
TCP_LARGE_TXT_ANSWERS = [
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "surveys, informed by our own experiences conducting a long-term research survey over the past year."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "and explore the security implications of high speed Internet-scale network surveys, both offensive and defensive. "
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "in under 45 minutes from user space on a single machine, approaching the theoretical maximum speed of gigabit Ethernet."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "We introduce ZMap, a modular, open-source network scanner specifically architected to perform Internet-wide scans and capable of surveying the entire IPv4 address space"
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Internet-wide network scanning has numerous security applications, including exposing new vulnerabilities and tracking the adoption of defensive mechanisms, but probing the entire public address space with existing tools is both difficult and slow."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "We also discuss best practices for good Internet citizenship when performing Internet-wide"
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "We present the scanner architecture, experimentally characterize its performance and accuracy, "
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur."
},
{
"type": "TXT",
"class": "IN",
"name": "large-text.zdns-testing.com",
"answer": "Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem."
},
]
WWW_CNAME_ANSWERS = [
{
"type": "CNAME",
"class": "IN",
"name": "www.zdns-testing.com",
"answer": "zdns-testing.com."
}
]
DMARC_ANSWER = {
"data": {
"dmarc": "v=DMARC1; p=none; rua=mailto:[email protected]"
}
}
SPF_ANSWER = {
"data": {
"spf": "v=spf1 mx include:_spf.google.com -all"
}
}
SOA_ANSWERS = [
{
"type": "SOA",
"class": "IN",
"name": "zdns-testing.com",
"ns": "ns-cloud-c1.googledomains.com",
"mbox": "cloud-dns-hostmaster.google.com",
"serial": 2,
"refresh": 21600,
"retry": 3600,
"expire": 259200,
"min_ttl": 300
}
]
SRV_ANSWERS = [
{
"type": "SRV",
"class": "IN",
"name": "_sip._udp.sip.voice.google.com",
"port": 5060,
"priority": 10,
"target": "sip-anycast-1.voice.google.com.",
"weight": 1
},
{
"type": "SRV",
"class": "IN",
"name": "_sip._udp.sip.voice.google.com",
"port": 5060,
"priority": 20,
"target": "sip-anycast-2.voice.google.com.",
"weight": 1
}
]
TLSA_ANSWERS = [
{
"type": "TLSA",
"class": "IN",
"name": "_25._tcp.mail.ietf.org",
"cert_usage": 3,
"selector": 1,
"matching_type": 1,
"certificate": "0c72ac70b745ac19998811b131d662c9ac69dbdbe7cb23e5b514b56664c5d3d6"
}
]
ECS_MAPPINGS = {
"171.67.68.0/24": "2.3.4.5",
"131.159.92.0/24": "3.4.5.6",
"129.127.149.0/24": "1.2.3.4"
}
def assertSuccess(self, res, cmd):
self.assertEqual(res["status"], "NOERROR", cmd)
def assertServFail(self, res, cmd):
self.assertEqual(res["status"], "SERVFAIL", cmd)
def assertEqualAnswers(self, res, correct, cmd, key="answer"):
self.assertIn("answers", res["data"])
for answer in res["data"]["answers"]:
del answer["ttl"]
a = sorted(res["data"]["answers"], key=lambda x: x[key])
b = sorted(correct, key=lambda x: x[key])
helptext = "%s\nExpected:\n%s\n\nActual:\n%s" % (cmd,
json.dumps(b,indent=4), json.dumps(a,indent=4))
def _lowercase(obj):
""" Make dictionary lowercase """
if isinstance(obj, dict):
for k, v in obj.items():
if k == "name":
obj[k] = v.lower()
else:
_lowercase(v)
_lowercase(a)
_lowercase(b)
self.assertEqual(a, b, helptext)
def assertEqualNXDOMAIN(self, res, correct):
self.assertEqual(res["name"], correct["name"])
self.assertEqual(res["status"], correct["status"])
def assertEqualMXLookup(self, res, correct):
self.assertEqual(res["name"], correct["name"])
self.assertEqual(res["status"], correct["status"])
for exchange in res["data"]["exchanges"]:
del exchange["ttl"]
self.assertEqual(recursiveSort(res["data"]["exchanges"]), recursiveSort(correct["data"]["exchanges"]))
def assertEqualALookup(self, res, correct):
self.assertEqual(res["name"], correct["name"])
self.assertEqual(res["status"], correct["status"])
if "ipv4_addresses" in correct["data"]:
self.assertIn("ipv4_addresses", res["data"])
self.assertEqual(sorted(res["data"]["ipv4_addresses"]), sorted(correct["data"]["ipv4_addresses"]))
else:
self.assertNotIn("ipv4_addresses", res["data"])
if "ipv6_addresses" in correct["data"]:
self.assertIn("ipv6_addresses", res["data"])
self.assertEqual(sorted(res["data"]["ipv6_addresses"]), sorted(correct["data"]["ipv6_addresses"]))
else:
self.assertNotIn("ipv6_addresses", res["data"])
def assertEqualNSLookup(self, res, correct):
self.assertEqual(res["name"], correct["name"])
self.assertEqual(res["status"], correct["status"])
for server in res["data"]["servers"]:
del server["ttl"]
self.assertEqual(recursiveSort(res["data"]["servers"]), recursiveSort(correct["data"]["servers"]))
def assertEqualTypes(self, res, list):
res_types = set()
for rr in res["data"]["answers"]:
res_types.add(rr["type"])
self.assertEqual(sorted(res_types), sorted(list))
def check_json_in_list(self, json_obj, list):
for obj in list:
if json_obj == obj:
return True
return False
def assertEqualAxfrLookup(self, records, correct_records):
for record in list(records):
try:
del record["ttl"]
except:
pass
try:
del record["min_ttl"]
except:
pass
try:
del record["expire"]
except:
pass
try:
del record["refresh"]
except:
pass
try:
del record["retry"]
except:
pass
# Delete records without the "name" field
if not "name" in record:
records.remove(record)
for expected_record in correct_records:
self.assertEqual(self.check_json_in_list(expected_record, records), True)
def test_a(self):
c = "A"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.ROOT_A_ANSWERS, cmd)
def test_cname(self):
c = "CNAME"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.WWW_CNAME_ANSWERS, cmd)
def test_caa(self):
c = "CAA"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.CAA_RECORD, cmd, key="name")
def test_txt(self):
c = "TXT"
name = "test_txt.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.TXT_RECORD, cmd)
def test_a_iterative(self):
c = "A --iterative"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.ROOT_A_ANSWERS, cmd)
def test_a_iterative_nxdomain(self):
c = "A --iterative"
name = "zdns-testing-nxdomain.com"
cmd, res = self.run_zdns(c, name)
self.assertEqualNXDOMAIN(res, self.NXDOMAIN_ANSWER)
def test_aaaa(self):
c = "AAAA"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.ROOT_AAAA_ANSWERS, cmd)
def test_aaaa_iterative(self):
c = "AAAA --iterative"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.ROOT_AAAA_ANSWERS, cmd)
def test_mx(self):
c = "MX"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.MX_SERVERS, cmd)
def test_mx_iterative(self):
c = "MX --iterative"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.MX_SERVERS, cmd)
def test_ns(self):
c = "NS"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.NS_SERVERS, cmd)
def test_ns_iterative(self):
c = "NS --iterative"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.NS_SERVERS, cmd)
def test_mx_lookup(self):
c = "mxlookup --ipv4-lookup --ipv6-lookup"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualMXLookup(res, self.MX_LOOKUP_ANSWER)
def test_mx_lookup_iterative(self):
c = "mxlookup --ipv4-lookup --ipv6-lookup --iterative"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualMXLookup(res, self.MX_LOOKUP_ANSWER)
def test_mx_lookup_ipv4(self):
c = "mxlookup --ipv4-lookup"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualMXLookup(res, self.MX_LOOKUP_ANSWER_IPV4)
def test_mx_lookup_ipv6(self):
c = "mxlookup --ipv6-lookup"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualMXLookup(res, self.MX_LOOKUP_ANSWER_IPV6)
def test_mx_lookup_default(self):
c = "mxlookup"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualMXLookup(res, self.MX_LOOKUP_ANSWER_IPV4)
def test_a_lookup(self):
c = "alookup --ipv4-lookup --ipv6-lookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualALookup(res, self.A_LOOKUP_WWW_ZDNS_TESTING)
def test_a_lookup_iterative(self):
c = "alookup --ipv4-lookup --ipv6-lookup --iterative"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualALookup(res, self.A_LOOKUP_WWW_ZDNS_TESTING)
def test_a_lookup_ipv4(self):
c = "alookup --ipv4-lookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualALookup(res, self.A_LOOKUP_IPV4_WWW_ZDNS_TESTING)
def test_a_lookup_ipv6(self):
c = "alookup --ipv6-lookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualALookup(res, self.A_LOOKUP_IPV6_WWW_ZDNS_TESTING)
def test_a_lookup_default(self):
c = "alookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualALookup(res, self.A_LOOKUP_IPV4_WWW_ZDNS_TESTING)
def test_ns_lookup(self):
c = "nslookup --ipv4-lookup --ipv6-lookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualNSLookup(res, self.NS_LOOKUP_WWW_ZDNS_TESTING)
def test_ns_lookup_iterative(self):
c = "nslookup --ipv4-lookup --ipv6-lookup --iterative"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualALookup(res, self.NS_LOOKUP_WWW_ZDNS_TESTING)
def test_ns_lookup_default(self):
c = "nslookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualNSLookup(res, self.NS_LOOKUP_IPV4_WWW_ZDNS_TESTING)
def test_ns_lookup_ipv4(self):
c = "nslookup --ipv4-lookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualNSLookup(res, self.NS_LOOKUP_IPV4_WWW_ZDNS_TESTING)
def test_ns_lookup_ipv6(self):
c = "nslookup --ipv6-lookup"
name = "www.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualNSLookup(res, self.NS_LOOKUP_IPV6_WWW_ZDNS_TESTING)
def test_spf_lookup(self):
c = "spf"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.SPF_ANSWER["data"])
def test_spf_lookup_iterative(self):
c = "spf --iterative"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.SPF_ANSWER["data"])
def test_dmarc_lookup(self):
c = "dmarc"
name = "_dmarc.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.DMARC_ANSWER["data"])
def test_dmarc_lookup_iterative(self):
c = "dmarc --iterative"
name = "_dmarc.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.DMARC_ANSWER["data"])
def test_ptr(self):
c = "PTR"
name = "8.8.8.8"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.PTR_LOOKUP_GOOGLE_PUB, cmd)
def test_ptr_iterative(self):
c = "PTR --iterative"
name = "8.8.8.8"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.PTR_LOOKUP_GOOGLE_PUB, cmd)
def test_spf(self):
c = "SPF"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.SPF_ANSWER["data"])
def test_spf_iterative(self):
c = "SPF --iterative"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.SPF_ANSWER["data"])
def test_dmarc(self):
c = "DMARC"
name = "_dmarc.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.DMARC_ANSWER["data"])
def test_dmarc_iterative(self):
c = "DMARC --iterative"
name = "_dmarc.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual(res["data"], self.DMARC_ANSWER["data"])
def test_axfr(self):
# In this test, we just check for few specific records
# in the AXFR fetch for zonetransfer.me because the
# records can change over time and we want to minimise
# having to update resources/axfr.json
c = "axfr"
name = "zonetransfer.me"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
f = open("resources/axfr.json")
axfr_answer = json.load(f)
self.assertEqualAxfrLookup(res["data"]["servers"][0]["records"], axfr_answer["data"]["servers"][0]["records"])
f.close()
def test_soa(self):
c = "SOA"
name = "zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.SOA_ANSWERS, cmd, key="serial")
def test_srv(self):
c = "SRV"
name = "_sip._udp.sip.voice.google.com"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.SRV_ANSWERS, cmd, key="target")
def test_tlsa(self):
c = "TLSA"
name = "_25._tcp.mail.ietf.org"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqualAnswers(res, self.TLSA_ANSWERS, cmd, key="certificate")
def test_too_big_txt_udp(self):
c = "TXT --udp-only --name-servers=8.8.8.8:53"
name = "large-text.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertEqual(res["status"], "TRUNCATED")
self.assertEqual(res["data"]["protocol"], "udp")
def test_too_big_txt_tcp(self):
c = "TXT --tcp-only --name-servers=8.8.8.8:53" # Azure DNS does not provide results.
name = "large-text.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertEqualAnswers(res, self.TCP_LARGE_TXT_ANSWERS, cmd, key="answer")
def test_too_big_txt_all(self):
c = "TXT --name-servers=8.8.8.8:53"
name = "large-text.zdns-testing.com"
cmd, res = self.run_zdns(c, name)
self.assertEqual(res["data"]["protocol"], "tcp")
self.assertEqualAnswers(res, self.TCP_LARGE_TXT_ANSWERS, cmd, key="answer")
def test_override_name(self):
c = "A --override-name=zdns-testing.com"
name = "notrealname.com"
cmd, res = self.run_zdns(c, name)
self.assertEqualAnswers(res, self.ROOT_A_ANSWERS, cmd)
def test_server_mode_a_lookup_ipv4(self):
c = "A --override-name=zdns-testing.com --name-server-mode"
name = "8.8.8.8:53"
cmd, res = self.run_zdns(c, name)
self.assertEqual(res["data"]["resolver"], "8.8.8.8:53")
self.assertEqualAnswers(res, self.ROOT_A_ANSWERS, cmd)
def test_mixed_mode_a_lookup_ipv4(self):
c = "A --name-servers=0.0.0.0"
name = "zdns-testing.com,8.8.8.8:53"
cmd, res = self.run_zdns(c, name)
self.assertEqual(res["data"]["resolver"], "8.8.8.8:53")
self.assertEqualAnswers(res, self.ROOT_A_ANSWERS, cmd)
def test_local_addr_interface_warning(self):
c = "A --local-addr 192.168.1.5 --local-interface en0"
name = "zdns-testing.com"
self.run_zdns_check_failure(c, name, "Both --local-addr and --local-interface specified.")
def test_edns0_client_subnet(self):
name = "ecs-geo.zdns-testing.com"
for subnet, ip_addr in self.ECS_MAPPINGS.items():
# Hardcoding a name server that supports ECS; Github's default recursive does not.
c = f"A --client-subnet {subnet} --name-servers=8.8.8.8:53"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
address, netmask = tuple(subnet.split("/"))
family = 1 if ip_address(address).version == 4 else 2
self.assertEqual(address, res["data"]['additionals'][0]['csubnet']['address'])
self.assertEqual(int(netmask), res["data"]['additionals'][0]['csubnet']["source_netmask"])
self.assertEqual(family, res["data"]['additionals'][0]['csubnet']['family'])
self.assertTrue("source_scope" in res["data"]['additionals'][0]['csubnet'])
correct = [{"type":"A", "class":"IN", "answer": ip_addr, "name":"ecs-geo.zdns-testing.com"}]
self.assertEqualAnswers(res, correct, cmd)
def test_edns0_nsid(self):
name = "google.com"
# using Google Public DNS for testing as its NSID always follows format 'gpdns-<airport code>'
c = f"A --nsid --name-servers=8.8.8.8:53"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertTrue("nsid" in res["data"]['additionals'][0])
self.assertTrue(res["data"]['additionals'][0]['nsid']['nsid'].startswith("gpdns-"))
def test_edns0_ede_1(self):
name = "dnssec.fail"
# using Cloudflare Public DNS (1.1.1.1) that implements EDE
c = f"A --name-servers=1.1.1.1:53"
cmd, res = self.run_zdns(c, name)
self.assertServFail(res, cmd)
self.assertTrue("ede" in res["data"]['additionals'][0])
ede_obj = res["data"]['additionals'][0]["ede"][0]
self.assertEqual("DNSKEY Missing", ede_obj["error_text"])
self.assertEqual("no SEP matching the DS found for dnssec.fail.", ede_obj["extra_text"])
self.assertEqual(9, ede_obj["info_code"])
def test_edns0_ede_2_cd(self):
name = "dnssec.fail"
# using Cloudflare Public DNS (1.1.1.1) that implements EDE, checking disabled resulting in NOERROR
c = f"A --name-servers=1.1.1.1:53 --checking-disabled"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertTrue("ede" in res["data"]['additionals'][0])
ede_obj = res["data"]['additionals'][0]["ede"][0]
self.assertEqual("DNSKEY Missing", ede_obj["error_text"])
self.assertEqual("no SEP matching the DS found for dnssec.fail.", ede_obj["extra_text"])
self.assertEqual(9, ede_obj["info_code"])
def test_dnssec_response(self):
# checks if dnssec records are returned
c = f"SOA --dnssec --name-servers=8.8.8.8:53"
name = "."
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
self.assertEqual('do', res["data"]['additionals'][0]['flags'])
self.assertEqualTypes(res, ["SOA", "RRSIG"])
def test_cd_bit_not_set(self):
c = "A --name-servers=8.8.8.8:53"
name = "dnssec-failed.org"
cmd, res = self.run_zdns(c, name)
self.assertServFail(res, cmd)
def test_cd_bit_set(self):
c = "A --name-servers=8.8.8.8:53 --checking-disabled"
name = "dnssec-failed.org"
cmd, res = self.run_zdns(c, name)
self.assertSuccess(res, cmd)
if __name__ == "__main__":
unittest.main()