tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_webauthn_store_credential.html (2168B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <head>
      4  <title>Tests for Store for W3C Web Authentication</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="text/javascript" src="u2futil.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 
     11  <h1>Tests for Store for W3C Web Authentication</h1>
     12  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1309284">Mozilla Bug 1309284</a>
     13 
     14  <script class="testbody" type="text/javascript">
     15    "use strict";
     16 
     17    add_task(async () => {
     18      await addVirtualAuthenticator();
     19    });
     20 
     21    isnot(navigator.credentials, undefined, "Credential Management API endpoint must exist");
     22    isnot(navigator.credentials.create, undefined, "CredentialManagement create API endpoint must exist");
     23    isnot(navigator.credentials.get, undefined, "CredentialManagement get API endpoint must exist");
     24    isnot(navigator.credentials.store, undefined, "CredentialManagement store API endpoint must exist");
     25 
     26    function arrivingHereIsBad(aResult) {
     27      ok(false, "Bad result! Received a: " + aResult);
     28      return Promise.resolve();
     29    }
     30 
     31    function expectNotSupportedError(aResult) {
     32      ok(aResult.toString().startsWith("NotSupportedError"), "Expecting a NotSupportedError, received: " + aResult);
     33      return Promise.resolve();
     34    }
     35 
     36    add_task(async function test_store_credential() {
     37      let credentialChallenge = new Uint8Array(16);
     38      window.crypto.getRandomValues(credentialChallenge);
     39 
     40      let rp = {id: document.domain, name: "none"};
     41      let user = {id: new Uint8Array(64), name: "none", displayName: "none"};
     42      let params = [ {type: "public-key", alg: "es256"}, {type: "public-key", alg: -7} ]
     43 
     44      let makeCredentialOptions = {
     45        rp, user, challenge: credentialChallenge, pubKeyCredParams: params
     46      };
     47 
     48      let credential = await navigator.credentials.create({publicKey: makeCredentialOptions})
     49        .catch(arrivingHereIsBad);
     50 
     51      await navigator.credentials.store(credential)
     52        .then(arrivingHereIsBad)
     53        .catch(expectNotSupportedError);
     54    });
     55  </script>
     56 
     57 </body>
     58 </html>