credblob-supported.https.html (2517B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>credBlob extension tests</title> 4 <meta name="timeout" content="long"> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script src=helpers.js></script> 10 <body></body> 11 <script> 12 "use strict"; 13 14 const blobu8 = new Uint8Array(16); 15 window.crypto.getRandomValues(blobu8); 16 const blob = blobu8.buffer; 17 const authenticatorOptions = { 18 protocol: "ctap2_1", 19 extensions: ["credBlob"], 20 }; 21 22 function compareBuffers(a, b) { 23 if (a.byteLength != b.byteLength) { 24 return false; 25 } 26 const a8 = new Uint8Array(a); 27 const b8 = new Uint8Array(b); 28 for (let i = 0; i < a8.length; i++) { 29 if (a8[i] != b8[i]) { 30 return false; 31 } 32 } 33 return true; 34 } 35 36 virtualAuthenticatorPromiseTest(async t => { 37 const cred = await createCredential({ 38 options: { 39 publicKey: {}, 40 }, 41 }); 42 43 const createExtensions = cred.getClientExtensionResults(); 44 assert_not_own_property(createExtensions, "credBlob"); 45 46 const assertion = await navigator.credentials.get({publicKey: { 47 challenge: new Uint8Array(), 48 allowCredentials: [{ 49 id: cred.rawId, 50 type: "public-key", 51 }], 52 extensions: { 53 getCredBlob: true, 54 }, 55 }}); 56 57 const getExtensions = assertion.getClientExtensionResults(); 58 assert_own_property(getExtensions, "getCredBlob"); 59 const emptyBuffer = new Uint8Array(); 60 assert_true(compareBuffers(getExtensions.getCredBlob, emptyBuffer)); 61 }, authenticatorOptions, "assertion without credBlob"); 62 63 virtualAuthenticatorPromiseTest(async t => { 64 const cred = await createCredential({ 65 options: { 66 publicKey: { 67 extensions: { 68 credBlob: blob, 69 }, 70 }, 71 }, 72 }); 73 74 const createExtensions = cred.getClientExtensionResults(); 75 assert_own_property(createExtensions, "credBlob"); 76 assert_equals(createExtensions.credBlob, true, "extension supported at create time"); 77 78 const assertion = await navigator.credentials.get({publicKey: { 79 challenge: new Uint8Array(), 80 allowCredentials: [{ 81 id: cred.rawId, 82 type: "public-key", 83 }], 84 extensions: { 85 getCredBlob: true, 86 }, 87 }}); 88 89 const getExtensions = assertion.getClientExtensionResults(); 90 assert_own_property(getExtensions, "getCredBlob"); 91 assert_true(compareBuffers(getExtensions.getCredBlob, blob)); 92 }, authenticatorOptions, "assertion with credBlob"); 93 </script>