DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
<!DOCTYPE html>
<meta charset=utf-8>
<head>
  <title>Test for MakeCredential for W3C Web Authentication</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="u2futil.js"></script>
  <script type="text/javascript" src="pkijs/common.js"></script>
  <script type="text/javascript" src="pkijs/asn1.js"></script>
  <script type="text/javascript" src="pkijs/x509_schema.js"></script>
  <script type="text/javascript" src="pkijs/x509_simpl.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>

  <h1>Test for MakeCredential for W3C Web Authentication</h1>
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1309284">Mozilla Bug 1309284</a>

  <script class="testbody" type="text/javascript">
    "use strict";

    // Execute the full-scope test
    SimpleTest.waitForExplicitFinish();

    function arrivingHereIsGood(aResult) {
      ok(true, "Good result! Received a: " + aResult);
      return Promise.resolve();
    }

    function arrivingHereIsBad(aResult) {
      ok(false, "Bad result! Received a: " + aResult);
      return Promise.resolve();
    }

    function expectNotAllowedError(aResult) {
      ok(aResult.toString().startsWith("NotAllowedError"), "Expecting a NotAllowedError");
      return Promise.resolve();
    }

    function expectTypeError(aResult) {
      ok(aResult.toString().startsWith("TypeError"), "Expecting a TypeError");
      return Promise.resolve();
    }

    function expectNotSupportedError(aResult) {
      ok(aResult.toString().startsWith("NotSupportedError"), "Expecting a NotSupportedError");
      return Promise.resolve();
    }

    SpecialPowers.pushPrefEnv({"set": [["security.webauth.webauthn", true],
                                       ["security.webauth.webauthn_enable_softtoken", true],
                                       ["security.webauth.webauthn_enable_android_fido2", false],
                                       ["security.webauth.webauthn_enable_usbtoken", false]]}, runTests);
    function runTests() {
      is(navigator.authentication, undefined, "navigator.authentication does not exist any longer");
      isnot(navigator.credentials, undefined, "Credential Management API endpoint must exist");
      isnot(navigator.credentials.create, undefined, "CredentialManagement create API endpoint must exist");
      isnot(navigator.credentials.get, undefined, "CredentialManagement get API endpoint must exist");

      let credm = navigator.credentials;

      let gCredentialChallenge = new Uint8Array(16);
      window.crypto.getRandomValues(gCredentialChallenge);

      let rp = {id: document.domain, name: "none", icon: "none"};
      let user = {id: new Uint8Array(64), name: "none", icon: "none", displayName: "none"};
      let param = {type: "public-key", alg: cose_alg_ECDSA_w_SHA256};
      let unsupportedParam = {type: "public-key", alg: cose_alg_ECDSA_w_SHA512};
      let badParam = {type: "SimplePassword", alg: "MaxLength=2"};

      var testFuncs = [
        // Test basic good call
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsGood)
                      .catch(arrivingHereIsBad);
        },

        // Test empty account
        function() {
          let makeCredentialOptions = {
            challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test without rp.name
        function() {
          let rp1 = {id: document.domain, icon: "none"};
          let makeCredentialOptions = {
            rp: rp1, user: user, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test without user.id
        function() {
          let user1 = {name: "none", icon: "none", displayName: "none"};
          let makeCredentialOptions = {
            rp: rp, user: user1, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test without user.name
        function() {
          let user1 = {id: new Uint8Array(64), icon: "none", displayName: "none"};
          let makeCredentialOptions = {
            rp: rp, user: user1, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test without user.displayName
        function() {
          let user1 = {id: new Uint8Array(64), name: "none", icon: "none"};
          let makeCredentialOptions = {
            rp: rp, user: user1, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test with a user handle that exceeds the max length
        function() {
          let user1 = {id: new Uint8Array(65), name: "none", icon: "none", displayName: "none"};
          let makeCredentialOptions = {
            rp: rp, user: user1, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test without any parameters; this is acceptable meaning the RP ID is
        // happy to take any credential type
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge, pubKeyCredParams: []
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsGood)
                      .catch(arrivingHereIsBad);
        },

        // Test without a parameter array at all
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge
          };
          return credm.create({publicKey: makeCredentialOptions})
               .then(arrivingHereIsBad)
               .catch(expectTypeError);
        },

        // Test with an unsupported parameter
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge, pubKeyCredParams: [unsupportedParam]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectNotSupportedError);
        },

        // Test with an unsupported parameter and a good one
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge,
            pubKeyCredParams: [param, unsupportedParam]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsGood)
                      .catch(arrivingHereIsBad);
        },

        // Test with a bad parameter
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge, pubKeyCredParams: [badParam]
          };
          return credm.create({publicKey: makeCredentialOptions})
               .then(arrivingHereIsBad)
               .catch(expectTypeError);
        },

        // Test with an unsupported parameter, and a bad one
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge,
            pubKeyCredParams: [unsupportedParam, badParam]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test with an unsupported parameter, a bad one, and a good one. This
        // should still fail, as anything with a badParam should fail.
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge,
            pubKeyCredParams: [param, unsupportedParam, badParam]
          };
          return credm.create({publicKey: makeCredentialOptions})
               .then(arrivingHereIsBad)
               .catch(expectTypeError);
        },

        // Test without a challenge
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test with an invalid challenge
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: "begone, thou ill-fitting moist glove!",
            pubKeyCredParams: [unsupportedParam]
          };
          return credm.create({publicKey: makeCredentialOptions})
               .then(arrivingHereIsBad)
               .catch(expectTypeError);
        },

        // Test with duplicate pubKeyCredParams
        function() {
          let makeCredentialOptions = {
            rp: rp, user: user, challenge: gCredentialChallenge,
            pubKeyCredParams: [param, param, param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsGood)
                      .catch(arrivingHereIsBad);
        },

        // Test with an RP ID that is not a valid domain string
        function() {
          let rp1 = { id: document.domain + ":somejunk", name: "none", icon: "none" };
          let makeCredentialOptions = {
            rp: rp1, user: user, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(arrivingHereIsGood);
        },

        // Test with another RP ID that is not a valid domain string
        function() {
          let rp1 = { id: document.domain + ":8888", name: "none", icon: "none" };
          let makeCredentialOptions = {
            rp: rp1, user: user, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(arrivingHereIsGood);
        },

        // Test with missing rp
        function() {
          let makeCredentialOptions = {
            user: user, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test with incorrect user ID type
        function() {
          let invalidType = user;
          invalidType.id = "a string, which is not a buffer";
          let makeCredentialOptions = {
            user: invalidType, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test with missing user
        function() {
          let makeCredentialOptions = {
            rp: rp, challenge: gCredentialChallenge, pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test a complete account
        function() {
          let completeRP = {id: document.domain, name: "Foxxy Name",
                            icon: "https://example.com/fox.svg"};
          let completeUser = {id: string2buffer("foxes_are_the_best@example.com"),
                              name: "Fox F. Foxington",
                              icon: "https://example.com/fox.svg",
                              displayName: "Foxxy V"};
          let makeCredentialOptions = {
            rp: completeRP, user: completeUser, challenge: gCredentialChallenge,
            pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsGood)
                      .catch(arrivingHereIsBad);
        },

        // Test with too-large user ID buffer
        function() {
          let hugeUser = {id: new Uint8Array(65),
                              name: "Fox F. Foxington",
                              icon: "https://example.com/fox.svg",
                              displayName: "Foxxy V"};
          let makeCredentialOptions = {
            rp: rp, user: hugeUser, challenge: gCredentialChallenge,
            pubKeyCredParams: [param]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsBad)
                      .catch(expectTypeError);
        },

        // Test with excluding unknown transports
        function() {
          let completeRP = {id: document.domain, name: "Foxxy Name",
                            icon: "https://example.com/fox.svg"};
          let completeUser = {id: string2buffer("foxes_are_the_best@example.com"),
                              name: "Fox F. Foxington",
                              icon: "https://example.com/fox.svg",
                              displayName: "Foxxy V"};
          let excludedUnknownTransport = {type: "public-key",
                                          id: string2buffer("123"),
                                          transports: ["unknown", "usb"]};
          let makeCredentialOptions = {
            rp: completeRP, user: completeUser, challenge: gCredentialChallenge,
            pubKeyCredParams: [param], excludeCredentials: [excludedUnknownTransport]
          };
          return credm.create({publicKey: makeCredentialOptions})
                      .then(arrivingHereIsGood)
                      .catch(arrivingHereIsBad);
        }];

      var i = 0;
      var runNextTest = () => {
        if (i == testFuncs.length) {
          SimpleTest.finish();
          return;
        }
        testFuncs[i]().then(() => { runNextTest(); });
        i = i + 1;
      };
      runNextTest();
    };

  </script>

</body>
</html>