Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/f33db7d4429f14c215933c28853813c46f97f11e
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/f33db7d4429f14c215933c28853813c46f97f11e
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/f33db7d4429f14c215933c28853813c46f97f11e

The branch, master has been updated
       via  f33db7d4429f14c215933c28853813c46f97f11e (commit)
      from  b25c7b3d2d3da854755208e05e43cbe787f389ae (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=f33db7d4429f14c215933c28853813c46f97f11e
commit f33db7d4429f14c215933c28853813c46f97f11e
Author: Daniel Silverstone <[email protected]>
Commit: Daniel Silverstone <[email protected]>

    Monkey: Support 401login in the monkey-driver et al.
    
    Signed-off-by: Daniel Silverstone <[email protected]>

diff --git a/test/monkey-driver.py b/test/monkey-driver.py
index 57c6c54..6463d96 100755
--- a/test/monkey-driver.py
+++ b/test/monkey-driver.py
@@ -4,6 +4,59 @@ import sys, getopt, yaml, time
 
 from monkeyfarmer import Browser
 
+class DriverBrowser(Browser):
+    def __init__(self, *args, **kwargs):
+        super(DriverBrowser, self).__init__(*args, **kwargs)
+        self.auth = []
+
+    def add_auth(self, url, realm, username, password):
+        self.auth.append((url, realm, username, password))
+
+    def remove_auth(self, url, realm, username, password):
+        keep = []
+        def matches(a,b):
+            if a is None or b is None:
+                return True
+            return a == b
+        for (iurl, irealm, iusername, ipassword) in self.auth:
+            if not (matches(url, iurl) or
+                    matches(realm, irealm) or
+                    matches(username, iusername) or
+                    matches(password, ipassword)):
+                keep.append((iurl, irealm, iusername, ipassword))
+        self.auth = keep
+
+    def handle_ready_login(self, logwin):
+        # We have logwin.{url,username,password,realm}
+        # We must logwin.send_{username,password}(xxx)
+        # We may logwin.go()
+        # We may logwin.destroy()
+        def matches(a,b):
+            if a is None or b is None:
+                return True
+            return a == b
+        candidates = []
+        for (url, realm, username, password) in self.auth:
+            score = 0
+            if matches(url, logwin.url):
+                score += 1
+            if matches(realm, logwin.realm):
+                score += 1
+            if matches(username, logwin.username):
+                score += 1
+            if score > 0:
+                candidates.append((score, username, password))
+        if candidates:
+            candidates.sort()
+            (score, username, password) = candidates[-1]
+            print("401: Found candidate {}/{} with score {}".format(username, 
password, score))
+            logwin.send_username(username)
+            logwin.send_password(password)
+            logwin.go()
+        else:
+            print("401: No candidate found, cancelling login box")
+            logwin.destroy()
+
 def print_usage():
     print('Usage:')
     print('  ' + sys.argv[0] + ' -m <path to monkey> -t <path to test>')
@@ -72,7 +125,7 @@ def run_test_step_action_launch(ctx, step):
     print(get_indent(ctx) + "Action: " + step["action"])
     assert(ctx.get('browser') is None)
     assert(ctx.get('windows') is None)
-    ctx['browser'] = Browser(monkey_cmd=[ctx["monkey"]], quiet=True)
+    ctx['browser'] = DriverBrowser(monkey_cmd=[ctx["monkey"]], quiet=True)
     assert_browser(ctx)
     ctx['windows'] = dict()
 
@@ -174,6 +227,9 @@ def run_test_step_action_plot_check(ctx, step):
         if 'text-contains' in check.keys():
             print("Check {} in 
{}".format(repr(check['text-contains']),repr(all_text)))
             assert(check['text-contains'] in all_text)
+        elif 'text-not-contains' in check.keys():
+            print("Check {} NOT in 
{}".format(repr(check['text-not-contains']),repr(all_text)))
+            assert(check['text-not-contains'] not in all_text)
         elif 'bitmap-count' in check.keys():
             assert(len(bitmaps) == int(check['bitmap-count']))
         else:
@@ -212,6 +268,21 @@ def run_test_step_action_timer_check(ctx, step):
     elif condition[1] == '>':
         assert(timer1["taken"] > timer2["taken"])
 
+def run_test_step_action_add_auth(ctx, step):
+    print(get_indent(ctx) + "Action:" + step["action"])
+    assert_browser(ctx)
+    browser = ctx['browser']
+    browser.add_auth(step.get("url"), step.get("realm"),
+                     step.get("username"), step.get("password"))
+
+
+def run_test_step_action_remove_auth(ctx, step):
+    print(get_indent(ctx) + "Action:" + step["action"])
+    assert_browser(ctx)
+    browser = ctx['browser']
+    browser.remove_auth(step.get("url"), step.get("realm"),
+                        step.get("username"), step.get("password"))
+
 def run_test_step_action_quit(ctx, step):
     print(get_indent(ctx) + "Action: " + step["action"])
     assert_browser(ctx)
@@ -231,6 +302,8 @@ step_handlers = {
     "timer-stop":   run_test_step_action_timer_stop,
     "timer-check":  run_test_step_action_timer_check,
     "plot-check":   run_test_step_action_plot_check,
+    "add-auth":     run_test_step_action_add_auth,
+    "remove-auth":  run_test_step_action_remove_auth,
     "quit":         run_test_step_action_quit,
 }
 
diff --git a/test/monkey-tests/401login.yaml b/test/monkey-tests/401login.yaml
new file mode 100644
index 0000000..a9a74cd
--- /dev/null
+++ b/test/monkey-tests/401login.yaml
@@ -0,0 +1,38 @@
+title: Test the 401 LOGIN functionality
+group: real-world
+steps:
+- action: launch
+  language: en
+- action: window-new
+  tag: win1
+- action: navigate
+  window: win1
+  url: https://httpbin.org/basic-auth/foo/bar
+- action: block
+  conditions:
+  - window: win1
+    status: complete
+- action: plot-check
+  window: win1
+  checks:
+  - text-not-contains: "\"authenticated\": true"
+- action: add-auth
+  url: https://httpbin.org/basic-auth/foo/bar
+  realm: Fake Realm
+  username: foo
+  password: bar
+- action: navigate
+  window: win1
+  url: https://httpbin.org/basic-auth/foo/bar
+- action: block
+  conditions:
+  - window: win1
+    status: complete
+- action: plot-check
+  window: win1
+  checks:
+  - text-contains: "\"authenticated\": true"
+- action: window-close
+  window: win1
+- action: quit
+


-----------------------------------------------------------------------

Summary of changes:
 test/monkey-driver.py                              |   75 +++++++++++++++++++-
 .../{resource-scheme.yaml => 401login.yaml}        |   18 +++--
 2 files changed, 85 insertions(+), 8 deletions(-)
 copy test/monkey-tests/{resource-scheme.yaml => 401login.yaml} (53%)

diff --git a/test/monkey-driver.py b/test/monkey-driver.py
index 57c6c54..6463d96 100755
--- a/test/monkey-driver.py
+++ b/test/monkey-driver.py
@@ -4,6 +4,59 @@ import sys, getopt, yaml, time
 
 from monkeyfarmer import Browser
 
+class DriverBrowser(Browser):
+    def __init__(self, *args, **kwargs):
+        super(DriverBrowser, self).__init__(*args, **kwargs)
+        self.auth = []
+
+    def add_auth(self, url, realm, username, password):
+        self.auth.append((url, realm, username, password))
+
+    def remove_auth(self, url, realm, username, password):
+        keep = []
+        def matches(a,b):
+            if a is None or b is None:
+                return True
+            return a == b
+        for (iurl, irealm, iusername, ipassword) in self.auth:
+            if not (matches(url, iurl) or
+                    matches(realm, irealm) or
+                    matches(username, iusername) or
+                    matches(password, ipassword)):
+                keep.append((iurl, irealm, iusername, ipassword))
+        self.auth = keep
+
+    def handle_ready_login(self, logwin):
+        # We have logwin.{url,username,password,realm}
+        # We must logwin.send_{username,password}(xxx)
+        # We may logwin.go()
+        # We may logwin.destroy()
+        def matches(a,b):
+            if a is None or b is None:
+                return True
+            return a == b
+        candidates = []
+        for (url, realm, username, password) in self.auth:
+            score = 0
+            if matches(url, logwin.url):
+                score += 1
+            if matches(realm, logwin.realm):
+                score += 1
+            if matches(username, logwin.username):
+                score += 1
+            if score > 0:
+                candidates.append((score, username, password))
+        if candidates:
+            candidates.sort()
+            (score, username, password) = candidates[-1]
+            print("401: Found candidate {}/{} with score {}".format(username, 
password, score))
+            logwin.send_username(username)
+            logwin.send_password(password)
+            logwin.go()
+        else:
+            print("401: No candidate found, cancelling login box")
+            logwin.destroy()
+
 def print_usage():
     print('Usage:')
     print('  ' + sys.argv[0] + ' -m <path to monkey> -t <path to test>')
@@ -72,7 +125,7 @@ def run_test_step_action_launch(ctx, step):
     print(get_indent(ctx) + "Action: " + step["action"])
     assert(ctx.get('browser') is None)
     assert(ctx.get('windows') is None)
-    ctx['browser'] = Browser(monkey_cmd=[ctx["monkey"]], quiet=True)
+    ctx['browser'] = DriverBrowser(monkey_cmd=[ctx["monkey"]], quiet=True)
     assert_browser(ctx)
     ctx['windows'] = dict()
 
@@ -174,6 +227,9 @@ def run_test_step_action_plot_check(ctx, step):
         if 'text-contains' in check.keys():
             print("Check {} in 
{}".format(repr(check['text-contains']),repr(all_text)))
             assert(check['text-contains'] in all_text)
+        elif 'text-not-contains' in check.keys():
+            print("Check {} NOT in 
{}".format(repr(check['text-not-contains']),repr(all_text)))
+            assert(check['text-not-contains'] not in all_text)
         elif 'bitmap-count' in check.keys():
             assert(len(bitmaps) == int(check['bitmap-count']))
         else:
@@ -212,6 +268,21 @@ def run_test_step_action_timer_check(ctx, step):
     elif condition[1] == '>':
         assert(timer1["taken"] > timer2["taken"])
 
+def run_test_step_action_add_auth(ctx, step):
+    print(get_indent(ctx) + "Action:" + step["action"])
+    assert_browser(ctx)
+    browser = ctx['browser']
+    browser.add_auth(step.get("url"), step.get("realm"),
+                     step.get("username"), step.get("password"))
+
+
+def run_test_step_action_remove_auth(ctx, step):
+    print(get_indent(ctx) + "Action:" + step["action"])
+    assert_browser(ctx)
+    browser = ctx['browser']
+    browser.remove_auth(step.get("url"), step.get("realm"),
+                        step.get("username"), step.get("password"))
+
 def run_test_step_action_quit(ctx, step):
     print(get_indent(ctx) + "Action: " + step["action"])
     assert_browser(ctx)
@@ -231,6 +302,8 @@ step_handlers = {
     "timer-stop":   run_test_step_action_timer_stop,
     "timer-check":  run_test_step_action_timer_check,
     "plot-check":   run_test_step_action_plot_check,
+    "add-auth":     run_test_step_action_add_auth,
+    "remove-auth":  run_test_step_action_remove_auth,
     "quit":         run_test_step_action_quit,
 }
 
diff --git a/test/monkey-tests/resource-scheme.yaml 
b/test/monkey-tests/401login.yaml
similarity index 53%
copy from test/monkey-tests/resource-scheme.yaml
copy to test/monkey-tests/401login.yaml
index 791a79c..a9a74cd 100644
--- a/test/monkey-tests/resource-scheme.yaml
+++ b/test/monkey-tests/401login.yaml
@@ -1,5 +1,5 @@
-title: resource scheme
-group: basic
+title: Test the 401 LOGIN functionality
+group: real-world
 steps:
 - action: launch
   language: en
@@ -7,7 +7,7 @@ steps:
   tag: win1
 - action: navigate
   window: win1
-  url: resource:does-not-exist
+  url: https://httpbin.org/basic-auth/foo/bar
 - action: block
   conditions:
   - window: win1
@@ -15,11 +15,15 @@ steps:
 - action: plot-check
   window: win1
   checks:
-  - text-contains: Not found
-  - text-contains: Error 404
+  - text-not-contains: "\"authenticated\": true"
+- action: add-auth
+  url: https://httpbin.org/basic-auth/foo/bar
+  realm: Fake Realm
+  username: foo
+  password: bar
 - action: navigate
   window: win1
-  url: resource:netsurf.png
+  url: https://httpbin.org/basic-auth/foo/bar
 - action: block
   conditions:
   - window: win1
@@ -27,7 +31,7 @@ steps:
 - action: plot-check
   window: win1
   checks:
-  - bitmap-count: 1
+  - text-contains: "\"authenticated\": true"
 - action: window-close
   window: win1
 - action: quit


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to