diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /services/fxaccounts/tests/xpcshell/test_keys.js | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/fxaccounts/tests/xpcshell/test_keys.js')
-rw-r--r-- | services/fxaccounts/tests/xpcshell/test_keys.js | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/services/fxaccounts/tests/xpcshell/test_keys.js b/services/fxaccounts/tests/xpcshell/test_keys.js index 6e650a1609..9a25ca90f3 100644 --- a/services/fxaccounts/tests/xpcshell/test_keys.js +++ b/services/fxaccounts/tests/xpcshell/test_keys.js @@ -99,6 +99,128 @@ add_task(async function test_derive_multiple_keys_at_once() { }); }); +add_task(function test_check_valid_scoped_keys() { + const keys = new FxAccountsKeys(null); + add_task(function test_missing_key_data() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + add_task(function test_unexpected_scope() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "UnexpectedScope", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + add_task(function test_not_oct_key() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + // Should be "oct"! + kty: "EC", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + add_task(function test_invalid_kid_not_timestamp() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + // Does not have the timestamp! + kid: "IqQv4onc7VcVE1kTQkyyOw", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + add_task(function test_invalid_kid_not_valid_timestamp() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + // foo is not a valid timestamp! + kid: "foo-IqQv4onc7VcVE1kTQkyyOw", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + add_task(function test_invalid_kid_not_b64_fingerprint() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + // fingerprint not a valid base64 encoded string. + kid: "1510726318123-notvalidb64][", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + add_task(function test_invalid_k_not_base64() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + k: "notavalidb64[]", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + + add_task(function test_multiple_scoped_keys_one_invalid() { + const scopedKeys = { + // Valid + "https://identity.mozilla.com/apps/otherscope": { + kty: "oct", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "https://identity.mozilla.com/apps/otherscope", + }, + // Invalid + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + k: "notavalidb64[]", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), false); + }); + + add_task(function test_valid_scopedkeys() { + const scopedKeys = { + "https://identity.mozilla.com/apps/oldsync": { + kty: "oct", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "https://identity.mozilla.com/apps/oldsync", + }, + "https://identity.mozilla.com/apps/otherscope": { + kty: "oct", + kid: "1510726318123-IqQv4onc7VcVE1kTQkyyOw", + k: "DW_ll5GwX6SJ5GPqJVAuMUP2t6kDqhUulc2cbt26xbTcaKGQl-9l29FHAQ7kUiJETma4s9fIpEHrt909zgFang", + scope: "https://identity.mozilla.com/apps/otherscope", + }, + }; + Assert.equal(keys.validScopedKeys(scopedKeys), true); + }); +}); + add_task(async function test_rejects_bad_scoped_key_data() { const keys = new FxAccountsKeys(null); const uid = "aeaa1725c7a24ff983c6295725d5fc9b"; |