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
|
from .. import tutils, mastertest
from mitmproxy.builtins import setheaders
from mitmproxy.flow import state
from mitmproxy import options
class TestSetHeaders(mastertest.MasterTest):
def mkmaster(self, **opts):
s = state.State()
o = options.Options(**opts)
m = mastertest.RecordingMaster(o, None, s)
sh = setheaders.SetHeaders()
m.addons.add(o, sh)
return m, sh
def test_configure(self):
sh = setheaders.SetHeaders()
o = options.Options(
setheaders = [("~b", "one", "two")]
)
tutils.raises(
"invalid setheader filter pattern",
sh.configure, o, o.keys()
)
def test_setheaders(self):
m, sh = self.mkmaster(
setheaders = [
("~q", "one", "two"),
("~s", "one", "three")
]
)
f = tutils.tflow()
f.request.headers["one"] = "xxx"
m.request(f)
assert f.request.headers["one"] == "two"
f = tutils.tflow(resp=True)
f.response.headers["one"] = "xxx"
m.response(f)
assert f.response.headers["one"] == "three"
m, sh = self.mkmaster(
setheaders = [
("~s", "one", "two"),
("~s", "one", "three")
]
)
f = tutils.tflow(resp=True)
f.request.headers["one"] = "xxx"
f.response.headers["one"] = "xxx"
m.response(f)
assert f.response.headers.get_all("one") == ["two", "three"]
m, sh = self.mkmaster(
setheaders = [
("~q", "one", "two"),
("~q", "one", "three")
]
)
f = tutils.tflow()
f.request.headers["one"] = "xxx"
m.request(f)
assert f.request.headers.get_all("one") == ["two", "three"]
|