diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 0c4f94330..2c52963f0 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -6,6 +6,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { v4 as uuidv4, validate as validateUUID, version as versionUUID } from 'uuid' import { objectValuesToArray } from '@/util/utilities' import { testEnvironment, headerPushMock, resetToken, cleanDB } from '@test/helpers' import { logger, i18n as localization } from '@test/testSetup' @@ -47,7 +48,6 @@ import { ContributionLink } from '@model/ContributionLink' import { TransactionLink } from '@entity/TransactionLink' import { EventType } from '@/event/Event' import { Event as DbEvent } from '@entity/Event' -import { validate as validateUUID, version as versionUUID } from 'uuid' import { peterLustig } from '@/seeds/users/peter-lustig' import { UserContact } from '@entity/UserContact' import { OptInType } from '../enum/OptInType' @@ -2230,6 +2230,8 @@ describe('UserResolver', () => { }) describe('authenticated', () => { + const uuid = uuidv4() + beforeAll(async () => { user = await userFactory(testEnv, bibiBloxberg) await mutate({ @@ -2262,7 +2264,7 @@ describe('UserResolver', () => { query({ query: userQuery, variables: { - identifier: '00000000-0000-0000-0000-000000000000', + identifier: uuid, }, }), ).resolves.toEqual( @@ -2270,10 +2272,7 @@ describe('UserResolver', () => { errors: [new GraphQLError('No user found to given identifier')], }), ) - expect(logger.error).toBeCalledWith( - 'No user found to given identifier', - '00000000-0000-0000-0000-000000000000', - ) + expect(logger.error).toBeCalledWith('No user found to given identifier', uuid) }) }) diff --git a/backend/src/graphql/resolver/util/findUserByIdentifier.ts b/backend/src/graphql/resolver/util/findUserByIdentifier.ts index 8643bce72..e5907552e 100644 --- a/backend/src/graphql/resolver/util/findUserByIdentifier.ts +++ b/backend/src/graphql/resolver/util/findUserByIdentifier.ts @@ -1,12 +1,11 @@ import { User as DbUser } from '@entity/User' import { UserContact as DbUserContact } from '@entity/UserContact' import LogError from '@/server/LogError' +import { validate, version } from 'uuid' export const findUserByIdentifier = async (identifier: string): Promise => { let user: DbUser | undefined - if ( - /^[0-9a-f]{8,8}-[0-9a-f]{4,4}-[0-9a-f]{4,4}-[0-9a-f]{4,4}-[0-9a-f]{12,12}$/.exec(identifier) - ) { + if (validate(identifier) && version(identifier) === 4) { user = await DbUser.findOne({ where: { gradidoID: identifier }, relations: ['emailContact'] }) if (!user) { throw new LogError('No user found to given identifier', identifier)