mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2026-08-07 07:14:49 +00:00
fix(tests): check for process.exit in tests
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
committed by
Philip Molares
parent
3324bf1b2f
commit
33ae5c6e21
@@ -62,7 +62,7 @@ describe('AliasService', () => {
|
||||
}).compile();
|
||||
|
||||
const config = module.get<ConfigService>(ConfigService);
|
||||
forbiddenNoteId = config.get('noteConfig').forbiddenNoteIds[0];
|
||||
forbiddenNoteId = config.get('noteConfig').forbiddenAliases[0];
|
||||
service = module.get<AliasService>(AliasService);
|
||||
});
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('appConfig', () => {
|
||||
expect(config.baseUrl).toEqual(baseUrl);
|
||||
expect(config.rendererBaseUrl).toEqual(rendererBaseUrl);
|
||||
expect(config.backendPort).toEqual(port);
|
||||
expect(config.log.level).toEqual(Loglevel.WARN);
|
||||
expect(config.log.level).toEqual(Loglevel.INFO);
|
||||
expect(config.log.showTimestamp).toEqual(showLogTimestamp);
|
||||
restore();
|
||||
});
|
||||
@@ -139,7 +139,27 @@ describe('appConfig', () => {
|
||||
restore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error');
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when given a non-valid HD_BASE_URL', async () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
@@ -154,7 +174,11 @@ describe('appConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => appConfig()).toThrow('HD_BASE_URL');
|
||||
appConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
"HD_BASE_URL: Can't parse as URL",
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -171,9 +195,11 @@ describe('appConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => appConfig()).toThrow(
|
||||
appConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_BASE_URL: baseUrl must not contain a subdirectory',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -191,9 +217,11 @@ describe('appConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => appConfig()).toThrow(
|
||||
appConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_BACKEND_PORT: Number must be greater than 0',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -211,9 +239,11 @@ describe('appConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => appConfig()).toThrow(
|
||||
appConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_BACKEND_PORT: Number must be less than or equal to 65535',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -231,9 +261,11 @@ describe('appConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => appConfig()).toThrow(
|
||||
appConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_BACKEND_PORT: Expected integer, received float',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -251,9 +283,11 @@ describe('appConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => appConfig()).toThrow(
|
||||
appConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_BACKEND_PORT: Expected number, received nan',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -271,7 +305,9 @@ describe('appConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => appConfig()).toThrow('HD_LOG_LEVEL');
|
||||
appConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain('HD_LOG_LEVEL');
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -125,6 +125,25 @@ describe('authConfig', () => {
|
||||
});
|
||||
|
||||
describe('fails to be parsed', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error');
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH is 5', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
@@ -138,9 +157,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH: Number must be less than or equal to 4',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH is -1', () => {
|
||||
@@ -156,9 +177,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_LOCAL_MINIMAL_PASSWORD_STRENGTH: Number must be greater than or equal to 0',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
@@ -486,6 +509,25 @@ describe('authConfig', () => {
|
||||
});
|
||||
});
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error').mockImplementation();
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when HD_AUTH_LDAP_FUTURAMA_URL is wrong', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
@@ -499,9 +541,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_LDAP_FUTURAMA_URL: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_AUTH_LDAP_FUTURAMA_SEARCH_BASE is wrong', () => {
|
||||
@@ -517,9 +561,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_LDAP_FUTURAMA_SEARCH_BASE: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_AUTH_LDAP_FUTURAMA_TLS_CERT_PATHS is wrong', () => {
|
||||
@@ -535,9 +581,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_LDAP_FUTURAMA_TLS_CA_CERTS[0]: File not found',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
@@ -1011,6 +1059,25 @@ describe('authConfig', () => {
|
||||
});
|
||||
});
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error').mockImplementation();
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when HD_AUTH_OIDC_GITLAB_ISSUER is not set', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
@@ -1024,9 +1091,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_OIDC_GITLAB_ISSUER: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_AUTH_OIDC_GITLAB_CLIENT_ID is not set', () => {
|
||||
@@ -1042,9 +1111,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_OIDC_GITLAB_CLIENT_ID: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_AUTH_OIDC_GITLAB_CLIENT_SECRET is not set', () => {
|
||||
@@ -1060,9 +1131,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_AUTH_OIDC_GITLAB_CLIENT_SECRET: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_AUTH_OIDC_GITLAB_THEME is set to a wrong value', () => {
|
||||
@@ -1078,9 +1151,11 @@ describe('authConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => authConfig()).toThrow(
|
||||
authConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
"HD_AUTH_OIDC_GITLAB_THEME: Invalid enum value. Expected 'google' | 'github' | 'gitlab' | 'facebook' | 'discord' | 'mastodon' | 'azure', received 'something else'",
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -42,27 +42,56 @@ describe('customizationConfig', () => {
|
||||
restore();
|
||||
});
|
||||
|
||||
it('throws an error if anything is wrongly configured', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_BRANDING_CUSTOM_NAME: customName,
|
||||
HD_BRANDING_CUSTOM_LOGO: invalidCustomLogo,
|
||||
HD_URLS_PRIVACY: invalidPrivacyUrl,
|
||||
HD_URLS_TERMS_OF_USE: invalidTermsOfUseUrl,
|
||||
HD_URLS_IMPRINT: invalidImprintUrl,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => customizationConfig()).toThrow(
|
||||
`- HD_BRANDING_CUSTOM_LOGO: Invalid url
|
||||
- HD_URLS_PRIVACY: Invalid url
|
||||
- HD_URLS_TERMS_OF_USE: Invalid url
|
||||
- HD_URLS_IMPRINT: Invalid url`,
|
||||
);
|
||||
restore();
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error');
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when anything is wrongly configured', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_BRANDING_CUSTOM_NAME: customName,
|
||||
HD_BRANDING_CUSTOM_LOGO: invalidCustomLogo,
|
||||
HD_URLS_PRIVACY: invalidPrivacyUrl,
|
||||
HD_URLS_TERMS_OF_USE: invalidTermsOfUseUrl,
|
||||
HD_URLS_IMPRINT: invalidImprintUrl,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
customizationConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'- HD_BRANDING_CUSTOM_LOGO: Invalid url',
|
||||
);
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'- HD_URLS_PRIVACY: Invalid url',
|
||||
);
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'- HD_URLS_TERMS_OF_USE: Invalid url',
|
||||
);
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'- HD_URLS_IMPRINT: Invalid url',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,46 +96,71 @@ describe('databaseConfig', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('throws an error if the port is negative', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_DATABASE_TYPE: databaseTypePostgres,
|
||||
HD_DATABASE_NAME: databaseName,
|
||||
HD_DATABASE_USERNAME: databaseUser,
|
||||
HD_DATABASE_PASSWORD: databasePass,
|
||||
HD_DATABASE_HOST: databaseHost,
|
||||
HD_DATABASE_PORT: String(invalidDatabasePort),
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => databaseConfig()).toThrow(
|
||||
'HD_DATABASE_PORT: Number must be greater than 0',
|
||||
);
|
||||
restore();
|
||||
});
|
||||
it('throws an error if the port is too big', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_DATABASE_TYPE: databaseTypePostgres,
|
||||
HD_DATABASE_NAME: databaseName,
|
||||
HD_DATABASE_USERNAME: databaseUser,
|
||||
HD_DATABASE_PASSWORD: databasePass,
|
||||
HD_DATABASE_HOST: databaseHost,
|
||||
HD_DATABASE_PORT: String(invalidDatabasePort2),
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => databaseConfig()).toThrow(
|
||||
'HD_DATABASE_PORT: Number must be less than or equal to 65535',
|
||||
);
|
||||
restore();
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error');
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when the port is negative', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_DATABASE_TYPE: databaseTypePostgres,
|
||||
HD_DATABASE_NAME: databaseName,
|
||||
HD_DATABASE_USERNAME: databaseUser,
|
||||
HD_DATABASE_PASSWORD: databasePass,
|
||||
HD_DATABASE_HOST: databaseHost,
|
||||
HD_DATABASE_PORT: String(invalidDatabasePort),
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
databaseConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_DATABASE_PORT: Number must be greater than 0',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when the port is too big', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_DATABASE_TYPE: databaseTypePostgres,
|
||||
HD_DATABASE_NAME: databaseName,
|
||||
HD_DATABASE_USERNAME: databaseUser,
|
||||
HD_DATABASE_PASSWORD: databasePass,
|
||||
HD_DATABASE_HOST: databaseHost,
|
||||
HD_DATABASE_PORT: String(invalidDatabasePort2),
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
databaseConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_DATABASE_PORT: Number must be less than or equal to 65535',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -27,38 +27,61 @@ describe('externalServices', () => {
|
||||
restore();
|
||||
});
|
||||
|
||||
it('throws an error if PlantUML server is configured with an invalid URL', () => {
|
||||
const invalid = 'wrong!';
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_PLANTUML_SERVER: invalid,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => externalServicesConfig()).toThrow(
|
||||
'HD_PLANTUML_SERVER: Invalid url',
|
||||
);
|
||||
restore();
|
||||
});
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
it('throws an error if image proxy is configured', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_IMAGE_PROXY: imageProxy,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => externalServicesConfig()).toThrow(
|
||||
"HD_IMAGE_PROXY is currently not yet supported. Please don't configure it",
|
||||
);
|
||||
restore();
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error');
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when PlantUML server is configured with an invalid URL', () => {
|
||||
const invalid = 'wrong!';
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_PLANTUML_SERVER: invalid,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
externalServicesConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_PLANTUML_SERVER: Invalid url',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
it('when image proxy is configured', () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_IMAGE_PROXY: imageProxy,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => externalServicesConfig()).toThrow(
|
||||
"HD_IMAGE_PROXY is currently not yet supported. Please don't configure it",
|
||||
);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -147,6 +147,25 @@ describe('mediaConfig', () => {
|
||||
});
|
||||
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error');
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('for backend filesystem', () => {
|
||||
it('when HD_MEDIA_BACKEND_FILESYSTEM_UPLOAD_PATH is not set', async () => {
|
||||
const restore = mockedEnv(
|
||||
@@ -159,9 +178,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_FILESYSTEM_UPLOAD_PATH: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
@@ -181,9 +202,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_S3_ACCESS_KEY_ID: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_S3_SECRET_KEY is not set', async () => {
|
||||
@@ -200,9 +223,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_S3_SECRET_ACCESS_KEY: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_S3_BUCKET is not set', async () => {
|
||||
@@ -219,9 +244,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_S3_BUCKET: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_S3_ENDPOINT is not set', async () => {
|
||||
@@ -238,9 +265,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_S3_ENDPOINT: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_S3_ENDPOINT is not an URI', async () => {
|
||||
@@ -258,9 +287,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_S3_ENDPOINT: Invalid url',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
@@ -278,9 +309,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_AZURE_CONNECTION_STRING: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_AZURE_CONTAINER is not set', async () => {
|
||||
@@ -295,9 +328,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_AZURE_CONTAINER: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
@@ -314,9 +349,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_IMGUR_CLIENT_ID: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
@@ -335,9 +372,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_WEBDAV_CONNECTION_STRING: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_WEBDAV_CONNECTION_STRING is not set to an url', async () => {
|
||||
@@ -354,9 +393,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_WEBDAV_CONNECTION_STRING: Invalid url',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_WEBDAV_PUBLIC_URL is not set', async () => {
|
||||
@@ -372,9 +413,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_WEBDAV_PUBLIC_URL: Required',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
it('when HD_MEDIA_BACKEND_WEBDAV_PUBLIC_URL is not set to an url', async () => {
|
||||
@@ -391,9 +434,11 @@ describe('mediaConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => mediaConfig()).toThrow(
|
||||
mediaConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_MEDIA_BACKEND_WEBDAV_PUBLIC_URL: Invalid url',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -262,6 +262,25 @@ describe('noteConfig', () => {
|
||||
});
|
||||
|
||||
describe('throws error', () => {
|
||||
let spyConsoleError: jest.SpyInstance;
|
||||
let spyProcessExit: jest.Mock;
|
||||
let originalProcess: typeof process;
|
||||
|
||||
beforeEach(() => {
|
||||
spyConsoleError = jest.spyOn(console, 'error');
|
||||
spyProcessExit = jest.fn();
|
||||
originalProcess = global.process;
|
||||
global.process = {
|
||||
...originalProcess,
|
||||
exit: spyProcessExit,
|
||||
} as unknown as typeof global.process;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
global.process = originalProcess;
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('when given a non-valid HD_NOTE_FORBIDDEN_ALIASES', async () => {
|
||||
const restore = mockedEnv(
|
||||
{
|
||||
@@ -278,9 +297,14 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
'HD_NOTE_FORBIDDEN_ALIASES[0]: String must contain at least 1 character(s)\n - HD_NOTE_FORBIDDEN_ALIASES[1]: String must contain at least 1 character(s)',
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_NOTE_FORBIDDEN_ALIASES[0]: String must contain at least 1 character(s)',
|
||||
);
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_NOTE_FORBIDDEN_ALIASES[1]: String must contain at least 1 character(s)',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -300,9 +324,11 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_NOTE_MAX_LENGTH: Number must be greater than 0',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -322,9 +348,11 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_NOTE_MAX_LENGTH: Expected integer, received float',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -344,9 +372,11 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_NOTE_MAX_LENGTH: Expected number, received nan',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -365,9 +395,11 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
`HD_NOTE_PERMISSIONS_DEFAULT_EVERYONE: Invalid enum value. Expected '${PermissionLevelNames[PermissionLevel.DENY]}' | '${PermissionLevelNames[PermissionLevel.READ]}' | '${PermissionLevelNames[PermissionLevel.WRITE]}' | '${PermissionLevelNames[PermissionLevel.FULL]}', received 'wrong'`,
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -386,9 +418,11 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
`HD_NOTE_PERMISSIONS_DEFAULT_LOGGED_IN: Invalid enum value. Expected '${PermissionLevelNames[PermissionLevel.DENY]}' | '${PermissionLevelNames[PermissionLevel.READ]}' | '${PermissionLevelNames[PermissionLevel.WRITE]}' | '${PermissionLevelNames[PermissionLevel.FULL]}', received 'wrong'`,
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -398,20 +432,22 @@ describe('noteConfig', () => {
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
HD_NOTE_FORBIDDEN_ALIASES: forbiddenAliases.join(' , '),
|
||||
HD_NOTE_MAX_LENGTH: maxLength.toString(),
|
||||
HD_PERMISSION_DEFAULT_EVERYONE:
|
||||
HD_NOTE_PERMISSIONS_DEFAULT_EVERYONE:
|
||||
PermissionLevelNames[PermissionLevel.READ],
|
||||
HD_PERMISSION_DEFAULT_LOGGED_IN:
|
||||
HD_NOTE_PERMISSIONS_DEFAULT_LOGGED_IN:
|
||||
PermissionLevelNames[PermissionLevel.READ],
|
||||
HD_PERMISSIONS_MAX_GUEST_LEVEL: wrongDefaultPermission,
|
||||
HD_NOTE_PERMISSIONS_MAX_GUEST_LEVEL: wrongDefaultPermission,
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
`HD_PERMISSIONS_MAX_GUEST_LEVEL: Invalid enum value. Expected '${PermissionLevelNames[PermissionLevel.DENY]}' | '${PermissionLevelNames[PermissionLevel.READ]}' | '${PermissionLevelNames[PermissionLevel.WRITE]}' | '${PermissionLevelNames[PermissionLevel.FULL]}', received 'wrong'`,
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
`HD_NOTE_PERMISSIONS_MAX_GUEST_LEVEL: Invalid enum value. Expected '${PermissionLevelNames[PermissionLevel.DENY]}' | '${PermissionLevelNames[PermissionLevel.READ]}' | '${PermissionLevelNames[PermissionLevel.WRITE]}' | '${PermissionLevelNames[PermissionLevel.FULL]}', received 'wrong'`,
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -425,7 +461,7 @@ describe('noteConfig', () => {
|
||||
PermissionLevelNames[PermissionLevel.READ],
|
||||
HD_NOTE_PERMISSIONS_DEFAULT_LOGGED_IN:
|
||||
PermissionLevelNames[PermissionLevel.READ],
|
||||
HD_PERMISSIONS_MAX_GUEST_LEVEL: 'deny',
|
||||
HD_NOTE_PERMISSIONS_MAX_GUEST_LEVEL: 'deny',
|
||||
/* eslint-enable @typescript-eslint/naming-convention */
|
||||
},
|
||||
{
|
||||
@@ -433,7 +469,7 @@ describe('noteConfig', () => {
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
`'HD_NOTE_PERMISSIONS_DEFAULT_EVERYONE' is set to '${PermissionLevelNames[PermissionLevel.READ]}', but 'HD_PERMISSIONS_MAX_GUEST_LEVEL' is set to '${PermissionLevelNames[PermissionLevel.DENY]}'. This does not work since the default level may not be higher than the maximum guest level.`,
|
||||
`'HD_NOTE_PERMISSIONS_DEFAULT_EVERYONE' is set to '${PermissionLevelNames[PermissionLevel.READ]}', but 'HD_NOTE_PERMISSIONS_MAX_GUEST_LEVEL' is set to '${PermissionLevelNames[PermissionLevel.DENY]}'. This does not work since the default level may not be higher than the maximum guest level.`,
|
||||
);
|
||||
restore();
|
||||
});
|
||||
@@ -521,9 +557,11 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_NOTE_REVISION_RETENTION_DAYS: Number must be greater than or equal to 0',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
|
||||
@@ -545,9 +583,11 @@ describe('noteConfig', () => {
|
||||
clear: true,
|
||||
},
|
||||
);
|
||||
expect(() => noteConfig()).toThrow(
|
||||
noteConfig();
|
||||
expect(spyConsoleError.mock.calls[0][0]).toContain(
|
||||
'HD_NOTE_PERSIST_INTERVAL: Number must be greater than or equal to 0',
|
||||
);
|
||||
expect(spyProcessExit).toHaveBeenCalledWith(1);
|
||||
restore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -87,7 +87,6 @@ describe('FrontendConfigService', () => {
|
||||
level: Loglevel.ERROR,
|
||||
showTimestamp: false,
|
||||
},
|
||||
persistInterval: 10,
|
||||
};
|
||||
const authConfig: AuthConfig = {
|
||||
...emptyAuthConfig,
|
||||
@@ -106,7 +105,7 @@ describe('FrontendConfigService', () => {
|
||||
customName: null,
|
||||
customLogo: null,
|
||||
},
|
||||
specialUrls: {},
|
||||
urls: {},
|
||||
};
|
||||
}),
|
||||
registerAs('externalServicesConfig', () => {
|
||||
@@ -114,8 +113,8 @@ describe('FrontendConfigService', () => {
|
||||
}),
|
||||
registerAs('noteConfig', () => {
|
||||
return {
|
||||
forbiddenNoteIds: [],
|
||||
maxDocumentLength: 200,
|
||||
forbiddenAliases: [],
|
||||
maxLength: 200,
|
||||
permissions: {
|
||||
maxGuestLevel: PermissionLevel.FULL,
|
||||
default: {
|
||||
@@ -124,6 +123,7 @@ describe('FrontendConfigService', () => {
|
||||
},
|
||||
},
|
||||
revisionRetentionDays: 0,
|
||||
persistInterval: 10,
|
||||
} as unknown as NoteConfig;
|
||||
}),
|
||||
],
|
||||
@@ -195,7 +195,6 @@ describe('FrontendConfigService', () => {
|
||||
level: Loglevel.ERROR,
|
||||
showTimestamp: false,
|
||||
},
|
||||
persistInterval: 10,
|
||||
};
|
||||
const authConfig: AuthConfig = {
|
||||
...emptyAuthConfig,
|
||||
@@ -231,6 +230,7 @@ describe('FrontendConfigService', () => {
|
||||
maxGuestLevel: PermissionLevel.FULL,
|
||||
},
|
||||
revisionRetentionDays: 0,
|
||||
persistInterval: 10,
|
||||
};
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
imports: [
|
||||
|
||||
@@ -54,7 +54,7 @@ export class FrontendConfigService {
|
||||
plantUmlServer: this.externalServicesConfig.plantumlServer
|
||||
? new URL(this.externalServicesConfig.plantumlServer).toString()
|
||||
: null,
|
||||
urls: this.getSpecialUrls(),
|
||||
specialUrls: this.getSpecialUrls(),
|
||||
useImageProxy: !!this.externalServicesConfig.imageProxy,
|
||||
version: await getServerVersionFromPackageJson(),
|
||||
});
|
||||
|
||||
@@ -43,7 +43,7 @@ describe('s3 backend', () => {
|
||||
function mockMediaConfig(endPoint: string): MediaConfig {
|
||||
return Mock.of<MediaConfig>({
|
||||
backend: {
|
||||
use: MediaBackendType.S3,
|
||||
type: MediaBackendType.S3,
|
||||
s3: {
|
||||
accessKeyId: mockedS3AccessKeyId,
|
||||
secretAccessKey: mockedS3SecretAccessKey,
|
||||
|
||||
Reference in New Issue
Block a user