From ee054db071170fadf4108d7b282d2e4518987d8d Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Fri, 22 May 2020 09:15:27 +0100 Subject: [PATCH] monkey: Excise sslcert and add loading blocking support Signed-off-by: Daniel Silverstone --- docs/integration-testing.md | 11 +----- test/monkey_driver.py | 70 +++---------------------------------- test/monkeyfarmer.py | 54 ---------------------------- 3 files changed, 6 insertions(+), 129 deletions(-) diff --git a/docs/integration-testing.md b/docs/integration-testing.md index 1191fba2c..da93343d2 100644 --- a/docs/integration-testing.md +++ b/docs/integration-testing.md @@ -292,6 +292,7 @@ terminate the block. - window: win1 status: complete +valid `status` values are `complete` or `loading`. ## repeat @@ -488,16 +489,6 @@ Remove a previously added authentication details. password: bar -## add-cert - -Add certificate error handler for a url. - - -## remove-cert - -Remove certificate error handler for a url. - - ## clear-log Clear log for a window. diff --git a/test/monkey_driver.py b/test/monkey_driver.py index fe904d3bf..507464049 100755 --- a/test/monkey_driver.py +++ b/test/monkey_driver.py @@ -35,7 +35,6 @@ class DriverBrowser(Browser): def __init__(self, *args, **kwargs): super(DriverBrowser, self).__init__(*args, **kwargs) self.auth = [] - self.cert = [] def add_auth(self, url, realm, username, password): self.auth.append((url, realm, username, password)) @@ -87,46 +86,6 @@ class DriverBrowser(Browser): print("401: No candidate found, cancelling login box") logwin.destroy() - def add_cert(self, url): - # add sll certificate error exception - self.cert.append(url) - - def remove_cert(self, url): - keep = [] - - def matches(first, second): - if first is None or second is None: - return True - return first == second - - for iurl in self.cert: - if not matches(url, iurl): - keep.append(iurl) - self.cert = keep - - def handle_ready_sslcert(self, cwin): - - def matches(first, second): - if first is None or second is None: - return True - return first == second - - candidates = [] - for url in self.cert: - score = 0 - if matches(url, cwin.url): - score += 1 - if score > 0: - candidates.append((score, url)) - if candidates: - candidates.sort() - (score, url) = candidates[-1] - print("SSLCert: Found candidate {} with score {}".format(url, score)) - cwin.go() - else: - print("SSLCert: No candidate found, cancelling sslcert box") - cwin.destroy() - def print_usage(): print('Usage:') @@ -212,19 +171,19 @@ def conds_met(ctx, conds): elif 'window' in cond.keys(): status = cond['status'] window = cond['window'] - assert status == "complete" # TODO: Add more status support? + assert status == "complete" or status == "loading" # TODO: Add more status support? if window == "*all*": # all windows must be not throbbing throbbing = False for win in ctx['windows'].items(): if win[1].throbbing: throbbing = True - if not throbbing: - return True + # throbbing and want loading => true + # not throbbing and want complete => true + return (status == "loading") == throbbing else: win = ctx['windows'][window] - if win.throbbing is False: - return True + return win.throbbing == (status == "loading") else: raise AssertionError("Unknown condition: {}".format(repr(cond))) @@ -576,23 +535,6 @@ def run_test_step_action_remove_auth(ctx, step): step.get("username"), step.get("password")) -def run_test_step_action_add_cert(ctx, step): - print(get_indent(ctx) + "Action:" + step["action"]) - assert_browser(ctx) - browser = ctx['browser'] - browser.add_cert(step.get("url")) - - -def run_test_step_action_remove_cert(ctx, step): - - # pylint: disable=locally-disabled, invalid-name - - print(get_indent(ctx) + "Action:" + step["action"]) - assert_browser(ctx) - browser = ctx['browser'] - browser.remove_cert(step.get("url")) - - def run_test_step_action_clear_log(ctx, step): print(get_indent(ctx) + "Action: " + step["action"]) assert_browser(ctx) @@ -666,8 +608,6 @@ STEP_HANDLERS = { "wait-loading": run_test_step_action_wait_loading, "add-auth": run_test_step_action_add_auth, "remove-auth": run_test_step_action_remove_auth, - "add-cert": run_test_step_action_add_cert, - "remove-cert": run_test_step_action_remove_cert, "clear-log": run_test_step_action_clear_log, "wait-log": run_test_step_action_wait_log, "js-exec": run_test_step_action_js_exec, diff --git a/test/monkeyfarmer.py b/test/monkeyfarmer.py index c24687680..905fd9a81 100644 --- a/test/monkeyfarmer.py +++ b/test/monkeyfarmer.py @@ -216,7 +216,6 @@ class Browser: wrapper=wrapper) self.windows = {} self.logins = {} - self.sslcerts = {} self.current_draw_target = None self.started = False self.stopped = False @@ -288,18 +287,6 @@ class Browser: if win.alive and win.ready: self.handle_ready_login(win) - def handle_SSLCERT(self, action, _lwin, winid, *args): - if action == "VERIFY": - new_win = SSLCertWindow(self, winid, *args) - self.sslcerts[winid] = new_win - self.handle_ready_sslcert(new_win) - else: - win = self.sslcerts.get(winid, None) - if win is None: - print(" Unknown ssl cert window id {}".format(winid)) - else: - win.handle(action, *args) - def handle_PLOT(self, *args): if self.current_draw_target is not None: self.current_draw_target.handle_plot(*args) @@ -322,44 +309,6 @@ class Browser: # Override this method to do useful stuff lwin.destroy() - def handle_ready_sslcert(self, cwin): - - # pylint: disable=locally-disabled, no-self-use - - # Override this method to do useful stuff - cwin.destroy() - - -class SSLCertWindow: - - # pylint: disable=locally-disabled, invalid-name - - def __init__(self, browser, winid, _url, *url): - self.alive = True - self.browser = browser - self.winid = winid - self.url = " ".join(url) - - def handle(self, action, _str="STR"): - if action == "DESTROY": - self.alive = False - else: - raise AssertionError("Unknown action {} for sslcert window".format(action)) - - def _wait_dead(self): - while self.alive: - self.browser.farmer.loop(once=True) - - def go(self): - assert self.alive - self.browser.farmer.tell_monkey("SSLCERT GO {}".format(self.winid)) - self._wait_dead() - - def destroy(self): - assert self.alive - self.browser.farmer.tell_monkey("SSLCERT DESTROY {}".format(self.winid)) - self._wait_dead() - class LoginWindow: @@ -680,9 +629,6 @@ def farmer_test(): lwin.send_password("bar") lwin.go() - def handle_ready_sslcert(self, cwin): - cwin.destroy() - fbbrowser = FooBarLogin(quiet=True) win = fbbrowser.new_window() win.load_page("https://httpbin.org/basic-auth/foo/bar")