From 55ee3a0b6bda7298c10f1c40cf23c8e5d419c013 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 21 Feb 2023 17:14:09 +0100 Subject: [PATCH 01/10] feat(backend): alias in update user info --- .../src/graphql/arg/UpdateUserInfosArgs.ts | 5 + .../src/graphql/resolver/UserResolver.test.ts | 123 ++++++++++++++++++ backend/src/graphql/resolver/UserResolver.ts | 18 +++ backend/src/seeds/graphql/mutations.ts | 2 + 4 files changed, 148 insertions(+) diff --git a/backend/src/graphql/arg/UpdateUserInfosArgs.ts b/backend/src/graphql/arg/UpdateUserInfosArgs.ts index b45539487..cde5f7732 100644 --- a/backend/src/graphql/arg/UpdateUserInfosArgs.ts +++ b/backend/src/graphql/arg/UpdateUserInfosArgs.ts @@ -1,4 +1,5 @@ import { ArgsType, Field } from 'type-graphql' +// import { Length } from 'class-validator' @ArgsType() export default class UpdateUserInfosArgs { @@ -8,6 +9,10 @@ export default class UpdateUserInfosArgs { @Field({ nullable: true }) lastName?: string + @Field({ nullable: true }) + // @Length(5, 20) + alias?: string + @Field({ nullable: true }) language?: string diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 19eb04b34..89042ebdc 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -1134,6 +1134,129 @@ describe('UserResolver', () => { }) }) + describe('alias', () => { + beforeEach(() => { + jest.clearAllMocks() + }) + + describe('too short', () => { + it('throws and logs an error', async () => { + await expect( + mutate({ + mutation: updateUserInfos, + variables: { + alias: 'bibi', + }, + }), + ).resolves.toMatchObject({ + errors: [new GraphQLError('Given alias is too short')], + data: null, + }) + expect(logger.error).toBeCalledWith('Given alias is too short', 'bibi') + }) + }) + + describe('too long', () => { + it('throws and logs an error', async () => { + await expect( + mutate({ + mutation: updateUserInfos, + variables: { + alias: 'bibis_alias_far_too_long', + }, + }), + ).resolves.toMatchObject({ + errors: [new GraphQLError('Given alias is too long')], + data: null, + }) + expect(logger.error).toBeCalledWith( + 'Given alias is too long', + 'bibis_alias_far_too_long', + ) + }) + }) + + describe('invalid characters', () => { + it('throws and logs an error', async () => { + await expect( + mutate({ + mutation: updateUserInfos, + variables: { + alias: 'no_underscore', + }, + }), + ).resolves.toMatchObject({ + errors: [new GraphQLError('Invalid characters in alias')], + data: null, + }) + expect(logger.error).toBeCalledWith('Invalid characters in alias', 'no_underscore') + }) + }) + + describe('alias exists', () => { + let peter: User + beforeAll(async () => { + peter = await userFactory(testEnv, peterLustig) + await mutate({ + mutation: login, + variables: { + email: 'peter@lustig.de', + password: 'Aa12345_', + }, + }) + await mutate({ + mutation: updateUserInfos, + variables: { + alias: 'bibiBloxberg', + }, + }) + await mutate({ + mutation: login, + variables: { + email: 'bibi@bloxberg.de', + password: 'Aa12345_', + }, + }) + }) + + afterAll(async () => { + const [user] = await User.find({ id: peter.id }) + await user.remove() + }) + + it('throws and logs an error', async () => { + await expect( + mutate({ + mutation: updateUserInfos, + variables: { + alias: 'bibiBloxberg', + }, + }), + ).resolves.toMatchObject({ + errors: [new GraphQLError('Alias already in use')], + data: null, + }) + expect(logger.error).toBeCalledWith('Alias already in use', 'bibiBloxberg') + }) + }) + + describe('valid alias', () => { + it('updates the user in DB', async () => { + await mutate({ + mutation: updateUserInfos, + variables: { + alias: 'bibiBloxberg', + }, + }) + await expect(User.findOne()).resolves.toEqual( + expect.objectContaining({ + alias: 'bibiBloxberg', + }), + ) + }) + }) + }) + describe('language is not valid', () => { it('throws an error', async () => { jest.clearAllMocks() diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index f9617b0df..0c7ca79cb 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -517,6 +517,7 @@ export class UserResolver { { firstName, lastName, + alias, language, password, passwordNew, @@ -536,6 +537,23 @@ export class UserResolver { userEntity.lastName = lastName } + if (alias) { + if (alias.length < 5) { + throw new LogError('Given alias is too short', alias) + } + if (alias.length > 20) { + throw new LogError('Given alias is too long', alias) + } + if (!alias.match(/^[0-9A-Za-z]+$/)) { + throw new LogError('Invalid characters in alias', alias) + } + const aliasInUse = await DbUser.find({ alias }) + if (aliasInUse.length !== 0) { + throw new LogError('Alias already in use', alias) + } + userEntity.alias = alias + } + if (language) { if (!isLanguage(language)) { throw new LogError('Given language is not a valid language', language) diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index 4f9cbdeff..e0141b752 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -28,6 +28,7 @@ export const updateUserInfos = gql` mutation ( $firstName: String $lastName: String + $alias: String $password: String $passwordNew: String $locale: String @@ -37,6 +38,7 @@ export const updateUserInfos = gql` updateUserInfos( firstName: $firstName lastName: $lastName + alias: $alias password: $password passwordNew: $passwordNew language: $locale From 22f77459aab73fd34f17793a4e0ecaf3da1e84a4 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 24 Feb 2023 14:03:12 +0100 Subject: [PATCH 02/10] remove class validator comments --- backend/src/graphql/arg/UpdateUserInfosArgs.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/graphql/arg/UpdateUserInfosArgs.ts b/backend/src/graphql/arg/UpdateUserInfosArgs.ts index cde5f7732..dbf68c43c 100644 --- a/backend/src/graphql/arg/UpdateUserInfosArgs.ts +++ b/backend/src/graphql/arg/UpdateUserInfosArgs.ts @@ -1,5 +1,4 @@ import { ArgsType, Field } from 'type-graphql' -// import { Length } from 'class-validator' @ArgsType() export default class UpdateUserInfosArgs { @@ -10,7 +9,6 @@ export default class UpdateUserInfosArgs { lastName?: string @Field({ nullable: true }) - // @Length(5, 20) alias?: string @Field({ nullable: true }) From 3afc7b08fa7264246862110c31a1b72de7c8b7db Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 24 Feb 2023 14:15:52 +0100 Subject: [PATCH 03/10] update regex --- backend/src/graphql/resolver/UserResolver.test.ts | 8 ++++---- backend/src/graphql/resolver/UserResolver.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 89042ebdc..bbfbd1ddc 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -1182,14 +1182,14 @@ describe('UserResolver', () => { mutate({ mutation: updateUserInfos, variables: { - alias: 'no_underscore', + alias: 'no+äöllll', }, }), ).resolves.toMatchObject({ errors: [new GraphQLError('Invalid characters in alias')], data: null, }) - expect(logger.error).toBeCalledWith('Invalid characters in alias', 'no_underscore') + expect(logger.error).toBeCalledWith('Invalid characters in alias', 'no+äöllll') }) }) @@ -1245,12 +1245,12 @@ describe('UserResolver', () => { await mutate({ mutation: updateUserInfos, variables: { - alias: 'bibiBloxberg', + alias: 'bibi_Bloxberg', }, }) await expect(User.findOne()).resolves.toEqual( expect.objectContaining({ - alias: 'bibiBloxberg', + alias: 'bibi_Bloxberg', }), ) }) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 0c7ca79cb..2a13ee037 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -544,7 +544,7 @@ export class UserResolver { if (alias.length > 20) { throw new LogError('Given alias is too long', alias) } - if (!alias.match(/^[0-9A-Za-z]+$/)) { + if (!alias.match(/^[0-9A-Za-z]([_-]?[A-Za-z0-9])+$/)) { throw new LogError('Invalid characters in alias', alias) } const aliasInUse = await DbUser.find({ alias }) From 19a980b47bb9cf219e2fca81bab6ad6e86465ac6 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Fri, 24 Feb 2023 14:16:41 +0100 Subject: [PATCH 04/10] Update backend/src/graphql/resolver/UserResolver.test.ts Co-authored-by: Ulf Gebhardt --- backend/src/graphql/resolver/UserResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index bbfbd1ddc..b6b24949b 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -1220,7 +1220,7 @@ describe('UserResolver', () => { }) afterAll(async () => { - const [user] = await User.find({ id: peter.id }) + const user = await User.findOne({ id: peter.id }) await user.remove() }) From b7ce0e277ccc04d0c673fba87d3aa6df09dd4eb9 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 9 May 2023 13:58:53 +0200 Subject: [PATCH 05/10] fix variable name --- backend/src/graphql/resolver/UserResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 3674f6602..7198a3bdc 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -538,7 +538,7 @@ export class UserResolver { if (aliasInUse.length !== 0) { throw new LogError('Alias already in use', alias) } - userEntity.alias = alias + user.alias = alias } if (language) { From a82f0cb2845d0d2649d8177b2e41265d52294a88 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 10 May 2023 17:37:01 +0200 Subject: [PATCH 06/10] separate validation function for alias, tested --- .../src/graphql/resolver/UserResolver.test.ts | 101 -------------- backend/src/graphql/resolver/UserResolver.ts | 15 +-- .../resolver/util/validateAlias.test.ts | 125 ++++++++++++++++++ .../graphql/resolver/util/validateAlias.ts | 36 +++++ 4 files changed, 163 insertions(+), 114 deletions(-) create mode 100644 backend/src/graphql/resolver/util/validateAlias.test.ts create mode 100644 backend/src/graphql/resolver/util/validateAlias.ts diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 8ebe3e7af..5e39ae2ff 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -1208,107 +1208,6 @@ describe('UserResolver', () => { jest.clearAllMocks() }) - describe('too short', () => { - it('throws and logs an error', async () => { - await expect( - mutate({ - mutation: updateUserInfos, - variables: { - alias: 'bibi', - }, - }), - ).resolves.toMatchObject({ - errors: [new GraphQLError('Given alias is too short')], - data: null, - }) - expect(logger.error).toBeCalledWith('Given alias is too short', 'bibi') - }) - }) - - describe('too long', () => { - it('throws and logs an error', async () => { - await expect( - mutate({ - mutation: updateUserInfos, - variables: { - alias: 'bibis_alias_far_too_long', - }, - }), - ).resolves.toMatchObject({ - errors: [new GraphQLError('Given alias is too long')], - data: null, - }) - expect(logger.error).toBeCalledWith( - 'Given alias is too long', - 'bibis_alias_far_too_long', - ) - }) - }) - - describe('invalid characters', () => { - it('throws and logs an error', async () => { - await expect( - mutate({ - mutation: updateUserInfos, - variables: { - alias: 'no+äöllll', - }, - }), - ).resolves.toMatchObject({ - errors: [new GraphQLError('Invalid characters in alias')], - data: null, - }) - expect(logger.error).toBeCalledWith('Invalid characters in alias', 'no+äöllll') - }) - }) - - describe('alias exists', () => { - let peter: User - beforeAll(async () => { - peter = await userFactory(testEnv, peterLustig) - await mutate({ - mutation: login, - variables: { - email: 'peter@lustig.de', - password: 'Aa12345_', - }, - }) - await mutate({ - mutation: updateUserInfos, - variables: { - alias: 'bibiBloxberg', - }, - }) - await mutate({ - mutation: login, - variables: { - email: 'bibi@bloxberg.de', - password: 'Aa12345_', - }, - }) - }) - - afterAll(async () => { - const user = await User.findOne({ id: peter.id }) - await user.remove() - }) - - it('throws and logs an error', async () => { - await expect( - mutate({ - mutation: updateUserInfos, - variables: { - alias: 'bibiBloxberg', - }, - }), - ).resolves.toMatchObject({ - errors: [new GraphQLError('Alias already in use')], - data: null, - }) - expect(logger.error).toBeCalledWith('Alias already in use', 'bibiBloxberg') - }) - }) - describe('valid alias', () => { it('updates the user in DB', async () => { await mutate({ diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 7198a3bdc..6b4844154 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -73,6 +73,7 @@ import { getTimeDurationObject, printTimeDuration } from '@/util/time' import { FULL_CREATION_AVAILABLE } from './const/const' import { getUserCreations } from './util/creations' import { findUserByIdentifier } from './util/findUserByIdentifier' +import { validateAlias } from './util/validateAlias' // eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs const random = require('random-bigint') @@ -525,19 +526,7 @@ export class UserResolver { } if (alias) { - if (alias.length < 5) { - throw new LogError('Given alias is too short', alias) - } - if (alias.length > 20) { - throw new LogError('Given alias is too long', alias) - } - if (!alias.match(/^[0-9A-Za-z]([_-]?[A-Za-z0-9])+$/)) { - throw new LogError('Invalid characters in alias', alias) - } - const aliasInUse = await DbUser.find({ alias }) - if (aliasInUse.length !== 0) { - throw new LogError('Alias already in use', alias) - } + await validateAlias(alias) user.alias = alias } diff --git a/backend/src/graphql/resolver/util/validateAlias.test.ts b/backend/src/graphql/resolver/util/validateAlias.test.ts new file mode 100644 index 000000000..733a09ffe --- /dev/null +++ b/backend/src/graphql/resolver/util/validateAlias.test.ts @@ -0,0 +1,125 @@ +import { Connection } from '@dbTools/typeorm' +import { User } from '@entity/User' +import { ApolloServerTestClient } from 'apollo-server-testing' + +import { testEnvironment, cleanDB } from '@test/helpers' +import { logger, i18n as localization } from '@test/testSetup' + +import { userFactory } from '@/seeds/factory/user' +import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' + +import { validateAlias } from './validateAlias' + +let con: Connection +let testEnv: { + mutate: ApolloServerTestClient['mutate'] + query: ApolloServerTestClient['query'] + con: Connection +} + +beforeAll(async () => { + testEnv = await testEnvironment(logger, localization) + con = testEnv.con + await cleanDB() +}) + +afterAll(async () => { + await cleanDB() + await con.close() +}) + +describe('validate alias', () => { + beforeAll(() => { + jest.clearAllMocks() + }) + + describe('alias too short', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('Bi')).rejects.toEqual(new Error('Given alias is too short')) + expect(logger.error).toBeCalledWith('Given alias is too short', 'Bi') + }) + }) + + describe('alias too long', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('BibiBloxbergHexHexHex')).rejects.toEqual( + new Error('Given alias is too long'), + ) + expect(logger.error).toBeCalledWith('Given alias is too long', 'BibiBloxbergHexHexHex') + }) + }) + + describe('alias contains invalid characters', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('Bibi.Bloxberg')).rejects.toEqual( + new Error('Invalid characters in alias'), + ) + expect(logger.error).toBeCalledWith('Invalid characters in alias', 'Bibi.Bloxberg') + }) + }) + + describe('alias is a reserved word', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('admin')).rejects.toEqual(new Error('Alias is not allowed')) + expect(logger.error).toBeCalledWith('Alias is not allowed', 'admin') + }) + }) + + describe('alias is a reserved word with uppercase characters', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('Admin')).rejects.toEqual(new Error('Alias is not allowed')) + expect(logger.error).toBeCalledWith('Alias is not allowed', 'Admin') + }) + }) + + describe('hyphens and underscore', () => { + describe('alias starts with underscore', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('_bibi')).rejects.toEqual( + new Error('Invalid characters in alias'), + ) + expect(logger.error).toBeCalledWith('Invalid characters in alias', '_bibi') + }) + }) + + describe('alias contains two following hyphens', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('bi--bi')).rejects.toEqual( + new Error('Invalid characters in alias'), + ) + expect(logger.error).toBeCalledWith('Invalid characters in alias', 'bi--bi') + }) + }) + }) + + describe('test against existing alias in database', () => { + beforeAll(async () => { + const bibi = await userFactory(testEnv, bibiBloxberg) + const user = await User.findOne({ id: bibi.id }) + if (user) { + user.alias = 'b-b' + await user.save() + } + }) + + describe('alias exists in database', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('b-b')).rejects.toEqual(new Error('Alias already in use')) + expect(logger.error).toBeCalledWith('Alias already in use', 'b-b') + }) + }) + + describe('alias exists in database with in lower-case', () => { + it('throws and logs an error', async () => { + await expect(validateAlias('b-B')).rejects.toEqual(new Error('Alias already in use')) + expect(logger.error).toBeCalledWith('Alias already in use', 'b-B') + }) + }) + + describe('valid alias', () => { + it('resolves to void', async () => { + await expect(validateAlias('bibi')).resolves.toEqual(undefined) + }) + }) + }) +}) diff --git a/backend/src/graphql/resolver/util/validateAlias.ts b/backend/src/graphql/resolver/util/validateAlias.ts new file mode 100644 index 000000000..d35b9e363 --- /dev/null +++ b/backend/src/graphql/resolver/util/validateAlias.ts @@ -0,0 +1,36 @@ +import { Raw } from '@dbTools/typeorm' +import { User as DbUser } from '@entity/User' + +import { LogError } from '@/server/LogError' + +const reservedAlias = [ + 'admin', + 'email', + 'gast', + 'gdd', + 'gradido', + 'guest', + 'home', + 'root', + 'support', + 'temp', + 'tmp', + 'tmp', + 'user', + 'usr', + 'var', +] + +export const validateAlias = async (alias: string): Promise => { + if (alias.length < 3) throw new LogError('Given alias is too short', alias) + if (alias.length > 20) throw new LogError('Given alias is too long', alias) + if (!alias.match(/^[0-9A-Za-z]([_-]?[A-Za-z0-9])+$/)) + throw new LogError('Invalid characters in alias', alias) + if (reservedAlias.includes(alias.toLowerCase())) throw new LogError('Alias is not allowed', alias) + const aliasInUse = await DbUser.find({ + where: { alias: Raw((a) => `LOWER(${a}) = "${alias.toLowerCase()}"`) }, + }) + if (aliasInUse.length !== 0) { + throw new LogError('Alias already in use', alias) + } +} From c78691c87c3e9ea2df0ee145993c70485b5948b1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 10 May 2023 18:00:29 +0200 Subject: [PATCH 07/10] ignore unsage regex lint --- backend/src/graphql/resolver/util/validateAlias.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/graphql/resolver/util/validateAlias.ts b/backend/src/graphql/resolver/util/validateAlias.ts index d35b9e363..8528bf617 100644 --- a/backend/src/graphql/resolver/util/validateAlias.ts +++ b/backend/src/graphql/resolver/util/validateAlias.ts @@ -24,6 +24,7 @@ const reservedAlias = [ export const validateAlias = async (alias: string): Promise => { if (alias.length < 3) throw new LogError('Given alias is too short', alias) if (alias.length > 20) throw new LogError('Given alias is too long', alias) + /* eslint-disable-next-line security/detect-unsafe-regex */ if (!alias.match(/^[0-9A-Za-z]([_-]?[A-Za-z0-9])+$/)) throw new LogError('Invalid characters in alias', alias) if (reservedAlias.includes(alias.toLowerCase())) throw new LogError('Alias is not allowed', alias) From dbe752563be36565b39de1cc812fcaa9c4246a30 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 10 May 2023 18:39:41 +0200 Subject: [PATCH 08/10] Update backend/src/graphql/resolver/util/validateAlias.ts Co-authored-by: Ulf Gebhardt --- backend/src/graphql/resolver/util/validateAlias.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/util/validateAlias.ts b/backend/src/graphql/resolver/util/validateAlias.ts index 8528bf617..dcea7824c 100644 --- a/backend/src/graphql/resolver/util/validateAlias.ts +++ b/backend/src/graphql/resolver/util/validateAlias.ts @@ -21,7 +21,7 @@ const reservedAlias = [ 'var', ] -export const validateAlias = async (alias: string): Promise => { +export const validateAlias = async (alias: string): Promise => { if (alias.length < 3) throw new LogError('Given alias is too short', alias) if (alias.length > 20) throw new LogError('Given alias is too long', alias) /* eslint-disable-next-line security/detect-unsafe-regex */ @@ -34,4 +34,5 @@ export const validateAlias = async (alias: string): Promise => { if (aliasInUse.length !== 0) { throw new LogError('Alias already in use', alias) } + return true } From 1c924900199feeb4482e1a338aa1d6c4ceeecfd1 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 10 May 2023 18:39:52 +0200 Subject: [PATCH 09/10] Update backend/src/graphql/resolver/UserResolver.ts Co-authored-by: Ulf Gebhardt --- backend/src/graphql/resolver/UserResolver.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index bbd33f3ab..cc712e308 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -525,8 +525,7 @@ export class UserResolver { user.lastName = lastName } - if (alias) { - await validateAlias(alias) + if (alias && await validateAlias(alias)) { user.alias = alias } From d94543c1d9811e13fe84c315163d759dc6a9ead5 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 10 May 2023 20:47:28 +0200 Subject: [PATCH 10/10] fixes after merging suggestions --- backend/src/graphql/resolver/UserResolver.ts | 2 +- backend/src/graphql/resolver/util/validateAlias.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index cc712e308..0afbfcc5a 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -525,7 +525,7 @@ export class UserResolver { user.lastName = lastName } - if (alias && await validateAlias(alias)) { + if (alias && (await validateAlias(alias))) { user.alias = alias } diff --git a/backend/src/graphql/resolver/util/validateAlias.test.ts b/backend/src/graphql/resolver/util/validateAlias.test.ts index 733a09ffe..0cb790edb 100644 --- a/backend/src/graphql/resolver/util/validateAlias.test.ts +++ b/backend/src/graphql/resolver/util/validateAlias.test.ts @@ -117,8 +117,8 @@ describe('validate alias', () => { }) describe('valid alias', () => { - it('resolves to void', async () => { - await expect(validateAlias('bibi')).resolves.toEqual(undefined) + it('resolves to true', async () => { + await expect(validateAlias('bibi')).resolves.toEqual(true) }) }) })