mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-21 18:55:19 -04:00
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:
parent
508ad26771
commit
e6dc8c7678
2 changed files with 37 additions and 12 deletions
|
@ -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());
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue