diff --git a/federation/src/graphql/api/1_0/resolver/AuthenticationResolver.ts b/federation/src/graphql/api/1_0/resolver/AuthenticationResolver.ts index 3c62c7bef..4c14360e9 100644 --- a/federation/src/graphql/api/1_0/resolver/AuthenticationResolver.ts +++ b/federation/src/graphql/api/1_0/resolver/AuthenticationResolver.ts @@ -109,7 +109,7 @@ export class AuthenticationResolver { } } - @Mutation(() => String) + @Mutation(() => String, { nullable: true }) async authenticate( @Arg('data') args: EncryptedTransferArgs, @@ -125,7 +125,7 @@ export class AuthenticationResolver { // no infos to the caller return null } - if (!uint32Schema.safeParse(authArgs.oneTimeCode).success) { + if (!uint32Schema.safeParse(Number(authArgs.oneTimeCode)).success) { const errmsg = `invalid oneTimeCode: ${authArgs.oneTimeCode} for community with publicKey ${authArgs.publicKey}, expect uint32` methodLogger.error(errmsg) // no infos to the caller diff --git a/shared/src/schema/base.schema.test.ts b/shared/src/schema/base.schema.test.ts index 3e56a9a22..d12f2a3b4 100644 --- a/shared/src/schema/base.schema.test.ts +++ b/shared/src/schema/base.schema.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'bun:test' -import { uuidv4Schema } from './base.schema' +import { uuidv4Schema, uint32Schema } from './base.schema' import { v4 as uuidv4 } from 'uuid' describe('uuidv4 schema', () => { @@ -10,3 +10,15 @@ describe('uuidv4 schema', () => { } }) }) + +describe('uint32 schema', () => { + it('should validate uint32 (40x)', () => { + for (let i = 0; i < 40; i++) { + const uint32 = Math.floor(Math.random() * 4294967295) + expect(uint32Schema.safeParse(uint32).success).toBeTruthy() + } + }) + it('should validate 2092352810', () => { + expect(uint32Schema.safeParse(2092352810).success).toBeTruthy() + }) +})