refactor: Remove randomString function

This was done because it was only a wrapper for a nodejs function to check if the given parameter is a positive number.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-05-16 22:41:01 +02:00 committed by David Mehren
parent 69a2a24511
commit 875e848b80
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 5 additions and 17 deletions

View file

@ -17,6 +17,7 @@ import { NotInDBError, TokenNotValidError } from '../errors/errors';
import { Repository } from 'typeorm';
import { ConfigModule } from '@nestjs/config';
import appConfigMock from '../config/mock/app.config.mock';
import { randomBytes } from 'crypto';
describe('AuthService', () => {
let service: AuthService;
@ -79,7 +80,7 @@ describe('AuthService', () => {
.then((result) => expect(result).toBeTruthy());
});
it('fails, if secret is too short', async () => {
const secret = service.bufferToBase64Url(service.randomString(54));
const secret = service.bufferToBase64Url(randomBytes(54));
const hash = await service.hashPassword(secret);
await service
.checkPassword(secret, hash)
@ -328,10 +329,4 @@ describe('AuthService', () => {
);
});
});
describe('randomString', () => {
it('throws on invalid lenght parameter', () => {
expect(() => service.randomString(0)).toThrow();
expect(() => service.randomString(-1)).toThrow();
});
});
});