diff options
author | Matthew Miller <matthew@millerti.me> | 2022-08-15 21:42:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-15 21:42:25 -0700 |
commit | 1f6154311f596f192748a18258205b0e02c81a13 (patch) | |
tree | bc695fe7f9f258e3dd9385b78bf8d1ca8945fade /packages/server/src/authentication/verifyAuthenticationResponse.test.ts | |
parent | 53602597efcb3295b591812e60d612863d5fde15 (diff) | |
parent | 2357ad6d9999a37a7fbc6d7318b4432e289a249e (diff) |
Merge pull request #254 from MasterKale/feat/fido-conformance-optional-up
feat/fido-conformance-optional-up
Diffstat (limited to 'packages/server/src/authentication/verifyAuthenticationResponse.test.ts')
-rw-r--r-- | packages/server/src/authentication/verifyAuthenticationResponse.test.ts | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/packages/server/src/authentication/verifyAuthenticationResponse.test.ts b/packages/server/src/authentication/verifyAuthenticationResponse.test.ts index ecd3c24..8a5b2fa 100644 --- a/packages/server/src/authentication/verifyAuthenticationResponse.test.ts +++ b/packages/server/src/authentication/verifyAuthenticationResponse.test.ts @@ -372,6 +372,115 @@ test('should return credential backup info', async () => { expect(verification.authenticationInfo?.credentialBackedUp).toEqual(false); }); +test('[FIDO Conformance] should verify if user verification is required and user was verified but not present', () => { + const actualData = esmParseAuthenticatorData.parseAuthenticatorData( + base64url.toBuffer(assertionResponse.response.authenticatorData), + ); + + mockParseAuthData.mockReturnValue({ + ...actualData, + flags: { + up: false, + uv: true, + }, + }); + + const verification = verifyAuthenticationResponse({ + credential: assertionResponse, + expectedChallenge: assertionChallenge, + expectedOrigin: assertionOrigin, + expectedRPID: 'dev.dontneeda.pw', + authenticator: authenticator, + advancedFIDOConfig: { + userVerification: 'required', + } + }); + + expect(verification.verified).toEqual(true); +}); + +test('[FIDO Conformance] should verify if user verification is preferred and user was not verified or present', () => { + const actualData = esmParseAuthenticatorData.parseAuthenticatorData( + base64url.toBuffer(assertionResponse.response.authenticatorData), + ); + + mockParseAuthData.mockReturnValue({ + ...actualData, + flags: { + up: false, + uv: false, + }, + }); + + const verification = verifyAuthenticationResponse({ + credential: assertionResponse, + expectedChallenge: assertionChallenge, + expectedOrigin: assertionOrigin, + expectedRPID: 'dev.dontneeda.pw', + authenticator: authenticator, + requireUserVerification: false, + advancedFIDOConfig: { + userVerification: 'preferred', + }, + }); + + expect(verification.verified).toEqual(true); +}); + +test('[FIDO Conformance] should verify if user verification is discouraged and user was verified but not present', () => { + const actualData = esmParseAuthenticatorData.parseAuthenticatorData( + base64url.toBuffer(assertionResponse.response.authenticatorData), + ); + + mockParseAuthData.mockReturnValue({ + ...actualData, + flags: { + up: false, + uv: true, + }, + }); + + const verification = verifyAuthenticationResponse({ + credential: assertionResponse, + expectedChallenge: assertionChallenge, + expectedOrigin: assertionOrigin, + expectedRPID: 'dev.dontneeda.pw', + authenticator: authenticator, + advancedFIDOConfig: { + userVerification: 'discouraged', + }, + }); + + expect(verification.verified).toEqual(true); +}); + +test('[FIDO Conformance] should verify if user verification is discouraged and user was not verified or present', () => { + const actualData = esmParseAuthenticatorData.parseAuthenticatorData( + base64url.toBuffer(assertionResponse.response.authenticatorData), + ); + + mockParseAuthData.mockReturnValue({ + ...actualData, + flags: { + up: false, + uv: false, + }, + }); + + const verification = verifyAuthenticationResponse({ + credential: assertionResponse, + expectedChallenge: assertionChallenge, + expectedOrigin: assertionOrigin, + expectedRPID: 'dev.dontneeda.pw', + authenticator: authenticator, + advancedFIDOConfig: { + userVerification: 'discouraged', + }, + }); + + expect(verification.verified).toEqual(true); +}); + /** * Assertion examples below */ |