-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_0006_wsgi.py
128 lines (101 loc) · 4.04 KB
/
test_0006_wsgi.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
from pbtests.packetbeat import TestCase
"""
Tests for parsing WSGI traffic.
"""
class Test(TestCase):
def test_long_answer(self):
self.render_config_template(
http_ports=[8888]
)
self.run_packetbeat(pcap="wsgi_loopback.pcap")
objs = self.read_output()
assert len(objs) == 1
o = objs[0]
assert o["type"] == "http"
assert o["src_port"] == 46249
assert o["dst_port"] == 8888
assert o["status"] == "OK"
assert o["http"]["request"]["method"] == "GET"
assert o["http"]["request"]["uri"] == "/"
assert o["http"]["response"]["code"] == 200
assert o["http"]["response"]["phrase"] == "OK"
assert objs[0]["request_raw"] != ""
assert objs[0]["response_raw"] != ""
def test_drum_interraction(self):
self.render_config_template(
http_ports=[8888]
)
self.run_packetbeat(pcap="wsgi_drum.pcap")
objs = self.read_output()
assert len(objs) == 16
assert all([o["type"] == "http" for o in objs])
assert all([o["dst_port"] == 8888 for o in objs])
assert all([o["status"] == "OK" for i, o in enumerate(objs)
if i != 13])
assert objs[13]["status"] == "Error"
assert objs[13]["http"]["request"]["uri"] == "/comment/"
assert objs[13]["http"]["response"]["code"] == 500
def test_send_options(self):
self.render_config_template(
http_ports=[8888],
http_no_send_response=True,
http_no_send_request=True,
)
self.run_packetbeat(pcap="wsgi_loopback.pcap")
objs = self.read_output()
assert len(objs) == 1
assert objs[0]["request_raw"] == ""
assert objs[0]["response_raw"] == ""
def test_send_headers_options(self):
self.render_config_template(
http_ports=[8888],
)
self.run_packetbeat(pcap="wsgi_loopback.pcap")
objs = self.read_output()
assert len(objs) == 1
o = objs[0]
assert "headers" not in o["http"]["request"]
assert "headers" not in o["http"]["response"]
self.render_config_template(
http_ports=[8888],
http_send_all_headers=True,
)
self.run_packetbeat(pcap="wsgi_loopback.pcap")
objs = self.read_output()
assert len(objs) == 1
o = objs[0]
assert "headers" in o["http"]["request"]
assert "headers" in o["http"]["response"]
assert o["http"]["request"]["headers"]["cache-control"] == "max-age=0"
assert len(o["http"]["request"]["headers"]) == 9
assert len(o["http"]["response"]["headers"]) == 7
assert isinstance(o["http"]["response"]["headers"]["set-cookie"], basestring)
self.render_config_template(
http_ports=[8888],
http_send_headers=["User-Agent", "content-Type", "x-forwarded-for"],
)
self.run_packetbeat(pcap="wsgi_loopback.pcap")
objs = self.read_output()
assert len(objs) == 1
o = objs[0]
assert "headers" in o["http"]["request"]
assert "headers" in o["http"]["response"]
assert len(o["http"]["request"]["headers"]) == 1
assert len(o["http"]["response"]["headers"]) == 1
assert "user-agent" in o["http"]["request"]["headers"]
def test_split_cookie(self):
self.render_config_template(
http_ports=[8888],
http_send_all_headers=True,
http_split_cookie=True,
)
self.run_packetbeat(pcap="wsgi_loopback.pcap")
objs = self.read_output()
assert len(objs) == 1
o = objs[0]
assert len(o["http"]["request"]["headers"]) == 9
assert len(o["http"]["response"]["headers"]) == 7
assert isinstance(o["http"]["request"]["headers"]["cookie"], dict)
assert len(o["http"]["request"]["headers"]["cookie"]) == 6
assert isinstance(o["http"]["response"]["headers"]["set-cookie"], dict)
assert len(o["http"]["response"]["headers"]["set-cookie"]) == 4