2014-05-15 12:37:05 +00:00
|
|
|
import glob
|
2014-07-26 09:51:27 +00:00
|
|
|
from libmproxy import utils, script
|
2014-05-15 12:37:05 +00:00
|
|
|
from libmproxy.proxy import config
|
2016-02-02 12:25:31 +00:00
|
|
|
from . import tservers
|
2014-05-15 12:37:05 +00:00
|
|
|
|
2015-03-12 05:57:10 +00:00
|
|
|
|
2014-07-26 09:51:27 +00:00
|
|
|
def test_load_scripts():
|
|
|
|
example_dir = utils.Data("libmproxy").path("../examples")
|
|
|
|
scripts = glob.glob("%s/*.py" % example_dir)
|
|
|
|
|
|
|
|
tmaster = tservers.TestMaster(config.ProxyConfig())
|
2014-05-15 12:37:05 +00:00
|
|
|
|
2014-07-26 09:51:27 +00:00
|
|
|
for f in scripts:
|
2015-07-24 01:09:08 +00:00
|
|
|
if "har_extractor" in f:
|
|
|
|
continue
|
|
|
|
if "flowwriter" in f:
|
2014-12-24 00:39:38 +00:00
|
|
|
f += " -"
|
2014-09-05 13:05:44 +00:00
|
|
|
if "iframe_injector" in f:
|
|
|
|
f += " foo" # one argument required
|
2015-04-07 22:33:31 +00:00
|
|
|
if "filt" in f:
|
|
|
|
f += " ~a"
|
2014-07-26 09:51:27 +00:00
|
|
|
if "modify_response_body" in f:
|
|
|
|
f += " foo bar" # two arguments required
|
2015-03-12 05:57:10 +00:00
|
|
|
try:
|
2015-11-14 03:21:38 +00:00
|
|
|
s = script.Script(f, script.ScriptContext(tmaster)) # Loads the script file.
|
2015-05-30 00:03:28 +00:00
|
|
|
except Exception as v:
|
2015-07-24 00:57:56 +00:00
|
|
|
if "ImportError" not in str(v):
|
2015-03-12 05:57:10 +00:00
|
|
|
raise
|
|
|
|
else:
|
|
|
|
s.unload()
|