dom/u2f/tests/frame_register.html
author ffxbld <ffxbld@mozilla.com>
Mon, 10 Aug 2020 10:14:10 +0000
changeset 605814 7bf8ce68eb7981796d4e06fc6c75b3c9ffd5c2a1
parent 555809 3b3c5e0e1bc4a58d8a7d5718745cc41153e06a76
permissions -rw-r--r--
No Bug, mozilla-release repo-update remote-settings - a=repo-update r=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D86531

<!DOCTYPE html>
<meta charset=utf-8>
<head>
  <script type="text/javascript" src="frame_utils.js"></script>
  <script type="text/javascript" src="u2futil.js"></script>
</head>
<body>
<p>Register behavior</p>
<script class="testbody" type="text/javascript">
"use strict";
var version = "U2F_V2";
var challenge = new Uint8Array(16);

async function doTests() {
  local_is(window.location.origin, "https://example.com", "Is loaded correctly");

  // basic check
  await promiseU2FRegister("https://example.com/appId", [{
    version,
    challenge: bytesToBase64UrlSafe(challenge),
  }], [], function(res){
    local_is(res.version, version, "Version should be set correctly");
    local_ok(res.clientData.length > 0, "ClientData must be set");
    local_ok(res.registrationData.length > 0, "RegistrationData must be set");
    local_is(res.errorCode, 0, "AppID should work from the domain");
  });

  await promiseU2FRegister("https://example.net/appId", [{
    version,
    challenge: bytesToBase64UrlSafe(challenge),
  }], [], function(res){
    local_is(res.errorCode, 2, "AppID should not work from other domains");
  });

  await promiseU2FRegister("", [], [], function(res){
    local_is(res.errorCode, 2, "Empty register requests");
  });

  local_doesThrow(function(){
    u2f.register("", null, [], null);
  }, "Non-array register requests");

  local_doesThrow(function(){
    u2f.register("", [], null, null);
  }, "Non-array sign requests");

  local_doesThrow(function(){
    u2f.register("", null, null, null);
  }, "Non-array for both arguments");

  await promiseU2FRegister("", [{}], [], function(res){
    local_is(res.errorCode, 2, "Empty request");
  });

  await promiseU2FRegister("https://example.net/appId", [{
      version,
    }], [], function(res){
      local_is(res.errorCode, 2, "Missing challenge");
  });

  await promiseU2FRegister("https://example.net/appId", [{
      challenge: bytesToBase64UrlSafe(challenge),
    }], [], function(res){
     local_is(res.errorCode, 2, "Missing version");
  });

  await promiseU2FRegister("https://example.net/appId", [{
      version: "a_version_00",
      challenge: bytesToBase64UrlSafe(challenge),
    }], [], function(res){
      local_is(res.errorCode, 2, "Invalid version");
  });

  local_finished();
};

doTests();
</script>
</body>
</html>