diff options
author | Matthew Miller <matthew@millerti.me> | 2020-05-21 18:44:12 -0700 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2020-05-21 18:44:12 -0700 |
commit | e8c2c3171f6143409759f6d9ef06fab53600448c (patch) | |
tree | 9905f4000765f2240c4213508f7c73b5a1f3cb66 | |
parent | 0b37a9be7bcead032ba91c03d979c097c65d70bd (diff) |
Add unit tests for generateAttestationOptions in server
-rw-r--r-- | packages/server/src/attestation/generateAttestationOptions.test.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/packages/server/src/attestation/generateAttestationOptions.test.ts b/packages/server/src/attestation/generateAttestationOptions.test.ts new file mode 100644 index 0000000..4c6e605 --- /dev/null +++ b/packages/server/src/attestation/generateAttestationOptions.test.ts @@ -0,0 +1,66 @@ +import generateAttestationOptions from './generateAttestationOptions'; + +test('should generate credential request options suitable for sending via JSON', () => { + const serviceName = 'WebAuthntine'; + const rpID = 'not.real'; + const challenge = 'totallyrandomvalue'; + const userID = '1234'; + const username = 'usernameHere'; + const timeout = 1; + const attestationType = 'indirect'; + + const options = generateAttestationOptions( + serviceName, + rpID, + challenge, + userID, + username, + timeout, + attestationType, + ); + + expect(options).toEqual({ + publicKey: { + challenge, + rp: { + name: serviceName, + id: rpID, + }, + user: { + id: userID, + name: username, + displayName: username, + }, + pubKeyCredParams: [{ + alg: -7, + type: 'public-key', + }], + timeout, + attestation: attestationType, + }, + }); +}); + +test('defaults to 60 seconds if no timeout is specified', () => { + const options = generateAttestationOptions( + 'WebAuthntine', + 'not.real', + 'totallyrandomvalue', + '1234', + 'usernameHere', + ); + + expect(options.publicKey.timeout).toEqual(60000); +}); + +test('defaults to direct attestation if no attestation type is specified', () => { + const options = generateAttestationOptions( + 'WebAuthntine', + 'not.real', + 'totallyrandomvalue', + '1234', + 'usernameHere', + ); + + expect(options.publicKey.attestation).toEqual('direct'); +}); |