mirror of
https://github.com/immich-app/immich.git
synced 2025-12-26 01:11:47 +03:00
feat: migration api keys to use kysely (#15206)
This commit is contained in:
@@ -49,10 +49,7 @@ describe(APIKeyService.name, () => {
|
||||
|
||||
it('should throw an error if the api key does not have sufficient permissions', async () => {
|
||||
await expect(
|
||||
sut.create(
|
||||
{ ...authStub.admin, apiKey: { ...keyStub.admin, permissions: [] } },
|
||||
{ permissions: [Permission.ASSET_READ] },
|
||||
),
|
||||
sut.create({ ...authStub.admin, apiKey: keyStub.authKey }, { permissions: [Permission.ASSET_READ] }),
|
||||
).rejects.toBeInstanceOf(BadRequestException);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -405,7 +405,7 @@ describe('AuthService', () => {
|
||||
|
||||
describe('validate - api key', () => {
|
||||
it('should throw an error if no api key is found', async () => {
|
||||
keyMock.getKey.mockResolvedValue(null);
|
||||
keyMock.getKey.mockResolvedValue(void 0);
|
||||
await expect(
|
||||
sut.authenticate({
|
||||
headers: { 'x-api-key': 'auth_token' },
|
||||
@@ -417,7 +417,7 @@ describe('AuthService', () => {
|
||||
});
|
||||
|
||||
it('should throw an error if api key has insufficient permissions', async () => {
|
||||
keyMock.getKey.mockResolvedValue({ ...keyStub.admin, permissions: [] });
|
||||
keyMock.getKey.mockResolvedValue(keyStub.authKey);
|
||||
await expect(
|
||||
sut.authenticate({
|
||||
headers: { 'x-api-key': 'auth_token' },
|
||||
@@ -428,14 +428,14 @@ describe('AuthService', () => {
|
||||
});
|
||||
|
||||
it('should return an auth dto', async () => {
|
||||
keyMock.getKey.mockResolvedValue(keyStub.admin);
|
||||
keyMock.getKey.mockResolvedValue(keyStub.authKey);
|
||||
await expect(
|
||||
sut.authenticate({
|
||||
headers: { 'x-api-key': 'auth_token' },
|
||||
queryParams: {},
|
||||
metadata: { adminRoute: false, sharedLinkRoute: false, uri: 'test' },
|
||||
}),
|
||||
).resolves.toEqual({ user: userStub.admin, apiKey: keyStub.admin });
|
||||
).resolves.toEqual({ user: userStub.admin, apiKey: keyStub.authKey });
|
||||
expect(keyMock.getKey).toHaveBeenCalledWith('auth_token (hashed)');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -308,7 +308,7 @@ export class AuthService extends BaseService {
|
||||
private async validateApiKey(key: string): Promise<AuthDto> {
|
||||
const hashedKey = this.cryptoRepository.hashSha256(key);
|
||||
const apiKey = await this.keyRepository.getKey(hashedKey);
|
||||
if (apiKey?.user) {
|
||||
if (apiKey) {
|
||||
return { user: apiKey.user, apiKey };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user