public-key-credential-request-options-from-json.https.window.js (3856B)
1 // META: script=/resources/testdriver.js 2 // META: script=/resources/testdriver-vendor.js 3 // META: script=/resources/utils.js 4 // META: script=helpers.js 5 6 // The string "test" as ASCII bytes and base64url-encoded. 7 const test_bytes = new Uint8Array([0x74, 0x65, 0x73, 0x74]); 8 const test_b64 = "dGVzdA"; 9 10 test(() => { 11 let actual = PublicKeyCredential.parseRequestOptionsFromJSON({ 12 challenge: test_b64, 13 timeout: 60000, 14 rpId: "example.com", 15 allowCredentials: [ 16 { type: "public-key", id: test_b64 }, 17 ], 18 userVerification: "required", 19 hints: ["hybrid", "security-key"], 20 }); 21 let expected = { 22 challenge: test_bytes, 23 timeout: 60000, 24 rpId: "example.com", 25 allowCredentials: [ 26 { type: "public-key", id: test_bytes }, 27 ], 28 userVerification: "required", 29 hints: ["hybrid", "security-key"], 30 }; 31 32 assert_equals(actual.rpId, expected.rpId); 33 assert_true(bytesEqual(actual.challenge, expected.challenge)); 34 assert_equals(actual.timeout, expected.timeout); 35 assert_equals(actual.allowCredentials.length, expected.allowCredentials.length); 36 assert_equals(actual.allowCredentials[0].type, expected.allowCredentials[0].type); 37 assert_true(bytesEqual(actual.allowCredentials[0].id, expected.allowCredentials[0].id)); 38 assert_equals(actual.userVerification, expected.userVerification); 39 if (actual.hasOwnProperty("hints")) { 40 // Not all implementations support hints yet. 41 assertJsonEquals(actual.hints, expected.hints); 42 } 43 }, "parseRequestOptionsFromJSON()"); 44 45 test(() => { 46 let actual = PublicKeyCredential.parseRequestOptionsFromJSON({ 47 challenge: test_b64, 48 extensions: { 49 appid: "app id", 50 largeBlob: { 51 read: true, 52 }, 53 getCredBlob: true, 54 supplementalPubKeys: { 55 scopes: ["spk scope"], 56 attestation: "directest", 57 attestationFormats: ["asn2"], 58 }, 59 prf: { 60 eval: { 61 first: test_b64, 62 second: test_b64, 63 }, 64 evalByCredential: { 65 "test cred": { 66 first: test_b64, 67 second: test_b64, 68 }, 69 }, 70 }, 71 }, 72 }); 73 let expected = { 74 challenge: test_b64, 75 extensions: { 76 appid: "app id", 77 largeBlob: { 78 read: true, 79 }, 80 getCredBlob: true, 81 supplementalPubKeys: { 82 scopes: ["spk scope"], 83 attestation: "directest", 84 attestationFormats: ["asn2"], 85 }, 86 prf: { 87 eval: { 88 first: test_bytes, 89 second: test_bytes, 90 }, 91 evalByCredential: { 92 "test cred": { 93 first: test_bytes, 94 second: test_bytes, 95 }, 96 }, 97 }, 98 }, 99 }; 100 101 assert_equals(actual.extensions.appid, expected.extensions.appid); 102 // Some implementations do not support all of these extensions. 103 if (actual.extensions.hasOwnProperty('largeBlob')) { 104 assert_equals( 105 actual.extensions.largeBlob.read, expected.extensions.largeBlob.read); 106 } 107 if (actual.extensions.hasOwnProperty('getCredBlob')) { 108 assert_equals( 109 actual.extensions.getCredBlob, expected.extensions.getCredBlob); 110 } 111 if (actual.extensions.hasOwnProperty('supplementalPubKeys')) { 112 assertJsonEquals( 113 actual.extensions.supplementalPubKeys, 114 expected.extensions.supplementalPubKeys); 115 } 116 if (actual.extensions.hasOwnProperty('prf')) { 117 let prfValuesEquals = (a, b) => { 118 return bytesEqual(a.first, b.first) && bytesEqual(a.second, b.second); 119 }; 120 assert_true( 121 prfValuesEquals( 122 actual.extensions.prf.eval, expected.extensions.prf.eval), 123 'prf eval'); 124 assert_true( 125 prfValuesEquals( 126 actual.extensions.prf.evalByCredential['test cred'], 127 expected.extensions.prf.evalByCredential['test cred']), 128 'prf ebc'); 129 } 130 }, "parseRequestOptionsFromJSON() with extensions");