auth-tests.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import assert from 'assert';
  2. import storage from '../../../app/storage';
  3. import { decryptBundle, prepareScopedBundleKey } from '../../../app/fxa';
  4. import { b64ToArray } from '../../../app/utils';
  5. const decoder = new TextDecoder();
  6. describe('user auth', function() {
  7. it('prepares ECDH keys for PKCE auth', async function() {
  8. const empty = storage.get('scopedBundlePrivateKey');
  9. assert.equal(empty, undefined);
  10. const publicKeyB64 = await prepareScopedBundleKey(storage);
  11. const publicKey = JSON.parse(decoder.decode(b64ToArray(publicKeyB64)));
  12. assert(!publicKey.d, 'not a public key');
  13. assert(publicKey.x);
  14. assert(publicKey.y);
  15. assert.equal(publicKey.kty, 'EC');
  16. assert.equal(publicKey.crv, 'P-256');
  17. const privateKey = JSON.parse(storage.get('scopedBundlePrivateKey'));
  18. storage.remove('scopedBundlePrivateKey');
  19. assert.equal(privateKey.kty, 'EC');
  20. assert.equal(privateKey.crv, 'P-256');
  21. assert(privateKey.d, 'not a private key');
  22. });
  23. it('decrypts the PKCE auth bundle', async function() {
  24. storage.set(
  25. 'scopedBundlePrivateKey',
  26. '{"kty":"EC","kid":"cV9_thVX9XRa-R2nVZF9rFdwrcR_eST4UZuUCx03ebI","crv":"P-256","x":"-0OOb6SPdYBz0CkQLWRu8ojDUhRe-VoKnwLEBi97KAk","y":"U3fXgj1LV7KhiO5O60niMjPpDqToh15-R6C22NnmNXY","d":"KfIQCxZrqSI6j69rAC6fEiGIYKwYv2buQG9NTcKOiGc"}'
  27. );
  28. const jwks = await decryptBundle(
  29. storage,
  30. 'eyJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiRUNESC1FUyIsImtpZCI6ImNWOV90aFZYOVhSYS1SMm5WWkY5ckZkd3JjUl9lU1Q0VVp1VUN4MDNlYkkiLCJlcGsiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiJqckcwajNFODNodDZJcDE1YmtuZWRUV3kwZmR1WnR0V3NtMkFybUNoQU5rIiwieSI6Ijl3SmNQUDRrQmQ5amtCbEJJcWRhclQ2NjVIQU00SndUX0FSSFc0aTN4QUUifX0..Dkf-FXtakCiPuXjW.-KfVQEntYjUe3f5OxslSQwjLFauc50RurLQHDV75sUixNTlsjTIldCZVb6WUKpQkpOdFHOUYFX9_Cvk2ENKdfcVm2eTuyomlKklHF3q5209KwJz8lDK3gOQuAlz79eDou0k_Z3JNGu-qZ8IiDhZZ9iNSgBrsq0BZwVXZ9ViSFEW-YzJBQlKmildscXhp_-Lf6-qiJJrPbZCXFD3PZmzcule3kyBOarg_fjjHLFlIpdjP1lI5wBETqdjk7iBKeO2isSQO7-8.q5EzqP6OPg9yb5BcJH2oFg'
  31. );
  32. assert.deepEqual(jwks, {
  33. 'https://identity.mozilla.com/apps/send': {
  34. kty: 'oct',
  35. scope: 'https://identity.mozilla.com/apps/send',
  36. k: '5_jrbS76RzJ4EwlKSl527vqz3BDqf5DM4sNsoEK_hoA',
  37. kid: '1414456160-n6yE-eL-ADvnsJo_huq3DA'
  38. }
  39. });
  40. });
  41. });