mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 18:25:21 -04:00
wip: refactoring to knex and general chores, starting with User
Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
6e151c8a1b
commit
7adce05412
198 changed files with 3865 additions and 5899 deletions
|
@ -104,13 +104,13 @@ describe('ApiTokenService', () => {
|
|||
describe('getTokensByUser', () => {
|
||||
it('works', async () => {
|
||||
createQueryBuilderFunc.getMany = () => [apiToken];
|
||||
const tokens = await service.getTokensByUser(user);
|
||||
const tokens = await service.getTokensOfUserById(user);
|
||||
expect(tokens).toHaveLength(1);
|
||||
expect(tokens).toEqual([apiToken]);
|
||||
});
|
||||
it('should return empty array if token for user do not exists', async () => {
|
||||
jest.spyOn(apiTokenRepo, 'find').mockImplementationOnce(async () => []);
|
||||
const tokens = await service.getTokensByUser(user);
|
||||
const tokens = await service.getTokensOfUserById(user);
|
||||
expect(tokens).toHaveLength(0);
|
||||
expect(tokens).toEqual([]);
|
||||
});
|
||||
|
@ -153,13 +153,13 @@ describe('ApiTokenService', () => {
|
|||
);
|
||||
|
||||
expect(() =>
|
||||
service.checkToken(secret, accessToken as ApiToken),
|
||||
service.ensureTokenIsValid(secret, accessToken as ApiToken),
|
||||
).not.toThrow();
|
||||
});
|
||||
it('AuthToken has wrong hash', () => {
|
||||
const [accessToken] = service.createToken(user, 'TestToken', null);
|
||||
expect(() =>
|
||||
service.checkToken('secret', accessToken as ApiToken),
|
||||
service.ensureTokenIsValid('secret', accessToken as ApiToken),
|
||||
).toThrow(TokenNotValidError);
|
||||
});
|
||||
it('AuthToken has wrong validUntil Date', () => {
|
||||
|
@ -168,9 +168,9 @@ describe('ApiTokenService', () => {
|
|||
'Test',
|
||||
new Date(1549312452000),
|
||||
);
|
||||
expect(() => service.checkToken(secret, accessToken as ApiToken)).toThrow(
|
||||
TokenNotValidError,
|
||||
);
|
||||
expect(() =>
|
||||
service.ensureTokenIsValid(secret, accessToken as ApiToken),
|
||||
).toThrow(TokenNotValidError);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -222,7 +222,7 @@ describe('ApiTokenService', () => {
|
|||
.mockImplementationOnce(async (_, __): Promise<ApiToken> => {
|
||||
return apiToken;
|
||||
});
|
||||
const userByToken = await service.validateToken(
|
||||
const userByToken = await service.getUserIdForToken(
|
||||
`hd2.${apiToken.keyId}.${testSecret}`,
|
||||
);
|
||||
expect(userByToken).toEqual({
|
||||
|
@ -233,27 +233,27 @@ describe('ApiTokenService', () => {
|
|||
describe('fails:', () => {
|
||||
it('the prefix is missing', async () => {
|
||||
await expect(
|
||||
service.validateToken(`${apiToken.keyId}.${'a'.repeat(73)}`),
|
||||
service.getUserIdForToken(`${apiToken.keyId}.${'a'.repeat(73)}`),
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
it('the prefix is wrong', async () => {
|
||||
await expect(
|
||||
service.validateToken(`hd1.${apiToken.keyId}.${'a'.repeat(73)}`),
|
||||
service.getUserIdForToken(`hd1.${apiToken.keyId}.${'a'.repeat(73)}`),
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
it('the secret is missing', async () => {
|
||||
await expect(
|
||||
service.validateToken(`hd2.${apiToken.keyId}`),
|
||||
service.getUserIdForToken(`hd2.${apiToken.keyId}`),
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
it('the secret is too long', async () => {
|
||||
await expect(
|
||||
service.validateToken(`hd2.${apiToken.keyId}.${'a'.repeat(73)}`),
|
||||
service.getUserIdForToken(`hd2.${apiToken.keyId}.${'a'.repeat(73)}`),
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
});
|
||||
it('the token contains sections after the secret', async () => {
|
||||
await expect(
|
||||
service.validateToken(
|
||||
service.getUserIdForToken(
|
||||
`hd2.${apiToken.keyId}.${'a'.repeat(73)}.extra`,
|
||||
),
|
||||
).rejects.toThrow(TokenNotValidError);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue