mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-17 08:34:54 -04:00
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:
parent
fd3fde9cc8
commit
552cb05d92
3 changed files with 24 additions and 7 deletions
|
@ -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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue