refactor(api/private/tokens): validate POST data with DTO

This adds a `AuthTokenCreateDto` which allows
to fully validate incoming JSON data.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-03-04 18:01:45 +01:00
parent fd3fde9cc8
commit 552cb05d92
3 changed files with 24 additions and 7 deletions

View file

@ -45,12 +45,15 @@ describe('Tokens', () => {
.post('/api/private/tokens')
.send({
label: tokenName,
validUntil: 0,
})
.expect('Content-Type', /json/)
.expect(201);
keyId = response.body.keyId;
expect(response.body.label).toBe(tokenName);
expect(response.body.validUntil).toBe(null);
expect(new Date(response.body.validUntil).getTime()).toBeGreaterThan(
Date.now(),
);
expect(response.body.lastUsedAt).toBe(null);
expect(response.body.secret.length).toBe(98);
});
@ -62,7 +65,9 @@ describe('Tokens', () => {
.expect('Content-Type', /json/)
.expect(200);
expect(response.body[0].label).toBe(tokenName);
expect(response.body[0].validUntil).toBe(null);
expect(new Date(response.body[0].validUntil).getTime()).toBeGreaterThan(
Date.now(),
);
expect(response.body[0].lastUsedAt).toBe(null);
expect(response.body[0].secret).not.toBeDefined();
});