fix(server): validation events actually throwing an error (#8172)

* fix validation events

* add e2e test
This commit is contained in:
Daniel Dietzler 2024-03-21 23:59:21 +01:00 committed by GitHub
parent 508f32c08a
commit d6823b128c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 8 deletions

View file

@ -1,10 +1,12 @@
import { LoginResponseDto } from '@immich/sdk';
import { LoginResponseDto, getConfig } from '@immich/sdk';
import { createUserDto } from 'src/fixtures';
import { errorDto } from 'src/responses';
import { app, utils } from 'src/utils';
import { app, asBearerAuth, utils } from 'src/utils';
import request from 'supertest';
import { beforeAll, describe, expect, it } from 'vitest';
const getSystemConfig = (accessToken: string) => getConfig({ headers: asBearerAuth(accessToken) });
describe('/system-config', () => {
let admin: LoginResponseDto;
let nonAdmin: LoginResponseDto;
@ -60,4 +62,25 @@ describe('/system-config', () => {
expect(body).toEqual(expect.objectContaining({ id: 'immich-map-dark' }));
});
});
describe('PUT /system-config', () => {
it('should require authentication', async () => {
const { status, body } = await request(app).put('/system-config');
expect(status).toBe(401);
expect(body).toEqual(errorDto.unauthorized);
});
it('should reject an invalid config entry', async () => {
const { status, body } = await request(app)
.put('/system-config')
.set('Authorization', `Bearer ${admin.accessToken}`)
.send({
...(await getSystemConfig(admin.accessToken)),
storageTemplate: { enabled: true, hashVerificationEnabled: true, template: '{{foo}}' },
});
expect(status).toBe(400);
expect(body).toEqual(errorDto.badRequest(expect.stringContaining('Invalid storage template')));
});
});
});