From f8393eeebe9fd1b18cbc2862456815edeb3921d6 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Fri, 20 Dec 2024 10:10:24 -0500 Subject: [PATCH] fix: clearer error messaging --- api/src/unraid-api/auth/api-key.service.spec.ts | 2 +- api/src/unraid-api/auth/api-key.service.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/api/src/unraid-api/auth/api-key.service.spec.ts b/api/src/unraid-api/auth/api-key.service.spec.ts index d3d43599b..cffd670a9 100644 --- a/api/src/unraid-api/auth/api-key.service.spec.ts +++ b/api/src/unraid-api/auth/api-key.service.spec.ts @@ -154,7 +154,7 @@ describe('ApiKeyService', () => { const saveSpy = vi.spyOn(apiKeyService, 'saveApiKey'); await expect(apiKeyService.create('', 'desc', [Role.GUEST])).rejects.toThrow( - 'API key name must be alphanumeric + spaces' + 'API key name must contain only letters, numbers, and spaces (Unicode letters are supported)' ); await expect(apiKeyService.create('name', 'desc', [])).rejects.toThrow( diff --git a/api/src/unraid-api/auth/api-key.service.ts b/api/src/unraid-api/auth/api-key.service.ts index 302a8a631..0516bd01a 100644 --- a/api/src/unraid-api/auth/api-key.service.ts +++ b/api/src/unraid-api/auth/api-key.service.ts @@ -3,15 +3,23 @@ import crypto from 'crypto'; import { readdir, readFile, writeFile } from 'fs/promises'; import { join } from 'path'; + + import { ensureDir } from 'fs-extra'; import { GraphQLError } from 'graphql'; import { v4 as uuidv4 } from 'uuid'; import { ZodError } from 'zod'; + + import { ApiKeySchema, ApiKeyWithSecretSchema } from '@app/graphql/generated/api/operations'; import { ApiKey, ApiKeyWithSecret, Role, UserAccount } from '@app/graphql/generated/api/types'; import { getters } from '@app/store'; + + + + @Injectable() export class ApiKeyService implements OnModuleInit { private readonly logger = new Logger(ApiKeyService.name); @@ -47,7 +55,9 @@ export class ApiKeyService implements OnModuleInit { if (/^[\p{L}\p{N} ]+$/u.test(name)) { return name; } else { - throw new GraphQLError('API key name must be alphanumeric + spaces'); + throw new GraphQLError( + 'API key name must contain only letters, numbers, and spaces (Unicode letters are supported)' + ); } } @@ -298,4 +308,4 @@ export class ApiKeyService implements OnModuleInit { keyFile: this.keyFile, }; } -} +} \ No newline at end of file