forked from csirtgadgets/csirtg-indicator-py-v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fqdn.py
115 lines (93 loc) · 2.86 KB
/
test_fqdn.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
from csirtg_indicator import Indicator
from csirtg_indicator.exceptions import InvalidIndicator
from faker import Faker
import pytest
fake = Faker()
GOOD = [
'hdxturkceizle.xn--6frz82g',
'xn--1--blcfn0a0ai7a1a7e.xn--p1acf',
'example.org',
'1.2.3.4.com',
'xn----jtbbmekqknepg3a.xn--p1ai',
'dualstack.cddf-prod-frontend-1ho73vqwbi0tw-1326553765.us-east-1.elb.amazonaws.com',
'laser-retargeting-server-production.us-east-1-prod-core-edge-public.spongecell.net',
'example.org.',
'an0ther.exAmple.orG.',
'under_score.com',
'_dc-mx.test.someotherdom.com.',
]
BAD = [
'dot.',
'this.is-bad-',
'this-too.is_bad-.',
'this.is.bad-.com',
'space com',
'a.12E.',
'192.168.1.13F',
'underscore.c_om',
'-dash.com',
'dash-.com',
'sub.-dash.com',
'sub-.dash.com',
'-.com',
'-com',
'.com',
'com',
'mkyong.t.t.c',
'mkyong,com',
'mkyong.com/users',
'slash.com/',
'a.123',
'b.123.',
'x.XN--VERMGENSBERATUNG-PWBBJALKJSDFWHATLADKDALKJSDFJWHATLEIUDWLAIFU',
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkk.com',
'www.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkk.co.uk',
'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcde.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijk.comm',
]
def _not(data):
for d in data:
d = Indicator(d)
assert d.itype != 'fqdn'
def test_fqdn_ip():
data = ['192.168.1.0/24', '192.168.1.1', '2001:1608:10:147::21', '2001:4860:4860::8888']
_not(data)
def test_fqdn_urls():
data = [
'http://192.168.1.1/1.html',
'http://www41.xzmnt.com',
'http://get.ahoybest.com/n/3.6.16/12205897/microsoft lync server 2010.exe',
'https://example.com:443/1.html'
]
_not(data)
def test_fqdn_ok():
for d in GOOD:
e = Indicator(d)
assert e.itype is 'fqdn'
d = d.rstrip('.')
assert e.indicator == d.lower()
def test_fqdn_not_ok():
for d in BAD:
with pytest.raises(InvalidIndicator):
e = Indicator(d)
def test_fqdn_subdomain():
data = [
'www.yahoo.com',
'www.ww2.yahoo.com',
'this.is.aNother.sub.domain.tld.',
]
for d in data:
print(Indicator(indicator=d).is_subdomain())
assert Indicator(indicator=d).is_subdomain()
data = [
'yahoo.com',
'google.com',
'notasubdomain.tLd.',
'http://google.com',
'https://www.google.com',
'http://www2.www.google.com',
]
for d in data:
assert not Indicator(indicator=d).is_subdomain()
def test_fqdn_random():
for d in range(0, 100):
assert Indicator(indicator=fake.domain_name()).itype == 'fqdn'