mirror of
https://github.com/standardnotes/server
synced 2026-07-14 00:01:54 -04:00
fix(auth): updating counter post authenticator verification
This commit is contained in:
@@ -7,6 +7,7 @@ export interface AuthenticatorRepositoryInterface {
|
||||
findById(id: UniqueEntityId): Promise<Authenticator | null>
|
||||
findByUserUuidAndCredentialId(userUuid: Uuid, credentialId: string): Promise<Authenticator | null>
|
||||
save(authenticator: Authenticator): Promise<void>
|
||||
updateCounter(id: UniqueEntityId, counter: number): Promise<void>
|
||||
remove(authenticator: Authenticator): Promise<void>
|
||||
removeByUserUuid(userUuid: Uuid): Promise<void>
|
||||
}
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => {
|
||||
|
||||
authenticatorRepository = {} as jest.Mocked<AuthenticatorRepositoryInterface>
|
||||
authenticatorRepository.findByUserUuidAndCredentialId = jest.fn().mockReturnValue(authenticator)
|
||||
authenticatorRepository.save = jest.fn()
|
||||
authenticatorRepository.updateCounter = jest.fn()
|
||||
|
||||
authenticatorChallengeRepository = {} as jest.Mocked<AuthenticatorChallengeRepositoryInterface>
|
||||
authenticatorChallengeRepository.findByUserUuid = jest.fn().mockReturnValue({
|
||||
@@ -221,6 +221,6 @@ describe('VerifyAuthenticatorAuthenticationResponse', () => {
|
||||
})
|
||||
|
||||
expect(result.isFailed()).toBeFalsy()
|
||||
expect(authenticatorRepository.save).toHaveBeenCalled()
|
||||
expect(authenticatorRepository.updateCounter).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
+1
-3
@@ -60,9 +60,7 @@ export class VerifyAuthenticatorAuthenticationResponse implements UseCaseInterfa
|
||||
return Result.fail(`Could not verify authenticator authentication response: ${(error as Error).message}`)
|
||||
}
|
||||
|
||||
authenticator.props.counter = verification.authenticationInfo.newCounter as number
|
||||
|
||||
await this.authenticatorRepository.save(authenticator)
|
||||
await this.authenticatorRepository.updateCounter(authenticator.id, verification.authenticationInfo.newCounter)
|
||||
|
||||
return Result.ok(true)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,19 @@ export class MySQLAuthenticatorRepository implements AuthenticatorRepositoryInte
|
||||
private mapper: MapperInterface<Authenticator, TypeORMAuthenticator>,
|
||||
) {}
|
||||
|
||||
async updateCounter(id: UniqueEntityId, counter: number): Promise<void> {
|
||||
await this.ormRepository
|
||||
.createQueryBuilder()
|
||||
.update()
|
||||
.set({
|
||||
counter,
|
||||
})
|
||||
.where('uuid = :uuid', {
|
||||
uuid: id.toString(),
|
||||
})
|
||||
.execute()
|
||||
}
|
||||
|
||||
async removeByUserUuid(userUuid: Uuid): Promise<void> {
|
||||
await this.ormRepository
|
||||
.createQueryBuilder()
|
||||
|
||||
Reference in New Issue
Block a user