mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Unit tests: cmdline.pathod
This commit is contained in:
parent
f8e95db6b0
commit
3061bdd0c2
@ -179,7 +179,7 @@ def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
|
||||
|
||||
reqs = []
|
||||
for r in args.requests:
|
||||
if os.path.exists(r):
|
||||
if os.path.isfile(r):
|
||||
data = open(r).read()
|
||||
r = data
|
||||
try:
|
||||
@ -346,7 +346,7 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
|
||||
if len(parts) == 1:
|
||||
parts = ["*", parts[0]]
|
||||
parts[1] = os.path.expanduser(parts[1])
|
||||
if not os.path.exists(parts[1]):
|
||||
if not os.path.isfile(parts[1]):
|
||||
return parser.error("Certificate file does not exist: %s"%parts[1])
|
||||
certs.append(parts)
|
||||
args.ssl_certs = certs
|
||||
@ -369,7 +369,7 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
|
||||
|
||||
anchors = []
|
||||
for patt, spec in args.anchors:
|
||||
if os.path.exists(spec):
|
||||
if os.path.isfile(spec):
|
||||
data = open(spec).read()
|
||||
spec = data
|
||||
|
||||
@ -382,8 +382,7 @@ def args_pathod(argv, stdout=sys.stdout, stderr=sys.stderr):
|
||||
try:
|
||||
arex = re.compile(patt)
|
||||
except re.error:
|
||||
print >> stderr, "Invalid regex in anchor: %s" % patt
|
||||
sys.exit(1)
|
||||
return parser.error("Invalid regex in anchor: %s" % patt)
|
||||
anchors.append((arex, req))
|
||||
args.anchors = anchors
|
||||
return args
|
||||
|
@ -4,9 +4,96 @@ import cStringIO
|
||||
import mock
|
||||
|
||||
|
||||
def test_pathod():
|
||||
@mock.patch("argparse.ArgumentParser.error")
|
||||
def test_pathod(perror):
|
||||
assert cmdline.args_pathod(["pathod"])
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"--cert",
|
||||
tutils.test_data.path("data/testkey.pem")
|
||||
]
|
||||
)
|
||||
assert a.ssl_certs
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"--cert",
|
||||
"nonexistent"
|
||||
]
|
||||
)
|
||||
assert perror.called
|
||||
perror.reset_mock()
|
||||
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"-a",
|
||||
"foo=200"
|
||||
]
|
||||
)
|
||||
assert a.anchors
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"-a",
|
||||
"foo=" + tutils.test_data.path("data/response")
|
||||
]
|
||||
)
|
||||
assert a.anchors
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"-a",
|
||||
"?=200"
|
||||
]
|
||||
)
|
||||
assert perror.called
|
||||
perror.reset_mock()
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"-a",
|
||||
"foo"
|
||||
]
|
||||
)
|
||||
assert perror.called
|
||||
perror.reset_mock()
|
||||
|
||||
s = cStringIO.StringIO()
|
||||
tutils.raises(
|
||||
SystemExit,
|
||||
cmdline.args_pathod,
|
||||
["pathod", "-a", "foo=."],
|
||||
s,
|
||||
s
|
||||
)
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"--limit-size",
|
||||
"200k"
|
||||
]
|
||||
)
|
||||
assert a.sizelimit
|
||||
|
||||
a = cmdline.args_pathod(
|
||||
[
|
||||
"pathod",
|
||||
"--limit-size",
|
||||
"q"
|
||||
]
|
||||
)
|
||||
assert perror.called
|
||||
perror.reset_mock()
|
||||
|
||||
|
||||
@mock.patch("argparse.ArgumentParser.error")
|
||||
def test_pathoc(perror):
|
||||
|
Loading…
Reference in New Issue
Block a user