-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasicHttp.py
64 lines (49 loc) · 2.03 KB
/
basicHttp.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
from testsbase import testsbase
import magic
import os
from numpy import mean
class basicHttp(testsbase):
def __init__(self, config):
super().__init__(config)
def run(self, vh=None):
test_list = [self.test2, self.test3, self.test4, self.test5, self.test7]
# test_list = [self.test2,self.test3]
docroot = self.config['server'][0]['documentroot']
results = []
for root, dirs, files in os.walk(docroot, topdown=False):
for name in files:
testfile = os.path.join(root, name)[len(docroot)+1:]
print("test file: {}".format(testfile))
results.append(super().run(tests=test_list, vh=vh, testfile=testfile))
return mean(results)
def test2(self):
""" GET file, check sha254 """
response = self.get
return self.check_byhash(response)
def test3(self):
""" GET supported headers """
response = self.get
headers = [h in response.headers for h in ['server',
'date', 'content-length', 'content-type', 'etag']]
return all (headers)
def test4(self):
""" content-length """
content_length = int(self.head.headers['content-length'])
response = self.get
return response.status_code == 200 and content_length == len(response.content)
def test5(self):
""" HEAD method """
response = self.head
headers = [h in response.headers for h in ['server',
'date', 'content-length', 'content-type', 'etag']]
return len(response.text) == 0 and all(headers)
# def test6(self):
# """ etag support """
# response = self.get
# etag = response.headers['etag']
# response = requests.get(self.url, headers={'If-None-Match': etag})
# return response.status_code == 304
def test7(self):
""" check mime-type """
response = self.get
return magic.from_buffer(response.content, mime=True) == response.headers['content-type']