aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/builtins/script.py6
-rw-r--r--test/mitmproxy/builtins/test_script.py13
-rw-r--r--test/mitmproxy/data/addonscripts/addon.py22
3 files changed, 39 insertions, 2 deletions
diff --git a/mitmproxy/builtins/script.py b/mitmproxy/builtins/script.py
index 220fb9af..ed5f2ecd 100644
--- a/mitmproxy/builtins/script.py
+++ b/mitmproxy/builtins/script.py
@@ -99,7 +99,6 @@ class ReloadHandler(watchdog.events.FileSystemEventHandler):
return False
if os.path.basename(event.src_path).startswith("."):
return False
- print(event.src_path)
return True
def on_modified(self, event):
@@ -151,7 +150,10 @@ class Script:
def load_script(self):
self.ns = load_script(self.path, self.args)
- self.run("start")
+ ret = self.run("start")
+ if ret:
+ self.ns = ret
+ self.run("start")
def tick(self):
if self.should_reload.is_set():
diff --git a/test/mitmproxy/builtins/test_script.py b/test/mitmproxy/builtins/test_script.py
index 1658088c..3f07b576 100644
--- a/test/mitmproxy/builtins/test_script.py
+++ b/test/mitmproxy/builtins/test_script.py
@@ -116,6 +116,19 @@ class TestScript(mastertest.MasterTest):
assert not fm.state.view[0].request.is_replay
assert fm.state.view[1].request.is_replay
+ def test_addon(self):
+ s = state.State()
+ m = master.FlowMaster(options.Options(), None, s)
+ sc = script.Script(
+ tutils.test_data.path(
+ "data/addonscripts/addon.py"
+ )
+ )
+ m.addons.add(sc)
+ assert sc.ns.event_log == [
+ 'scriptstart', 'addonstart', 'addonconfigure'
+ ]
+
class TestScriptLoader(mastertest.MasterTest):
def test_simple(self):
diff --git a/test/mitmproxy/data/addonscripts/addon.py b/test/mitmproxy/data/addonscripts/addon.py
new file mode 100644
index 00000000..3b09d231
--- /dev/null
+++ b/test/mitmproxy/data/addonscripts/addon.py
@@ -0,0 +1,22 @@
+event_log = []
+
+
+class Addon:
+ @property
+ def event_log(self):
+ return event_log
+
+ def start(self):
+ event_log.append("addonstart")
+
+ def configure(self, options):
+ event_log.append("addonconfigure")
+
+
+def configure(options):
+ event_log.append("addonconfigure")
+
+
+def start():
+ event_log.append("scriptstart")
+ return Addon()