feat(auth): add listing authenticators

This commit is contained in:
Karol Sójko
2022-12-29 13:37:30 +01:00
parent 7df699353c
commit 01837eaea9
25 changed files with 207 additions and 2 deletions
@@ -32,6 +32,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
const result = await useCase.execute({
userUuid: 'invalid',
name: 'name',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
@@ -49,6 +50,27 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
)
})
it('should return error if name is invalid', async () => {
const useCase = createUseCase()
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
name: '',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
response: {
attestationObject: Buffer.from('attestationObject'),
clientDataJSON: Buffer.from('clientDataJSON'),
},
type: 'type',
},
})
expect(result.isFailed()).toBeTruthy()
expect(result.getError()).toEqual('Could not verify authenticator registration response: Given value is empty: ')
})
it('should return error if challenge is not found', async () => {
authenticatorChallengeRepository.findByUserUuid = jest.fn().mockReturnValue(null)
@@ -56,6 +78,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
name: 'name',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
@@ -96,6 +119,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
name: 'name',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
@@ -129,6 +153,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
name: 'name',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
@@ -164,6 +189,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
name: 'name',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
@@ -213,6 +239,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
name: 'name',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
@@ -256,6 +283,7 @@ describe('VerifyAuthenticatorRegistrationResponse', () => {
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
name: 'name',
registrationCredential: {
id: Buffer.from('id'),
rawId: Buffer.from('rawId'),
@@ -1,4 +1,4 @@
import { Dates, Result, UseCaseInterface, Uuid } from '@standardnotes/domain-core'
import { Dates, Result, UseCaseInterface, Uuid, Validator } from '@standardnotes/domain-core'
import { VerifiedRegistrationResponse, verifyRegistrationResponse } from '@simplewebauthn/server'
import { AuthenticatorChallengeRepositoryInterface } from '../../Authenticator/AuthenticatorChallengeRepositoryInterface'
@@ -20,6 +20,11 @@ export class VerifyAuthenticatorRegistrationResponse implements UseCaseInterface
}
const userUuid = userUuidOrError.getValue()
const nameValidation = Validator.isNotEmpty(dto.name)
if (nameValidation.isFailed()) {
return Result.fail(`Could not verify authenticator registration response: ${nameValidation.getError()}`)
}
const authenticatorChallenge = await this.authenticatorChallengeRepository.findByUserUuid(userUuid)
if (!authenticatorChallenge) {
return Result.fail('Could not verify authenticator registration response: challenge not found')
@@ -47,6 +52,7 @@ export class VerifyAuthenticatorRegistrationResponse implements UseCaseInterface
const authenticatorOrError = Authenticator.create({
userUuid,
name: dto.name,
counter: verification.registrationInfo.counter,
credentialBackedUp: verification.registrationInfo.credentialBackedUp,
credentialDeviceType: verification.registrationInfo.credentialDeviceType,
@@ -1,4 +1,5 @@
export interface VerifyAuthenticatorRegistrationResponseDTO {
userUuid: string
name: string
registrationCredential: Record<string, unknown>
}