feat(cli): split lab lifecycle from exploitation, add --url/--path targets, socket readiness probe
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import unittest
|
||||
|
||||
from poc import cli
|
||||
|
||||
|
||||
def parse(argv):
|
||||
return cli.build_parser().parse_args(argv)
|
||||
|
||||
|
||||
class SeparationTest(unittest.TestCase):
|
||||
def test_lab_defaults_to_up(self):
|
||||
self.assertEqual(parse(["lab"]).action, "up")
|
||||
|
||||
def test_lab_up_status_down(self):
|
||||
for action in ("up", "down", "status"):
|
||||
self.assertEqual(parse(["lab", action]).action, action)
|
||||
|
||||
def test_lab_rejects_unknown_action(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
parse(["lab", "exploit"])
|
||||
|
||||
def test_lab_has_no_exploit_flags(self):
|
||||
ns = parse(["lab", "up"])
|
||||
for flag in ("proof", "retries", "dry_run"):
|
||||
self.assertFalse(hasattr(ns, flag), flag)
|
||||
|
||||
def test_exploit_keeps_its_flags(self):
|
||||
ns = parse(["exploit", "--cmd", "id>/out/x", "--retries", "1"])
|
||||
self.assertEqual(ns.cmd, "id>/out/x")
|
||||
self.assertEqual(ns.retries, 1)
|
||||
|
||||
def test_lab_actions_do_not_run_the_chain(self):
|
||||
ns = parse(["lab", "up"])
|
||||
self.assertIs(ns.func, cli.cmd_lab)
|
||||
|
||||
def test_exploit_and_leak_are_separate_commands(self):
|
||||
self.assertIs(parse(["exploit"]).func, cli.cmd_exploit)
|
||||
self.assertIs(parse(["leak"]).func, cli.cmd_leak)
|
||||
self.assertIs(parse(["check"]).func, cli.cmd_check)
|
||||
|
||||
|
||||
class UrlTargetTest(unittest.TestCase):
|
||||
def test_defaults_without_url(self):
|
||||
ns = cli.resolve_target(parse(["exploit"]))
|
||||
self.assertEqual((ns.host, ns.port, ns.path), ("127.0.0.1", 18110, ""))
|
||||
|
||||
def test_url_sets_host_port_and_path(self):
|
||||
ns = cli.resolve_target(parse(["exploit", "--url", "http://10.0.0.5:8080/app/index.php"]))
|
||||
self.assertEqual(ns.host, "10.0.0.5")
|
||||
self.assertEqual(ns.port, 8080)
|
||||
self.assertEqual(ns.path, "/app/index.php")
|
||||
|
||||
def test_url_default_port_80(self):
|
||||
ns = cli.resolve_target(parse(["leak", "--url", "http://lab.internal/index.php"]))
|
||||
self.assertEqual(ns.port, 80)
|
||||
|
||||
def test_url_root_path_defaults(self):
|
||||
ns = cli.resolve_target(parse(["leak", "--url", "http://lab.internal:9000"]))
|
||||
self.assertEqual(ns.path, "/index.php")
|
||||
|
||||
def test_https_rejected(self):
|
||||
with self.assertRaises(SystemExit):
|
||||
cli.resolve_target(parse(["exploit", "--url", "https://lab.internal/"]))
|
||||
|
||||
def test_explicit_flags_win_over_url(self):
|
||||
ns = cli.resolve_target(parse(["exploit", "--url", "http://a:1/x.php", "--port", "7000"]))
|
||||
self.assertEqual(ns.port, 7000)
|
||||
Reference in New Issue
Block a user