refactor(server): env validation (#13817)

This commit is contained in:
Jason Rasmussen
2024-10-30 05:00:41 -04:00
committed by GitHub
parent 19eb3ed8b9
commit 0f668fd5c6
8 changed files with 305 additions and 149 deletions

View File

@@ -8,6 +8,7 @@ const getEnv = () => {
const resetEnv = () => {
for (const env of [
'IMMICH_ENV',
'IMMICH_WORKERS_INCLUDE',
'IMMICH_WORKERS_EXCLUDE',
'IMMICH_TRUSTED_PROXIES',
@@ -62,6 +63,18 @@ describe('getEnv', () => {
resetEnv();
});
it('should use defaults', () => {
const config = getEnv();
expect(config).toMatchObject({
host: undefined,
port: 2283,
environment: 'production',
configFile: undefined,
logLevel: undefined,
});
});
describe('database', () => {
it('should use defaults', () => {
const { database } = getEnv();
@@ -202,6 +215,11 @@ describe('getEnv', () => {
trustedProxies: ['10.1.0.0', '10.2.0.0', '169.254.0.0/16'],
});
});
it('should reject invalid trusted proxies', () => {
process.env.IMMICH_TRUSTED_PROXIES = '10.1';
expect(() => getEnv()).toThrowError('Invalid environment variables: IMMICH_TRUSTED_PROXIES');
});
});
describe('telemetry', () => {