-
Notifications
You must be signed in to change notification settings - Fork 8
/
testsites.py
120 lines (104 loc) · 3.72 KB
/
testsites.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
import requests
ignore_headers = set(['x-cache-info', 'connection', 'server', 'x-powered-by', 'x-backend-server'])
live = {'moz': 'live.mozillamessaging.com',
'tb': 'live.thunderbird.net'
}
broker = {'moz': 'broker.thunderbird.net',
'tb': 'broker-live.mozillamessaging.com'
}
mx = {'moz': 'mx.thunderbird.net',
'tb': 'mx-live.mozillamessaging.com'
}
autoconfig = {'moz': 'autoconfig.thunderbird.net',
'tb': 'autoconfig-live.mozillamessaging.com'
}
live_urls = [
'/thunderbird/start/?locale=en-US&version=52&os=WINNT&buildid=20170206074256',
'/thunderbird/releasenotes/?locale=en-US&version=45.7.1&os=WINNT&buildid=20170206074256/',
'/thunderbird/firstrun/?locale=en-US&version=45.7.1&os=WINNT&buildid=20170206074256/',
'/thunderbird/whatsnew/?locale=en-US&version=45.7.1&os=WINNT&buildid=20170206074256/',
'/thunderbird/plugin-crashed/?locale=en-US&version=45.7.1&os=WINNT&buildid=20170206074256/',
'/thunderbird/addons/search?q=header&locale=en-US&lver=45.7.1&hver=45.7.1&os=WINNT',
]
mx_urls = [
'/dns/mx/google.com',
'/dns/mx/garbagegoeshere',
'/dns/mx/doesntexistatall345354345345345.com',
'/dns/mx/mozilla.com',
]
autoconfig_urls = [
'/v1.1/',
'/v1.0/',
'/v1.0/1and1.com',
'/v1.1/2die4.com',
]
broker_urls = [
'/provider/list',
'/provider/suggest?first_name=andrei&last_name=hajdukewycz&providers=gandi',
'/provider/suggest?totalgarbage=lol',
'/provider/suggest?first_name=andrei',
]
class DictDiffer(object):
"""
Calculate the difference between two dictionaries as:
(1) items added
(2) items removed
(3) keys same in both but changed values
(4) keys same in both and unchanged values
"""
def __init__(self, current_dict, past_dict):
self.current_dict, self.past_dict = current_dict, past_dict
self.set_current, self.set_past = set(current_dict.keys()), set(past_dict.keys())
self.intersect = self.set_current.intersection(self.set_past)
def added(self):
return self.set_current - self.intersect
def removed(self):
return self.set_past - self.intersect
def changed(self):
return set(o for o in self.intersect if self.past_dict[o] != self.current_dict[o])
def unchanged(self):
return set(o for o in self.intersect if self.past_dict[o] == self.current_dict[o])
def header_diff(moz, tb):
diff = DictDiffer(moz, tb)
changed = diff.changed() - ignore_headers
added = diff.added() - ignore_headers
removed = diff.removed() - ignore_headers
if len(changed) > 0:
print "Headers Changed"
for i in changed:
print i + ": Moz:" + moz.get(i, 'EMPTY') + "|" + tb.get(i, 'EMPTY')
if len(added) > 0:
print "Headers Added"
for i in added:
print i + ":" + tb.get(i, 'EMPTY')
if len(removed) > 0:
print "Headers Removed"
for i in removed:
print i
def checkurls(domains, urls):
print "------------------------------------------Testing {0}--------------------------------------------".format(domains['moz'])
for url in urls:
moztarget = "https://" + domains['moz'] + url
tbtarget = "https://" + domains['tb'] + url
moz = requests.get(moztarget, allow_redirects=False)
tb = requests.get(tbtarget, allow_redirects=False)
if moz.status_code == tb.status_code and (moz.status_code == 301 or moz.status_code == 302):
mozh = moz.headers
tbh = tb.headers
moz = requests.get(moztarget)
tb = requests.get(moztarget)
if moz.url == tb.url:
print "Match for REDIRECT %s" % url
#header_diff(mozh, tbh)
else:
if tb.text == moz.text and tb.status_code == moz.status_code:
print "Match for %s" % url
else:
print "Error for %s" % url
print tb.text
print moz.text
#header_diff(moz.headers, tb.headers)
checkurls(mx, mx_urls)
checkurls(broker, broker_urls)
checkurls(live, live_urls)
checkurls(autoconfig, autoconfig_urls)