diff --git a/src/auth/auth.service.spec.ts b/src/auth/auth.service.spec.ts index b79f7f0bf..ab13f1141 100644 --- a/src/auth/auth.service.spec.ts +++ b/src/auth/auth.service.spec.ts @@ -319,4 +319,10 @@ describe('AuthService', () => { ); }); }); + describe('randomString', () => { + it('throws on invalid lenght parameter', () => { + expect(() => service.randomString(0)).toThrow(); + expect(() => service.randomString(-1)).toThrow(); + }); + }); }); diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 76758e680..45fa70280 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -64,7 +64,7 @@ export class AuthService { randomString(length: number): Buffer { if (length <= 0) { - return null; + throw new Error('randomString cannot have a length < 1'); } return randomBytes(length); }