mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-05 02:36:04 +00:00
refactor(auth-token): rename lastUsed to lastUsedAt
This is part of an effort to name all date attributes consistently. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
b98944aeb0
commit
c7dd942c1f
5 changed files with 16 additions and 16 deletions
|
@ -16,5 +16,5 @@ export class AuthTokenDto {
|
|||
validUntil: Date;
|
||||
@IsDate()
|
||||
@IsOptional()
|
||||
lastUsed: Date | null;
|
||||
lastUsedAt: Date | null;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ export class AuthToken {
|
|||
nullable: true,
|
||||
type: 'date',
|
||||
})
|
||||
lastUsed: Date | null;
|
||||
lastUsedAt: Date | null;
|
||||
|
||||
public static create(
|
||||
keyId: string,
|
||||
|
@ -57,7 +57,7 @@ export class AuthToken {
|
|||
newToken.label = label;
|
||||
newToken.accessTokenHash = accessToken;
|
||||
newToken.validUntil = validUntil;
|
||||
newToken.lastUsed = null;
|
||||
newToken.lastUsedAt = null;
|
||||
return newToken;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,14 +143,14 @@ describe('AuthService', () => {
|
|||
jest.spyOn(authTokenRepo, 'findOne').mockResolvedValueOnce({
|
||||
...authToken,
|
||||
user: Promise.resolve(user),
|
||||
lastUsed: new Date(1549312452000),
|
||||
lastUsedAt: new Date(1549312452000),
|
||||
});
|
||||
jest
|
||||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.keyId).toEqual(authToken.keyId);
|
||||
expect(authTokenSaved.lastUsed).not.toEqual(1549312452000);
|
||||
expect(authTokenSaved.lastUsedAt).not.toEqual(1549312452000);
|
||||
return authToken;
|
||||
},
|
||||
);
|
||||
|
@ -242,7 +242,7 @@ describe('AuthService', () => {
|
|||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
expect(authTokenSaved.lastUsedAt).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
|
@ -252,7 +252,7 @@ describe('AuthService', () => {
|
|||
token.validUntil.getTime() -
|
||||
(new Date().getTime() + 2 * 365 * 24 * 60 * 60 * 1000),
|
||||
).toBeLessThanOrEqual(10000);
|
||||
expect(token.lastUsed).toBeNull();
|
||||
expect(token.lastUsedAt).toBeNull();
|
||||
expect(token.secret.startsWith(token.keyId)).toBeTruthy();
|
||||
});
|
||||
it('with validUntil not 0', async () => {
|
||||
|
@ -261,7 +261,7 @@ describe('AuthService', () => {
|
|||
.spyOn(authTokenRepo, 'save')
|
||||
.mockImplementationOnce(
|
||||
async (authTokenSaved: AuthToken, _): Promise<AuthToken> => {
|
||||
expect(authTokenSaved.lastUsed).toBeNull();
|
||||
expect(authTokenSaved.lastUsedAt).toBeNull();
|
||||
return authTokenSaved;
|
||||
},
|
||||
);
|
||||
|
@ -273,7 +273,7 @@ describe('AuthService', () => {
|
|||
);
|
||||
expect(token.label).toEqual(identifier);
|
||||
expect(token.validUntil.getTime()).toEqual(validUntil);
|
||||
expect(token.lastUsed).toBeNull();
|
||||
expect(token.lastUsedAt).toBeNull();
|
||||
expect(token.secret.startsWith(token.keyId)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
@ -290,7 +290,7 @@ describe('AuthService', () => {
|
|||
authToken.validUntil = new Date();
|
||||
const tokenDto = service.toAuthTokenDto(authToken);
|
||||
expect(tokenDto.keyId).toEqual(authToken.keyId);
|
||||
expect(tokenDto.lastUsed).toBeNull();
|
||||
expect(tokenDto.lastUsedAt).toBeNull();
|
||||
expect(tokenDto.label).toEqual(authToken.label);
|
||||
expect(tokenDto.validUntil.getTime()).toEqual(
|
||||
authToken.validUntil.getTime(),
|
||||
|
|
|
@ -108,7 +108,7 @@ export class AuthService {
|
|||
if (accessToken === undefined) {
|
||||
throw new NotInDBError(`AuthToken for key '${keyId}' not found`);
|
||||
}
|
||||
accessToken.lastUsed = new Date();
|
||||
accessToken.lastUsedAt = new Date();
|
||||
await this.authTokenRepository.save(accessToken);
|
||||
}
|
||||
|
||||
|
@ -175,11 +175,11 @@ export class AuthService {
|
|||
keyId: authToken.keyId,
|
||||
createdAt: authToken.createdAt,
|
||||
validUntil: authToken.validUntil,
|
||||
lastUsed: null,
|
||||
lastUsedAt: null,
|
||||
};
|
||||
|
||||
if (authToken.lastUsed) {
|
||||
tokenDto.lastUsed = new Date(authToken.lastUsed);
|
||||
if (authToken.lastUsedAt) {
|
||||
tokenDto.lastUsedAt = new Date(authToken.lastUsedAt);
|
||||
}
|
||||
|
||||
return tokenDto;
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('Tokens', () => {
|
|||
keyId = response.body.keyId;
|
||||
expect(response.body.label).toBe(tokenName);
|
||||
expect(response.body.validUntil).toBe(null);
|
||||
expect(response.body.lastUsed).toBe(null);
|
||||
expect(response.body.lastUsedAt).toBe(null);
|
||||
expect(response.body.secret.length).toBe(98);
|
||||
});
|
||||
|
||||
|
@ -59,7 +59,7 @@ describe('Tokens', () => {
|
|||
.expect(200);
|
||||
expect(response.body[0].label).toBe(tokenName);
|
||||
expect(response.body[0].validUntil).toBe(null);
|
||||
expect(response.body[0].lastUsed).toBe(null);
|
||||
expect(response.body[0].lastUsedAt).toBe(null);
|
||||
expect(response.body[0].secret).not.toBeDefined();
|
||||
});
|
||||
it(`DELETE /tokens/:keyid`, async () => {
|
||||
|
|
Loading…
Reference in a new issue