feat: sqlite driver for auth service (#572)

* wip: initial sqlite bootstrap

* wip: switch to sqlite3 as default db type

* wip: boilerplate data

* fix(auth): case sensitive register and login

* fix(auth): refactor username validations

* fix(auth): allow changing username to both username and email:

* fix(auth): lock middleware for recovery log in

* fix(domain-core): specs for invalid types

* fix(auth): lock middleware specs

* fix(auth): typeorm code arrangements

* fix: running e2e on both mysql and sqlite in ci
This commit is contained in:
Karol Sójko
2023-04-27 11:17:01 +02:00
committed by GitHub
parent 34018ae7eb
commit 3aef5998df
238 changed files with 526592 additions and 205 deletions
@@ -24,7 +24,7 @@ describe('GetUserKeyParams', () => {
user = {} as jest.Mocked<User>
userRepository = {} as jest.Mocked<UserRepositoryInterface>
userRepository.findOneByEmail = jest.fn().mockReturnValue(user)
userRepository.findOneByUsernameOrEmail = jest.fn().mockReturnValue(user)
userRepository.findOneByUuid = jest.fn().mockReturnValue(user)
logger = {} as jest.Mocked<Logger>
@@ -46,6 +46,12 @@ describe('GetUserKeyParams', () => {
expect(keyParamsFactory.create).toHaveBeenCalledWith(user, true)
})
it('should throw an error when searching by email and the email is invalid', async () => {
await expect(createUseCase().execute({ email: '', authenticated: false })).rejects.toThrowError(
'Username cannot be empty',
)
})
it('should get key params for an unauthenticated user - searching by email', async () => {
expect(await createUseCase().execute({ email: '[email protected]', authenticated: false })).toEqual({
keyParams: {
@@ -87,7 +93,7 @@ describe('GetUserKeyParams', () => {
})
it('should get pseudo key params for a non existing user - when searching by email', async () => {
userRepository.findOneByEmail = jest.fn().mockReturnValue(null)
userRepository.findOneByUsernameOrEmail = jest.fn().mockReturnValue(null)
expect(await createUseCase().execute({ email: '[email protected]', authenticated: false })).toEqual({
keyParams: {
@@ -10,6 +10,7 @@ import { User } from '../../User/User'
import { PKCERepositoryInterface } from '../../User/PKCERepositoryInterface'
import { GetUserKeyParamsDTOV2Challenged } from './GetUserKeyParamsDTOV2Challenged'
import { KeyParamsData } from '@standardnotes/responses'
import { Username } from '@standardnotes/domain-core'
@injectable()
export class GetUserKeyParams implements UseCaseInterface {
@@ -33,7 +34,13 @@ export class GetUserKeyParams implements UseCaseInterface {
let user: User | null = null
if (dto.email !== undefined) {
user = await this.userRepository.findOneByEmail(dto.email)
const usernameOrError = Username.create(dto.email)
if (usernameOrError.isFailed()) {
throw Error(usernameOrError.getError())
}
const username = usernameOrError.getValue()
user = await this.userRepository.findOneByUsernameOrEmail(username)
if (!user) {
this.logger.debug(`No user with email ${dto.email}. Creating pseudo key params.`)