Bug 1103196 - Error on encountering invalid certificate; r?automatedtester draft
authorAndreas Tolfsen <ato@mozilla.com>
Sun, 06 Nov 2016 18:01:23 +0000
changeset 439890 007b922c4edce2b4181f0f23363c3c3a6803076f
parent 439889 721295480f0f2e4f454b3b8297fe7c64d2c98fad
child 439891 cb8d0d1e5fedb4f20ab69313cc7c9c4a12b24556
push id36114
push userbmo:ato@mozilla.com
push dateWed, 16 Nov 2016 18:21:30 +0000
reviewersautomatedtester
bugs1103196
milestone53.0a1
Bug 1103196 - Error on encountering invalid certificate; r?automatedtester When arriving at a document which baseURI starts with `about:certerror` will cause Marionette to now return `error.InsecureCertificateError`. This is mandated by the WebDriver specification. This does, however, mark a non-backwards compatible change in Marionette. It is assumed we will be able to mitigate this change in error type as few consumers, if any, rely on the more generic type considering we did not support invalid TLS certificates prior to this push. MozReview-Commit-ID: JcIMvCXimB
testing/marionette/driver.js
testing/marionette/listener.js
--- a/testing/marionette/driver.js
+++ b/testing/marionette/driver.js
@@ -1412,27 +1412,32 @@ GeckoDriver.prototype.switchToParentFram
  *     A web element reference to the element to switch to.
  * @param {(string|number)} id
  *     If element is not defined, then this holds either the id, name,
  *     or index of the frame to switch to.
  */
 GeckoDriver.prototype.switchToFrame = function*(cmd, resp) {
   let {id, element, focus} = cmd.parameters;
 
-  let checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+  const otherErrorsExpr = /about:.+(error)|(blocked)\?/;
+  const checkTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+
   let curWindow = this.getCurrentWindow();
 
   let checkLoad = function() {
-    let errorRegex = /about:.+(error)|(blocked)\?/;
-    let curWindow = this.getCurrentWindow();
-    if (curWindow.document.readyState == "complete") {
+    let win = this.getCurrentWindow();
+    if (win.document.readyState == "complete") {
       return;
-    } else if (curWindow.document.readyState == "interactive" &&
-        errorRegex.exec(curWindow.document.baseURI)) {
-      throw new UnknownError("Error loading page");
+    } else if (win.document.readyState == "interactive") {
+      let baseURI = win.document.baseURI;
+      if (baseURI.startsWith("about:certerror")) {
+        throw new InsecureCertificateError();
+      } else if (otherErrorsExpr.exec(win.document.baseURI)) {
+        throw new UnknownError("Error loading page");
+      }
     }
 
     checkTimer.initWithCallback(checkLoad.bind(this), 100, Ci.nsITimer.TYPE_ONE_SHOT);
   };
 
   if (this.context == Context.CHROME) {
     let foundFrame = null;
 
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -870,20 +870,25 @@ function pollForReadyState(msg, start = 
     let doc = curContainer.frame.document;
     let now = new Date().getTime();
     if (pageTimeout == null || (now - start) <= pageTimeout) {
       // document fully loaded
       if (doc.readyState == "complete") {
         callback();
         sendOk(command_id);
 
+      // document with an insecure cert
+      } else if (doc.readyState == "interactive" &&
+          doc.baseURI.startsWith("about:certerror")) {
+        callback();
+        sendError(new InsecureCertificateError(), command_id);
+
       // we have reached an error url without requesting it
       } else if (doc.readyState == "interactive" &&
-          /about:.+(error)\?/.exec(doc.baseURI) &&
-          !doc.baseURI.startsWith(url)) {
+          /about:.+(error)\?/.exec(doc.baseURI)) {
         callback();
         sendError(new UnknownError("Reached error page: " + doc.baseURI), command_id);
 
       // return early for about: urls
       } else if (doc.readyState == "interactive" && doc.baseURI.startsWith("about:")) {
         callback();
         sendOk(command_id);