From f939caf2d9a781d42989ad6e92a5c7150ff48e19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20S=C3=B3jko?= Date: Mon, 18 Mar 2024 09:08:16 +0100 Subject: [PATCH] fix(auth): allow registration on new api versions - fixes #1046 (#1048) --- .../auth/src/Domain/UseCase/Register.spec.ts | 37 +++++++++++++++++++ packages/auth/src/Domain/UseCase/Register.ts | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/auth/src/Domain/UseCase/Register.spec.ts b/packages/auth/src/Domain/UseCase/Register.spec.ts index 985ac0d3f..ea4a92826 100644 --- a/packages/auth/src/Domain/UseCase/Register.spec.ts +++ b/packages/auth/src/Domain/UseCase/Register.spec.ts @@ -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')) diff --git a/packages/auth/src/Domain/UseCase/Register.ts b/packages/auth/src/Domain/UseCase/Register.ts index 64684e77e..d7558b832 100644 --- a/packages/auth/src/Domain/UseCase/Register.ts +++ b/packages/auth/src/Domain/UseCase/Register.ts @@ -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}`,