auth: Split randomBase64UrlString in two functions

add test for BufferToBase64Url and toAuthTokenDto

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-01-23 19:04:00 +01:00 committed by David Mehren
parent 508ad26771
commit e6dc8c7678
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 37 additions and 12 deletions

View file

@ -112,7 +112,7 @@ describe('AuthService', () => {
it('getAuthToken', async () => {
const token = 'testToken';
authToken.accessTokenHash = await service.hashPassword(token);
const authTokenFromCall = await service.getAuthToken(
const authTokenFromCall = await service.getAuthTokenAndValidate(
authToken.keyId,
token,
);
@ -154,4 +154,19 @@ describe('AuthService', () => {
expect(token.lastUsed).toBeUndefined();
expect(token.secret.startsWith(token.keyId)).toBeTruthy();
});
it('BufferToBase64Url', () => {
expect(
service.BufferToBase64Url(Buffer.from('testsentence is a test sentence')),
).toEqual('dGVzdHNlbnRlbmNlIGlzIGEgdGVzdCBzZW50ZW5jZQ');
});
it('toAuthTokenDto', async () => {
const tokenDto = await service.toAuthTokenDto(authToken);
expect(tokenDto.keyId).toEqual(authToken.keyId);
expect(tokenDto.lastUsed).toBeNull();
expect(tokenDto.label).toEqual(authToken.identifier);
expect(tokenDto.validUntil).toBeNull();
expect(tokenDto.created).toEqual(authToken.createdAt.getTime());
});
});