-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Webauthn authenticators now accept 'credentials'
- Loading branch information
1 parent
da8612f
commit 413873b
Showing
4 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { IdxAuthenticator } from '../../../../lib/idx/types'; | ||
import { WebauthnAuthenticatorFactory } from '@okta/test.support/idx'; | ||
import { WebauthnEnrollment } from '../../../../lib/idx/authenticator'; | ||
|
||
describe('idx/authenticator/WebauthnEnrollment', () => { | ||
let testContext; | ||
beforeEach(() => { | ||
const idxAuthenticator: IdxAuthenticator = WebauthnAuthenticatorFactory.build(); | ||
const authenticator = new WebauthnEnrollment(idxAuthenticator); | ||
testContext = { | ||
idxAuthenticator, | ||
authenticator | ||
}; | ||
}); | ||
|
||
describe('constructor', () => { | ||
it('sets the authenticator on the "meta" property', () => { | ||
const { idxAuthenticator, authenticator } = testContext; | ||
expect(authenticator.meta).toBe(idxAuthenticator); | ||
}); | ||
}); | ||
|
||
describe('canVerify', () => { | ||
it('by default, returns false', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.canVerify({ unknownValue: 'foo' })).toBe(false); | ||
}); | ||
it('canVerify using "credentials"', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.canVerify({ credentials: { attestation: 'foo', clientData: 'foo' } })).toBe(true); | ||
}); | ||
it('canVerify without using "credentials"', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.canVerify({ attestation: 'foo', clientData: 'foo' })).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('mapCredentials', () => { | ||
it('returns undefined by default', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.mapCredentials({})).toBe(undefined); | ||
}); | ||
it('returns a credentials object when values passed via credentials', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.mapCredentials({ credentials: { attestation: 'foo', clientData: 'foo' } })).toEqual({ | ||
attestation: 'foo', | ||
clientData: 'foo' | ||
}); | ||
}); | ||
it('returns a credentials object when values passed directly', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.mapCredentials({ attestation: 'foo', clientData: 'foo' })).toEqual({ | ||
attestation: 'foo', | ||
clientData: 'foo' | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getInputs', () => { | ||
it('returns one input: answer', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.getInputs()).toEqual([ | ||
{ name: 'clientData', type: 'string', required: true, visible: false, label: 'Client Data' }, | ||
{ name: 'attestation', type: 'string', required: true, visible: false, label: 'Attestation' }, | ||
]); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { IdxAuthenticator } from '../../../../lib/idx/types'; | ||
import { WebauthnAuthenticatorFactory } from '@okta/test.support/idx'; | ||
import { WebauthnVerification } from '../../../../lib/idx/authenticator'; | ||
|
||
const VALID_CREDS = { | ||
clientData: 'foo', | ||
authenticatorData: 'foo', | ||
signatureData:'foo', | ||
}; | ||
|
||
describe('idx/authenticator/WebauthnEnrollment', () => { | ||
let testContext; | ||
beforeEach(() => { | ||
const idxAuthenticator: IdxAuthenticator = WebauthnAuthenticatorFactory.build(); | ||
const authenticator = new WebauthnVerification(idxAuthenticator); | ||
testContext = { | ||
idxAuthenticator, | ||
authenticator | ||
}; | ||
}); | ||
|
||
describe('constructor', () => { | ||
it('sets the authenticator on the "meta" property', () => { | ||
const { idxAuthenticator, authenticator } = testContext; | ||
expect(authenticator.meta).toBe(idxAuthenticator); | ||
}); | ||
}); | ||
|
||
describe('canVerify', () => { | ||
it('by default, returns false', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.canVerify({ unknownValue: 'foo' })).toBe(false); | ||
}); | ||
it('canVerify using "credentials"', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.canVerify({ credentials: {...VALID_CREDS} })).toBe(true); | ||
}); | ||
it('canVerify without using "credentials"', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.canVerify({...VALID_CREDS})).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('mapCredentials', () => { | ||
it('returns undefined by default', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.mapCredentials({})).toBe(undefined); | ||
}); | ||
it('returns a credentials object when values passed via credentials', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.mapCredentials({ credentials: {...VALID_CREDS} })).toEqual({...VALID_CREDS}); | ||
}); | ||
it('returns a credentials object when values passed directly', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.mapCredentials({ ...VALID_CREDS })).toEqual({...VALID_CREDS}); | ||
}); | ||
}); | ||
|
||
describe('getInputs', () => { | ||
it('returns one input: answer', () => { | ||
const { authenticator } = testContext; | ||
expect(authenticator.getInputs()).toEqual([ | ||
{ name: 'authenticatorData', type: 'string', label: 'Authenticator Data', required: true, visible: false }, | ||
{ name: 'clientData', type: 'string', label: 'Client Data', required: true, visible: false }, | ||
{ name: 'signatureData', type: 'string', label: 'Signature Data', required: true, visible: false }, | ||
]); | ||
}); | ||
}); | ||
}); |