aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mitmproxy/test_command.py79
-rw-r--r--test/mitmproxy/test_types.py9
2 files changed, 86 insertions, 2 deletions
diff --git a/test/mitmproxy/test_command.py b/test/mitmproxy/test_command.py
index 25df2e61..c777192d 100644
--- a/test/mitmproxy/test_command.py
+++ b/test/mitmproxy/test_command.py
@@ -23,6 +23,10 @@ class TAddon:
def cmd3(self, foo: int) -> int:
return foo
+ @command.command("cmd4")
+ def cmd4(self, a: int, b: str, c: mitmproxy.types.Path) -> str:
+ return "ok"
+
@command.command("subcommand")
def subcommand(self, cmd: mitmproxy.types.Cmd, *args: mitmproxy.types.Arg) -> str:
return "ok"
@@ -46,6 +50,10 @@ class TAddon:
def path(self, arg: mitmproxy.types.Path) -> None:
pass
+ @command.command("flow")
+ def flow(self, f: flow.Flow, s: str) -> None:
+ pass
+
class TestCommand:
def test_varargs(self):
@@ -78,8 +86,12 @@ class TestCommand:
[
"foo bar",
[
- command.ParseResult(value = "foo", type = mitmproxy.types.Cmd, valid = False),
- command.ParseResult(value = "bar", type = str, valid = True)
+ command.ParseResult(
+ value = "foo", type = mitmproxy.types.Cmd, valid = False
+ ),
+ command.ParseResult(
+ value = "bar", type = mitmproxy.types.Unknown, valid = False
+ )
],
[],
],
@@ -136,6 +148,69 @@ class TestCommand:
],
[]
],
+ [
+ "cmd4",
+ [
+ command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True),
+ ],
+ ["int", "str", "path"]
+ ],
+ [
+ "cmd4 ",
+ [
+ command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "", type = int, valid = False),
+ ],
+ ["str", "path"]
+ ],
+ [
+ "cmd4 1",
+ [
+ command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "1", type = int, valid = True),
+ ],
+ ["str", "path"]
+ ],
+ [
+ "cmd4 1",
+ [
+ command.ParseResult(value = "cmd4", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "1", type = int, valid = True),
+ ],
+ ["str", "path"]
+ ],
+ [
+ "flow",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ ],
+ ["flow", "str"]
+ ],
+ [
+ "flow ",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "", type = flow.Flow, valid = False),
+ ],
+ ["str"]
+ ],
+ [
+ "flow x",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "x", type = flow.Flow, valid = False),
+ ],
+ ["str"]
+ ],
+ [
+ "flow x ",
+ [
+ command.ParseResult(value = "flow", type = mitmproxy.types.Cmd, valid = True),
+ command.ParseResult(value = "x", type = flow.Flow, valid = False),
+ command.ParseResult(value = "", type = str, valid = True),
+ ],
+ []
+ ],
]
with taddons.context() as tctx:
tctx.master.addons.add(TAddon())
diff --git a/test/mitmproxy/test_types.py b/test/mitmproxy/test_types.py
index 29e86203..72492fa9 100644
--- a/test/mitmproxy/test_types.py
+++ b/test/mitmproxy/test_types.py
@@ -43,6 +43,15 @@ def test_str():
assert b.parse(tctx.master.commands, str, "foo") == "foo"
+def test_unknown():
+ with taddons.context() as tctx:
+ b = mitmproxy.types._UnknownType()
+ assert b.is_valid(tctx.master.commands, mitmproxy.types.Unknown, "foo") is False
+ assert b.is_valid(tctx.master.commands, mitmproxy.types.Unknown, 1) is False
+ assert b.completion(tctx.master.commands, mitmproxy.types.Unknown, "") == []
+ assert b.parse(tctx.master.commands, mitmproxy.types.Unknown, "foo") == "foo"
+
+
def test_int():
with taddons.context() as tctx:
b = mitmproxy.types._IntType()