fix(auth): allow registration on new api versions - fixes #1046 (#1048)

This commit is contained in:
Karol Sójko 2024-03-18 09:08:16 +01:00 committed by GitHub
parent 0f3615ee65
commit f939caf2d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 1 deletions

View file

@ -127,6 +127,43 @@ describe('Register', () => {
})
})
it('should register a new user with default set of roles on new api version', async () => {
const role = new Role()
role.name = RoleName.NAMES.CoreUser
roleRepository.findOneByName = jest.fn().mockReturnValueOnce(role)
expect(
await createUseCase().execute({
email: 'test@test.te',
password: 'asdzxc',
updatedWithUserAgent: 'Mozilla',
apiVersion: '20240226',
ephemeralSession: false,
version: '004',
pwCost: 11,
pwSalt: 'qweqwe',
pwNonce: undefined,
}),
).toEqual({ success: true, authResponse: { foo: 'bar' } })
expect(userRepository.save).toHaveBeenCalledWith({
email: 'test@test.te',
encryptedPassword: expect.any(String),
encryptedServerKey: 'test',
serverEncryptionVersion: 1,
pwCost: 11,
pwNonce: undefined,
pwSalt: 'qweqwe',
updatedWithUserAgent: 'Mozilla',
uuid: expect.any(String),
version: '004',
createdAt: new Date(1),
updatedAt: new Date(1),
roles: Promise.resolve([role]),
})
})
it('should fail to register if applying default settings fails', async () => {
applyDefaultSettings.execute = jest.fn().mockReturnValue(Result.fail('error'))

View file

@ -36,7 +36,7 @@ export class Register implements UseCaseInterface {
const { email, password, apiVersion, ephemeralSession, ...registrationFields } = dto
if (apiVersion !== ApiVersion.v20200115) {
if (![ApiVersion.v20200115, ApiVersion.v20240226].includes(apiVersion as ApiVersion)) {
return {
success: false,
errorMessage: `Unsupported api version: ${apiVersion}`,