mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
validate and version from uuid
This commit is contained in:
parent
9c84ca185d
commit
be978184c7
@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@ -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<DbUser | null> => {
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user