@mimik/configuration 6.0.8 → 6.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/index.js +2 -2
- package/package.json +1 -1
- package/.husky/pre-commit +0 -2
- package/.husky/pre-push +0 -2
- package/eslint.config.js +0 -87
- package/manual-test/test-config.js +0 -48
- package/manual-test/testEnv.js +0 -21
- package/test/configuration.spec.js +0 -1038
- package/test/testEnv.js +0 -46
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ The following environment variables are being used for the configuration:
|
|
|
84
84
|
| OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
|
|
85
85
|
| OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
|
|
86
86
|
| API_KEYS | list of API Keys which are tested against in case of APIKey security | [] |
|
|
87
|
-
| LOG_MODE | collector to be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`,
|
|
87
|
+
| LOG_MODE | collector to be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, `awsKinesis`, `none`
|
|
88
88
|
| NO_STACK | disable the inclusion of the stack in all logs | yes | logInfo.noStack
|
|
89
89
|
| FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
|
|
90
90
|
| USER_DEFINITIONS_FILE | path for the custom user definitions | null | userDefinitions.file |
|
|
@@ -100,7 +100,7 @@ The following environment variables are being used for the configuration:
|
|
|
100
100
|
| MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
|
|
101
101
|
| REGISTRATION_SET | switch to enable use of registration | on | registration.set | can be `on` or `off`
|
|
102
102
|
| REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
|
|
103
|
-
| REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration
|
|
103
|
+
| REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration after the execution of the postOps | off | registration.afterPostOpsSet | can be `on` or `off`
|
|
104
104
|
| `$_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
|
|
105
105
|
| `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
|
|
106
106
|
|
package/index.js
CHANGED
|
@@ -496,7 +496,7 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
496
496
|
* | OAUTH_GENERIC_PREVIOUS_KEY | key for the token signature before change the public key | | security.generic.previousKey | [2]
|
|
497
497
|
* | OAUTH_GENERIC_AUDIENCE | url representing the generic of the service type to mST | noGeneric | security.generic.audience | [2]
|
|
498
498
|
* | API_KEYS | list of API Keys which are tested against in case of APIKey security | [] |
|
|
499
|
-
* | LOG_MODE | collector to be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`,
|
|
499
|
+
* | LOG_MODE | collector to be used to log events | sumologic | logInfo.mode | can be `sumologic`, `awsS3`, `all`, `awsKinesis`, `none`
|
|
500
500
|
* | NO_STACK | disable the inclusion of the stack in all logs | yes | logInfo.noStack
|
|
501
501
|
* | FILTER_FILE | path for the filter file definition | null | logInfo.filterFile |
|
|
502
502
|
* | USER_DEFINITIONS_FILE | path for the custom user definitions | null | userDefinitions.file |
|
|
@@ -512,7 +512,7 @@ configuration.locationProvider = setupLocationProvider();
|
|
|
512
512
|
* | MIT_AUDIENCE | audience of mIT | | dependencies.mIT.audience | [2]
|
|
513
513
|
* | REGISTRATION_SET | switch to enable use of registration | on | registration.set | can be `on` or `off`
|
|
514
514
|
* | REGISTRATION_RETRY | retry time for registering to mIT | 3000 | registration.retry | in milliseconds
|
|
515
|
-
* | REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration
|
|
515
|
+
* | REGISTRATION_AFTER_POSTOPS_SET | switch to set the registration after the execution of the postOps | off | registration.afterPostOpsSet | can be `on` or `off`
|
|
516
516
|
* | `${configuration.serverSettings.type}_URL`.toUpperCase() | cluster information | self | dependencies.`(SERVER_TYPE)`.url | should not be used
|
|
517
517
|
* | `${configuration.serverSettings.type}_AUDIENCE`.toUpperCase() | cluster information | | dependencies.`(SERVER_TYPE)`.audience | [2], but should not be used
|
|
518
518
|
*
|
package/package.json
CHANGED
package/.husky/pre-commit
DELETED
package/.husky/pre-push
DELETED
package/eslint.config.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import globals from 'globals';
|
|
2
|
-
import importPlugin from 'eslint-plugin-import';
|
|
3
|
-
import js from '@eslint/js';
|
|
4
|
-
import processDoc from '@mimik/eslint-plugin-document-env';
|
|
5
|
-
import stylistic from '@stylistic/eslint-plugin';
|
|
6
|
-
|
|
7
|
-
const MAX_LENGTH_LINE = 180;
|
|
8
|
-
const MAX_FUNCTION_PARAMETERS = 6;
|
|
9
|
-
const MAX_LINES_IN_FILES = 600;
|
|
10
|
-
const MAX_LINES_IN_FUNCTION = 150;
|
|
11
|
-
const MAX_STATEMENTS_IN_FUNCTION = 45;
|
|
12
|
-
const MIN_KEYS_IN_OBJECT = 10;
|
|
13
|
-
const MAX_COMPLEXITY = 30;
|
|
14
|
-
const ECMA_VERSION = 'latest';
|
|
15
|
-
const MAX_DEPTH = 6;
|
|
16
|
-
const ALLOWED_CONSTANTS = [0, 1, -1];
|
|
17
|
-
|
|
18
|
-
export default [
|
|
19
|
-
{
|
|
20
|
-
ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
|
|
21
|
-
},
|
|
22
|
-
importPlugin.flatConfigs.recommended,
|
|
23
|
-
stylistic.configs.recommended,
|
|
24
|
-
js.configs.all,
|
|
25
|
-
{
|
|
26
|
-
plugins: {
|
|
27
|
-
processDoc,
|
|
28
|
-
},
|
|
29
|
-
languageOptions: {
|
|
30
|
-
ecmaVersion: ECMA_VERSION,
|
|
31
|
-
globals: {
|
|
32
|
-
...globals.nodeBuiltin,
|
|
33
|
-
},
|
|
34
|
-
sourceType: 'module',
|
|
35
|
-
},
|
|
36
|
-
rules: {
|
|
37
|
-
'@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
|
|
38
|
-
'@stylistic/line-comment-position': ['off'],
|
|
39
|
-
'@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
|
|
40
|
-
'@stylistic/quotes': ['warn', 'single'],
|
|
41
|
-
'@stylistic/semi': ['error', 'always'],
|
|
42
|
-
'capitalized-comments': ['off'],
|
|
43
|
-
'complexity': ['error', MAX_COMPLEXITY],
|
|
44
|
-
'curly': ['off'],
|
|
45
|
-
'id-length': ['error', { exceptions: ['x', 'y', 'z', 'i', 'j', 'k'] }],
|
|
46
|
-
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
|
47
|
-
'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
|
|
48
|
-
'init-declarations': ['off'],
|
|
49
|
-
'linebreak-style': ['off'],
|
|
50
|
-
'max-depth': ['error', MAX_DEPTH],
|
|
51
|
-
'max-len': ['off'],
|
|
52
|
-
'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
|
|
53
|
-
'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
|
|
54
|
-
'max-params': ['error', MAX_FUNCTION_PARAMETERS],
|
|
55
|
-
'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
|
|
56
|
-
'no-confusing-arrow': ['off'],
|
|
57
|
-
'no-inline-comments': ['off'],
|
|
58
|
-
'no-magic-numbers': ['error', { ignore: ALLOWED_CONSTANTS, enforceConst: true, detectObjects: true }],
|
|
59
|
-
'no-process-env': ['error'],
|
|
60
|
-
'no-ternary': ['off'],
|
|
61
|
-
'no-undefined': ['off'],
|
|
62
|
-
'one-var': ['error', 'never'],
|
|
63
|
-
'processDoc/validate-document-env': ['error'],
|
|
64
|
-
'quotes': ['off'],
|
|
65
|
-
'sort-imports': ['error', { allowSeparatedGroups: true }],
|
|
66
|
-
'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
|
|
67
|
-
},
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
files: ['test/**/*.js'],
|
|
71
|
-
languageOptions: {
|
|
72
|
-
globals: {
|
|
73
|
-
...globals.mocha,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
rules: {
|
|
77
|
-
'class-methods-use-this': ['off'],
|
|
78
|
-
'max-classes-per-file': ['off'],
|
|
79
|
-
'max-lines': ['off'],
|
|
80
|
-
'max-lines-per-function': ['off'],
|
|
81
|
-
'max-statements': ['off'],
|
|
82
|
-
'no-empty-function': ['off'],
|
|
83
|
-
'no-magic-numbers': ['off'],
|
|
84
|
-
'processDoc/validate-document-env': ['off'],
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
];
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import './testEnv.js';
|
|
3
|
-
import { setConfig } from '../index.js';
|
|
4
|
-
// import Config from '../index.js';
|
|
5
|
-
|
|
6
|
-
const pack = {
|
|
7
|
-
swaggerFile: {
|
|
8
|
-
version: '2.0.6',
|
|
9
|
-
account: 'mimiktech',
|
|
10
|
-
name: 'swagger-mds',
|
|
11
|
-
},
|
|
12
|
-
mimik: {
|
|
13
|
-
type: 'test-pack-type',
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
const config = {
|
|
17
|
-
database: {
|
|
18
|
-
type: 'mongodb',
|
|
19
|
-
table: {
|
|
20
|
-
itResource: 'itResource',
|
|
21
|
-
lease: 'lease',
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
dependencies: {
|
|
25
|
-
'mIT': {
|
|
26
|
-
audience: 'test-audience',
|
|
27
|
-
url: 'test-url',
|
|
28
|
-
},
|
|
29
|
-
'test-pack-type': {
|
|
30
|
-
audience: 'test-pack-type-audience',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
security: {
|
|
34
|
-
server: {
|
|
35
|
-
id: 'test-security-id',
|
|
36
|
-
secret: 'test-security-secret',
|
|
37
|
-
accessKey: 'test-security-access-key',
|
|
38
|
-
audience: 'test-security-audience',
|
|
39
|
-
issuer: 'test-security-issuer',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
serverSettings: {
|
|
43
|
-
type: 'test-type',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const configuration = setConfig(pack, config);
|
|
48
|
-
console.log(configuration);
|
package/manual-test/testEnv.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/* eslint no-process-env: "off" */
|
|
2
|
-
import process from 'process';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* Test configuration Configuration.
|
|
7
|
-
*
|
|
8
|
-
* @description The following environment variables are needed to configure configuration:
|
|
9
|
-
*
|
|
10
|
-
* | Env variable name | Description | Default | Comments |
|
|
11
|
-
* | ----------------- | ----------- | ------- | -------- |
|
|
12
|
-
* | DATABASE_NAME | name of the database to use for mongodb
|
|
13
|
-
* | MONGO_REPLICAT_SET | set to a value for Boolean()
|
|
14
|
-
* | SUMO_LOGIC_ENDPOINT | dummy endpoint for sumologic
|
|
15
|
-
* | SUMO_LOGIC_COLLECTOR_CODE | dummy collector code for sumologic
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
process.env.DATABASE_NAME = 'test-database-name';
|
|
19
|
-
process.env.MONGO_REPLICAT_SET = 'test-mongo-replicat-set';
|
|
20
|
-
process.env.SUMO_LOGIC_ENDPOINT = 'test-logInfo-sumologic-endpoint';
|
|
21
|
-
process.env.SUMO_LOGIC_COLLECTOR_CODE = 'test-logInfo-sumologic-code';
|
|
@@ -1,1038 +0,0 @@
|
|
|
1
|
-
/* eslint no-process-env: "off" */
|
|
2
|
-
import './testEnv.js';
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
after,
|
|
6
|
-
afterEach,
|
|
7
|
-
before,
|
|
8
|
-
describe,
|
|
9
|
-
it,
|
|
10
|
-
} from 'mocha';
|
|
11
|
-
import esmock from 'esmock';
|
|
12
|
-
import { expect } from 'chai';
|
|
13
|
-
import process from 'node:process';
|
|
14
|
-
import { stub } from 'sinon';
|
|
15
|
-
|
|
16
|
-
// Minimal valid pack object for setConfig
|
|
17
|
-
const basePack = {
|
|
18
|
-
name: '@mimik/test-service',
|
|
19
|
-
version: '1.0.0',
|
|
20
|
-
mimik: { type: 'mTest' },
|
|
21
|
-
swaggerFile: {
|
|
22
|
-
version: '1.0.0',
|
|
23
|
-
account: 'mimiktech',
|
|
24
|
-
name: 'test-api',
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// Minimal valid options for setConfig
|
|
29
|
-
const baseOptions = {};
|
|
30
|
-
|
|
31
|
-
// Mock stubs for dependencies
|
|
32
|
-
const mockLogger = {
|
|
33
|
-
error: stub(),
|
|
34
|
-
warn: stub(),
|
|
35
|
-
info: stub(),
|
|
36
|
-
debug: stub(),
|
|
37
|
-
verbose: stub(),
|
|
38
|
-
flushAndExit: stub(),
|
|
39
|
-
flush: stub(),
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const mockGetCorrelationId = stub().returns('mock-correlation-id@0/2026-01-01T00:00:00.000Z');
|
|
43
|
-
const mockIpAddress = stub().returns('127.0.0.1');
|
|
44
|
-
const mockUserDefinitions = {
|
|
45
|
-
all: { attributes: ['nickname'], properties: ['nickName'] },
|
|
46
|
-
basic: { attributes: ['nickname'], properties: ['nickName'] },
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Helper to import module with esmock and optional env overrides
|
|
50
|
-
const importModule = async (envOverrides = {}) => {
|
|
51
|
-
const savedEnv = {};
|
|
52
|
-
for (const [key, value] of Object.entries(envOverrides)) {
|
|
53
|
-
savedEnv[key] = process.env[key];
|
|
54
|
-
if (value === undefined) delete process.env[key];
|
|
55
|
-
else process.env[key] = value;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const mod = await esmock('../index.js', {
|
|
59
|
-
'@mimik/sumologic-winston-logger': { default: mockLogger },
|
|
60
|
-
'@mimik/request-helper': { getCorrelationId: mockGetCorrelationId },
|
|
61
|
-
'@mimik/user-filters': { userDefinitions: mockUserDefinitions },
|
|
62
|
-
'ip': { address: mockIpAddress },
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
return { mod, savedEnv };
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const restoreEnv = (savedEnv) => {
|
|
69
|
-
for (const [key, value] of Object.entries(savedEnv)) {
|
|
70
|
-
if (value === undefined) delete process.env[key];
|
|
71
|
-
else process.env[key] = value;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const resetStubs = () => {
|
|
76
|
-
mockLogger.error.reset();
|
|
77
|
-
mockLogger.warn.reset();
|
|
78
|
-
mockLogger.info.reset();
|
|
79
|
-
mockLogger.debug.reset();
|
|
80
|
-
mockLogger.verbose.reset();
|
|
81
|
-
mockLogger.flush.reset();
|
|
82
|
-
mockLogger.flushAndExit.reset();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// ============================================================
|
|
86
|
-
// Tests
|
|
87
|
-
// ============================================================
|
|
88
|
-
|
|
89
|
-
describe('configuration Unit Tests', () => {
|
|
90
|
-
// ----------------------------------------------------------
|
|
91
|
-
// isProd
|
|
92
|
-
// ----------------------------------------------------------
|
|
93
|
-
describe('isProd()', () => {
|
|
94
|
-
let isProd;
|
|
95
|
-
let savedEnv;
|
|
96
|
-
|
|
97
|
-
before(async () => {
|
|
98
|
-
const result = await importModule();
|
|
99
|
-
({ isProd } = result.mod);
|
|
100
|
-
({ savedEnv } = result);
|
|
101
|
-
});
|
|
102
|
-
after(() => restoreEnv(savedEnv));
|
|
103
|
-
afterEach(() => {
|
|
104
|
-
delete process.env.NODE_ENV;
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should return true when NODE_ENV is "prod"', () => {
|
|
108
|
-
process.env.NODE_ENV = 'prod';
|
|
109
|
-
expect(isProd()).to.equal(true);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should return true when NODE_ENV is "production"', () => {
|
|
113
|
-
process.env.NODE_ENV = 'production';
|
|
114
|
-
expect(isProd()).to.equal(true);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('should return true when NODE_ENV is "PROD" (case insensitive)', () => {
|
|
118
|
-
process.env.NODE_ENV = 'PROD';
|
|
119
|
-
expect(isProd()).to.equal(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('should return true when NODE_ENV is "Production" (case insensitive)', () => {
|
|
123
|
-
process.env.NODE_ENV = 'Production';
|
|
124
|
-
expect(isProd()).to.equal(true);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should return false when NODE_ENV is "local"', () => {
|
|
128
|
-
process.env.NODE_ENV = 'local';
|
|
129
|
-
expect(isProd()).to.equal(false);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should return false when NODE_ENV is "development"', () => {
|
|
133
|
-
process.env.NODE_ENV = 'development';
|
|
134
|
-
expect(isProd()).to.equal(false);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('should return false when NODE_ENV is undefined', () => {
|
|
138
|
-
delete process.env.NODE_ENV;
|
|
139
|
-
expect(isProd()).to.equal(false);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('should return false when NODE_ENV is empty string', () => {
|
|
143
|
-
process.env.NODE_ENV = '';
|
|
144
|
-
expect(isProd()).to.equal(false);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// ----------------------------------------------------------
|
|
149
|
-
// Module-level side effects
|
|
150
|
-
// ----------------------------------------------------------
|
|
151
|
-
describe('Module-level side effects', () => {
|
|
152
|
-
it('should set SERVER_LOCAL_IPV4 to the mocked IP address', async () => {
|
|
153
|
-
const { savedEnv } = await importModule();
|
|
154
|
-
expect(process.env.SERVER_LOCAL_IPV4).to.equal('127.0.0.1');
|
|
155
|
-
restoreEnv(savedEnv);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('should set AWS_LOCAL_PROPERTIES to 169.254.169.254', async () => {
|
|
159
|
-
const { savedEnv } = await importModule();
|
|
160
|
-
expect(process.env.AWS_LOCAL_PROPERTIES).to.equal('169.254.169.254');
|
|
161
|
-
restoreEnv(savedEnv);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('should set CONSOLE_LEVEL to debug if not already set', async () => {
|
|
165
|
-
const saved = process.env.CONSOLE_LEVEL;
|
|
166
|
-
delete process.env.CONSOLE_LEVEL;
|
|
167
|
-
const { savedEnv } = await importModule();
|
|
168
|
-
expect(process.env.CONSOLE_LEVEL).to.equal('debug');
|
|
169
|
-
restoreEnv(savedEnv);
|
|
170
|
-
process.env.CONSOLE_LEVEL = saved;
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should preserve existing CONSOLE_LEVEL if already set', async () => {
|
|
174
|
-
process.env.CONSOLE_LEVEL = 'warn';
|
|
175
|
-
const { savedEnv } = await importModule();
|
|
176
|
-
expect(process.env.CONSOLE_LEVEL).to.equal('warn');
|
|
177
|
-
restoreEnv(savedEnv);
|
|
178
|
-
process.env.CONSOLE_LEVEL = 'debug';
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should set SERVER_ID if not already set', async () => {
|
|
182
|
-
const saved = process.env.SERVER_ID;
|
|
183
|
-
delete process.env.SERVER_ID;
|
|
184
|
-
await importModule();
|
|
185
|
-
expect(process.env.SERVER_ID).to.be.a('string');
|
|
186
|
-
expect(process.env.SERVER_ID.length).to.be.greaterThan(0);
|
|
187
|
-
if (saved) process.env.SERVER_ID = saved;
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
// ----------------------------------------------------------
|
|
192
|
-
// setConfig - base configuration
|
|
193
|
-
// ----------------------------------------------------------
|
|
194
|
-
describe('setConfig(pack, options) - base', () => {
|
|
195
|
-
let setConfig;
|
|
196
|
-
let savedEnv;
|
|
197
|
-
|
|
198
|
-
before(async () => {
|
|
199
|
-
const result = await importModule();
|
|
200
|
-
({ setConfig } = result.mod);
|
|
201
|
-
({ savedEnv } = result);
|
|
202
|
-
resetStubs();
|
|
203
|
-
});
|
|
204
|
-
after(() => restoreEnv(savedEnv));
|
|
205
|
-
afterEach(() => resetStubs());
|
|
206
|
-
|
|
207
|
-
it('should set SERVER_VERSION, SERVER_NAME, SERVER_TYPE from pack', () => {
|
|
208
|
-
setConfig(basePack, baseOptions);
|
|
209
|
-
expect(process.env.SERVER_VERSION).to.equal('1.0.0');
|
|
210
|
-
expect(process.env.SERVER_NAME).to.equal('@mimik/test-service');
|
|
211
|
-
expect(process.env.SERVER_TYPE).to.equal('mTest');
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it('should return a configuration object with serverSettings populated', () => {
|
|
215
|
-
const config = setConfig(basePack, baseOptions);
|
|
216
|
-
expect(config.serverSettings.name).to.equal('@mimik/test-service');
|
|
217
|
-
expect(config.serverSettings.type).to.equal('mTest');
|
|
218
|
-
expect(config.serverSettings.version).to.equal('1.0.0');
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('should default swagger provider to bitbucket when not provided', () => {
|
|
222
|
-
const config = setConfig(basePack, baseOptions);
|
|
223
|
-
expect(process.env.SWAGGER_FILE_PROVIDER).to.equal('bitbucket');
|
|
224
|
-
expect(config.serverSettings.swaggerFile.provider).to.equal('bitbucket');
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('should set swagger file properties from pack', () => {
|
|
228
|
-
const config = setConfig(basePack, baseOptions);
|
|
229
|
-
expect(config.serverSettings.swaggerFile.version).to.equal('1.0.0');
|
|
230
|
-
expect(config.serverSettings.swaggerFile.account).to.equal('mimiktech');
|
|
231
|
-
expect(config.serverSettings.swaggerFile.name).to.equal('test-api');
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('should use provided swagger provider when specified', () => {
|
|
235
|
-
const packWithProvider = {
|
|
236
|
-
...basePack,
|
|
237
|
-
swaggerFile: { ...basePack.swaggerFile, provider: 'swaggerhub' },
|
|
238
|
-
};
|
|
239
|
-
const config = setConfig(packWithProvider, baseOptions);
|
|
240
|
-
expect(config.serverSettings.swaggerFile.provider).to.equal('swaggerhub');
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it('should throw for unsupported swagger provider', () => {
|
|
244
|
-
const packBadProvider = {
|
|
245
|
-
...basePack,
|
|
246
|
-
swaggerFile: { ...basePack.swaggerFile, provider: 'gitlab' },
|
|
247
|
-
};
|
|
248
|
-
expect(() => setConfig(packBadProvider, baseOptions))
|
|
249
|
-
.to.throw('swaggerFile provider not supported: gitlab');
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('should construct the api path correctly', () => {
|
|
253
|
-
const config = setConfig(basePack, baseOptions);
|
|
254
|
-
expect(config.serverSettings.api).to.equal('../api/mimiktech_test-api_1.0.0_swagger.json');
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it('should use SWAGGER_FILE_DIRECTORY env var for api path', () => {
|
|
258
|
-
process.env.SWAGGER_FILE_DIRECTORY = '/custom/api';
|
|
259
|
-
const config = setConfig(basePack, baseOptions);
|
|
260
|
-
expect(config.serverSettings.api).to.include('/custom/api/');
|
|
261
|
-
delete process.env.SWAGGER_FILE_DIRECTORY;
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
it('should return default config values', () => {
|
|
265
|
-
const config = setConfig(basePack, baseOptions);
|
|
266
|
-
expect(config.cache.set).to.equal('off');
|
|
267
|
-
expect(config.topic.set).to.equal('off');
|
|
268
|
-
expect(config.encryption.set).to.equal('off');
|
|
269
|
-
expect(config.registration.set).to.equal('on');
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it('should parse SERVER_PORT as integer', () => {
|
|
273
|
-
const config = setConfig(basePack, baseOptions);
|
|
274
|
-
expect(config.serverSettings.port).to.equal(3000);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('should split API_KEYS into array', () => {
|
|
278
|
-
const config = setConfig(basePack, baseOptions);
|
|
279
|
-
expect(config.security.apiKeys).to.deep.equal(['testKey1', 'testKey2']);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
// ----------------------------------------------------------
|
|
284
|
-
// setConfig - MongoDB
|
|
285
|
-
// ----------------------------------------------------------
|
|
286
|
-
describe('setConfig - mongodb', () => {
|
|
287
|
-
it('should throw when DATABASE_NAME is not set', async () => {
|
|
288
|
-
const { mod, savedEnv } = await importModule();
|
|
289
|
-
expect(() => mod.setConfig(basePack, {
|
|
290
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
291
|
-
})).to.throw('Errors in configuration');
|
|
292
|
-
restoreEnv(savedEnv);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it('should set mongoSettings when DATABASE_NAME is set', async () => {
|
|
296
|
-
const { mod, savedEnv } = await importModule({ DATABASE_NAME: 'testdb' });
|
|
297
|
-
const config = mod.setConfig(basePack, {
|
|
298
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
299
|
-
});
|
|
300
|
-
expect(config.mongoSettings).to.be.an('object');
|
|
301
|
-
expect(config.mongoSettings.database).to.equal('testdb');
|
|
302
|
-
expect(config.mongoSettings.table).to.equal('test-table');
|
|
303
|
-
restoreEnv(savedEnv);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('should use default domain localhost', async () => {
|
|
307
|
-
const { mod, savedEnv } = await importModule({ DATABASE_NAME: 'testdb' });
|
|
308
|
-
const config = mod.setConfig(basePack, {
|
|
309
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
310
|
-
});
|
|
311
|
-
expect(config.mongoSettings.domain).to.equal('localhost');
|
|
312
|
-
expect(config.mongoSettings.url).to.include('mongodb://localhost/testdb');
|
|
313
|
-
restoreEnv(savedEnv);
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('should use mongodb+srv:// when MONGO_USE_SRV is yes', async () => {
|
|
317
|
-
const { mod, savedEnv } = await importModule({
|
|
318
|
-
DATABASE_NAME: 'testdb',
|
|
319
|
-
MONGO_USE_SRV: 'yes',
|
|
320
|
-
});
|
|
321
|
-
const config = mod.setConfig(basePack, {
|
|
322
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
323
|
-
});
|
|
324
|
-
expect(config.mongoSettings.url).to.include('mongodb+srv://');
|
|
325
|
-
restoreEnv(savedEnv);
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it('should include auth in URL when DATABASE_USER and DATABASE_PASSWORD are set', async () => {
|
|
329
|
-
const { mod, savedEnv } = await importModule({
|
|
330
|
-
DATABASE_NAME: 'testdb',
|
|
331
|
-
DATABASE_USER: 'admin',
|
|
332
|
-
DATABASE_PASSWORD: 'secret',
|
|
333
|
-
});
|
|
334
|
-
const config = mod.setConfig(basePack, {
|
|
335
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
336
|
-
});
|
|
337
|
-
expect(config.mongoSettings.url).to.include('admin:secret@');
|
|
338
|
-
restoreEnv(savedEnv);
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('should include default pool sizes and timeouts', async () => {
|
|
342
|
-
const { mod, savedEnv } = await importModule({ DATABASE_NAME: 'testdb' });
|
|
343
|
-
const config = mod.setConfig(basePack, {
|
|
344
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
345
|
-
});
|
|
346
|
-
expect(config.mongoSettings.options.family).to.equal(4);
|
|
347
|
-
expect(config.mongoSettings.options.socketTimeoutMS).to.equal(20000);
|
|
348
|
-
expect(config.mongoSettings.options.serverSelectionTimeoutMS).to.equal(30000);
|
|
349
|
-
expect(config.mongoSettings.options.heartbeatFrequencyMS).to.equal(10000);
|
|
350
|
-
expect(config.mongoSettings.connectTimeout).to.equal(30);
|
|
351
|
-
expect(config.mongoSettings.validationCheck).to.equal(1000);
|
|
352
|
-
expect(config.mongoSettings.reconnectOffset).to.equal(5);
|
|
353
|
-
restoreEnv(savedEnv);
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it('should include SSL options in query string when MONGO_SSL is yes', async () => {
|
|
357
|
-
const { mod, savedEnv } = await importModule({
|
|
358
|
-
DATABASE_NAME: 'testdb',
|
|
359
|
-
MONGO_SSL: 'yes',
|
|
360
|
-
});
|
|
361
|
-
const config = mod.setConfig(basePack, {
|
|
362
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
363
|
-
});
|
|
364
|
-
expect(config.mongoSettings.stringOptions).to.include('ssl=true');
|
|
365
|
-
restoreEnv(savedEnv);
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
it('should set replicat flag when MONGO_REPLICAT_SET is set', async () => {
|
|
369
|
-
const { mod, savedEnv } = await importModule({
|
|
370
|
-
DATABASE_NAME: 'testdb',
|
|
371
|
-
MONGO_REPLICAT_SET: 'rs0',
|
|
372
|
-
});
|
|
373
|
-
const config = mod.setConfig(basePack, {
|
|
374
|
-
database: { type: 'mongodb', table: 'test-table' },
|
|
375
|
-
});
|
|
376
|
-
expect(config.mongoSettings.replicat).to.equal(true);
|
|
377
|
-
expect(config.mongoSettings.stringOptions).to.include('replicaSet=rs0');
|
|
378
|
-
restoreEnv(savedEnv);
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// ----------------------------------------------------------
|
|
383
|
-
// setConfig - DynamoDB
|
|
384
|
-
// ----------------------------------------------------------
|
|
385
|
-
describe('setConfig - dynamodb', () => {
|
|
386
|
-
it('should set dynamoose config with defaults', async () => {
|
|
387
|
-
const { mod, savedEnv } = await importModule();
|
|
388
|
-
const config = mod.setConfig(basePack, {
|
|
389
|
-
database: { type: 'dynamodb', table: 'test-table' },
|
|
390
|
-
});
|
|
391
|
-
expect(config.dynamoose).to.be.an('object');
|
|
392
|
-
expect(config.dynamoose.tableName).to.equal('test-table');
|
|
393
|
-
expect(config.dynamoose.region).to.equal('----noRegion----');
|
|
394
|
-
expect(config.dynamoose.url).to.equal('http://localhost:8000');
|
|
395
|
-
expect(config.dynamoose.throughput.read).to.equal(1);
|
|
396
|
-
expect(config.dynamoose.throughput.write).to.equal(1);
|
|
397
|
-
expect(config.dynamoose.schemaThroughput.read).to.equal(1);
|
|
398
|
-
expect(config.dynamoose.schemaThroughput.write).to.equal(1);
|
|
399
|
-
restoreEnv(savedEnv);
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
it('should use ON_DEMAND when DYNAMO_SCHEMA_THROUGHPUT is ON_DEMAND', async () => {
|
|
403
|
-
const { mod, savedEnv } = await importModule({ DYNAMO_SCHEMA_THROUGHPUT: 'ON_DEMAND' });
|
|
404
|
-
const config = mod.setConfig(basePack, {
|
|
405
|
-
database: { type: 'dynamodb', table: 'test-table' },
|
|
406
|
-
});
|
|
407
|
-
expect(config.dynamoose.schemaThroughput).to.equal('ON_DEMAND');
|
|
408
|
-
expect(config.dynamoose.throughput).to.equal(undefined);
|
|
409
|
-
restoreEnv(savedEnv);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it('should parse numeric DYNAMO_SCHEMA_THROUGHPUT', async () => {
|
|
413
|
-
const { mod, savedEnv } = await importModule({ DYNAMO_SCHEMA_THROUGHPUT: '10' });
|
|
414
|
-
const config = mod.setConfig(basePack, {
|
|
415
|
-
database: { type: 'dynamodb', table: 'test-table' },
|
|
416
|
-
});
|
|
417
|
-
expect(config.dynamoose.schemaThroughput).to.equal(10);
|
|
418
|
-
restoreEnv(savedEnv);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('should fallback to 1 for non-numeric DYNAMO_SCHEMA_THROUGHPUT', async () => {
|
|
422
|
-
const { mod, savedEnv } = await importModule({ DYNAMO_SCHEMA_THROUGHPUT: 'abc' });
|
|
423
|
-
const config = mod.setConfig(basePack, {
|
|
424
|
-
database: { type: 'dynamodb', table: 'test-table' },
|
|
425
|
-
});
|
|
426
|
-
expect(config.dynamoose.schemaThroughput).to.equal(1);
|
|
427
|
-
restoreEnv(savedEnv);
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it('should include AWS credentials when set', async () => {
|
|
431
|
-
const { mod, savedEnv } = await importModule({
|
|
432
|
-
DYNAMODB_AWS_ACCESS_KEY_ID: 'test-key-id',
|
|
433
|
-
DYNAMODB_AWS_SECRET_ACCESS_KEY: 'test-secret',
|
|
434
|
-
});
|
|
435
|
-
const config = mod.setConfig(basePack, {
|
|
436
|
-
database: { type: 'dynamodb', table: 'test-table' },
|
|
437
|
-
});
|
|
438
|
-
expect(config.dynamoose.accessKeyId).to.equal('test-key-id');
|
|
439
|
-
expect(config.dynamoose.secretAccessKey).to.equal('test-secret');
|
|
440
|
-
restoreEnv(savedEnv);
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
// ----------------------------------------------------------
|
|
445
|
-
// setConfig - Level DB
|
|
446
|
-
// ----------------------------------------------------------
|
|
447
|
-
describe('setConfig - level', () => {
|
|
448
|
-
it('should set levelSettings with dir and persist from options', async () => {
|
|
449
|
-
const { mod, savedEnv } = await importModule();
|
|
450
|
-
const config = mod.setConfig(basePack, {
|
|
451
|
-
database: { type: 'level', dir: '/tmp/level', persist: true },
|
|
452
|
-
});
|
|
453
|
-
expect(config.levelSettings).to.deep.equal({ dir: '/tmp/level', persist: true });
|
|
454
|
-
restoreEnv(savedEnv);
|
|
455
|
-
});
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
// ----------------------------------------------------------
|
|
459
|
-
// setConfig - unsupported database type
|
|
460
|
-
// ----------------------------------------------------------
|
|
461
|
-
describe('setConfig - unsupported database type', () => {
|
|
462
|
-
it('should throw Error for unsupported database type', async () => {
|
|
463
|
-
const { mod, savedEnv } = await importModule();
|
|
464
|
-
expect(() => mod.setConfig(basePack, {
|
|
465
|
-
database: { type: 'sqlite' },
|
|
466
|
-
})).to.throw('database type not supported: sqlite');
|
|
467
|
-
restoreEnv(savedEnv);
|
|
468
|
-
});
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
// ----------------------------------------------------------
|
|
472
|
-
// setConfig - Redis cache
|
|
473
|
-
// ----------------------------------------------------------
|
|
474
|
-
describe('setConfig - redis cache', () => {
|
|
475
|
-
it('should set redisSettings when cache.type is redis and CACHE_SET is on', async () => {
|
|
476
|
-
const { mod, savedEnv } = await importModule({
|
|
477
|
-
CACHE_SET: 'on',
|
|
478
|
-
CACHE_USER: 'user',
|
|
479
|
-
CACHE_PASSWORD: 'pass',
|
|
480
|
-
});
|
|
481
|
-
const config = mod.setConfig(basePack, {
|
|
482
|
-
cache: { type: 'redis' },
|
|
483
|
-
});
|
|
484
|
-
expect(config.redisSettings).to.be.an('object');
|
|
485
|
-
expect(config.redisSettings.domain).to.equal('localhost:6379');
|
|
486
|
-
restoreEnv(savedEnv);
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
it('should not set redisSettings when CACHE_SET is off', async () => {
|
|
490
|
-
const { mod, savedEnv } = await importModule();
|
|
491
|
-
const config = mod.setConfig(basePack, {
|
|
492
|
-
cache: { type: 'redis' },
|
|
493
|
-
});
|
|
494
|
-
expect(config.redisSettings).to.equal(undefined);
|
|
495
|
-
restoreEnv(savedEnv);
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
it('should throw for unsupported cache type', async () => {
|
|
499
|
-
const { mod, savedEnv } = await importModule({ CACHE_SET: 'on' });
|
|
500
|
-
expect(() => mod.setConfig(basePack, {
|
|
501
|
-
cache: { type: 'memcached' },
|
|
502
|
-
})).to.throw('cache type not supported: memcached');
|
|
503
|
-
restoreEnv(savedEnv);
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
it('should include auth in URL when CACHE_USER and CACHE_PASSWORD are set', async () => {
|
|
507
|
-
const { mod, savedEnv } = await importModule({
|
|
508
|
-
CACHE_SET: 'on',
|
|
509
|
-
CACHE_USER: 'redisuser',
|
|
510
|
-
CACHE_PASSWORD: 'redispass',
|
|
511
|
-
});
|
|
512
|
-
const config = mod.setConfig(basePack, {
|
|
513
|
-
cache: { type: 'redis' },
|
|
514
|
-
});
|
|
515
|
-
expect(config.redisSettings.url).to.include('redisuser:redispass@');
|
|
516
|
-
restoreEnv(savedEnv);
|
|
517
|
-
});
|
|
518
|
-
|
|
519
|
-
it('should use default TTL values', async () => {
|
|
520
|
-
const { mod, savedEnv } = await importModule({ CACHE_SET: 'on', CACHE_USER: 'user', CACHE_PASSWORD: 'pass' });
|
|
521
|
-
const config = mod.setConfig(basePack, {
|
|
522
|
-
cache: { type: 'redis' },
|
|
523
|
-
});
|
|
524
|
-
expect(config.redisSettings.api.idTTL).to.equal(20);
|
|
525
|
-
expect(config.redisSettings.api.optionTTL).to.equal(5);
|
|
526
|
-
expect(config.redisSettings.connectTimeout).to.equal(30);
|
|
527
|
-
expect(config.redisSettings.request.TTL).to.equal(10);
|
|
528
|
-
expect(config.redisSettings.validationCheck).to.equal(1000);
|
|
529
|
-
expect(config.redisSettings.reconnectOffset).to.equal(5);
|
|
530
|
-
restoreEnv(savedEnv);
|
|
531
|
-
});
|
|
532
|
-
|
|
533
|
-
it('should configure cluster settings', async () => {
|
|
534
|
-
const { mod, savedEnv } = await importModule({
|
|
535
|
-
CACHE_SET: 'on',
|
|
536
|
-
CACHE_USER: 'user',
|
|
537
|
-
CACHE_PASSWORD: 'pass',
|
|
538
|
-
CACHE_CLUSTER_SET: 'on',
|
|
539
|
-
CACHE_CLUSTER_USE_REPLICAS: 'on',
|
|
540
|
-
CACHE_CLUSTER_MINIMIZE_CONNECTION: 'on',
|
|
541
|
-
});
|
|
542
|
-
const config = mod.setConfig(basePack, {
|
|
543
|
-
cache: { type: 'redis' },
|
|
544
|
-
});
|
|
545
|
-
expect(config.redisSettings.cluster.set).to.equal('on');
|
|
546
|
-
expect(config.redisSettings.cluster.useReplicas).to.equal('on');
|
|
547
|
-
expect(config.redisSettings.cluster.minimizeConnections).to.equal('on');
|
|
548
|
-
restoreEnv(savedEnv);
|
|
549
|
-
});
|
|
550
|
-
|
|
551
|
-
it('should have a reconnectStrategy that returns interval on retry', async () => {
|
|
552
|
-
const { mod, savedEnv } = await importModule({ CACHE_SET: 'on', CACHE_USER: 'user', CACHE_PASSWORD: 'pass' });
|
|
553
|
-
const config = mod.setConfig(basePack, {
|
|
554
|
-
cache: { type: 'redis' },
|
|
555
|
-
});
|
|
556
|
-
const strategy = config.redisSettings.options.socket.reconnectStrategy;
|
|
557
|
-
const result = strategy({ timesConnected: 1, attempt: 5 });
|
|
558
|
-
expect(result).to.equal(500);
|
|
559
|
-
restoreEnv(savedEnv);
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
it('should have a reconnectStrategy that returns undefined when no retry conditions met', async () => {
|
|
563
|
-
const { mod, savedEnv } = await importModule({ CACHE_SET: 'on', CACHE_USER: 'user', CACHE_PASSWORD: 'pass' });
|
|
564
|
-
const config = mod.setConfig(basePack, {
|
|
565
|
-
cache: { type: 'redis' },
|
|
566
|
-
});
|
|
567
|
-
const strategy = config.redisSettings.options.socket.reconnectStrategy;
|
|
568
|
-
const result = strategy({ timesConnected: 0, attempt: 0 });
|
|
569
|
-
expect(result).to.equal(undefined);
|
|
570
|
-
restoreEnv(savedEnv);
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
it('should have a reconnectStrategy that calls logger.error on ECONNREFUSED', async () => {
|
|
574
|
-
resetStubs();
|
|
575
|
-
const { mod, savedEnv } = await importModule({ CACHE_SET: 'on', CACHE_USER: 'user', CACHE_PASSWORD: 'pass' });
|
|
576
|
-
const config = mod.setConfig(basePack, {
|
|
577
|
-
cache: { type: 'redis' },
|
|
578
|
-
});
|
|
579
|
-
const strategy = config.redisSettings.options.socket.reconnectStrategy;
|
|
580
|
-
strategy({ timesConnected: 0, attempt: 0, error: { code: 'ECONNREFUSED' } });
|
|
581
|
-
expect(mockLogger.error.calledOnce).to.equal(true);
|
|
582
|
-
expect(mockLogger.flushAndExit.calledOnce).to.equal(true);
|
|
583
|
-
restoreEnv(savedEnv);
|
|
584
|
-
});
|
|
585
|
-
});
|
|
586
|
-
|
|
587
|
-
// ----------------------------------------------------------
|
|
588
|
-
// setConfig - Topic
|
|
589
|
-
// ----------------------------------------------------------
|
|
590
|
-
describe('setConfig - topic', () => {
|
|
591
|
-
it('should set topicSettings when topic is provided and TOPIC_SET is on', async () => {
|
|
592
|
-
const { mod, savedEnv } = await importModule({ TOPIC_SET: 'on' });
|
|
593
|
-
const config = mod.setConfig(basePack, {
|
|
594
|
-
topic: { name: 'test-topic' },
|
|
595
|
-
});
|
|
596
|
-
expect(config.topicSettings).to.be.an('object');
|
|
597
|
-
expect(config.topicSettings.name).to.equal('test-topic');
|
|
598
|
-
expect(config.topicSettings.region).to.equal('----noRegion----');
|
|
599
|
-
restoreEnv(savedEnv);
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
it('should not set topicSettings when TOPIC_SET is off', async () => {
|
|
603
|
-
const { mod, savedEnv } = await importModule();
|
|
604
|
-
const config = mod.setConfig(basePack, {
|
|
605
|
-
topic: { name: 'test-topic' },
|
|
606
|
-
});
|
|
607
|
-
expect(config.topicSettings).to.equal(undefined);
|
|
608
|
-
restoreEnv(savedEnv);
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
it('should set isFifoTopic when SET_SNS_TOPIC_FIFO is yes', async () => {
|
|
612
|
-
const { mod, savedEnv } = await importModule({
|
|
613
|
-
TOPIC_SET: 'on',
|
|
614
|
-
SET_SNS_TOPIC_FIFO: 'yes',
|
|
615
|
-
});
|
|
616
|
-
const config = mod.setConfig(basePack, {
|
|
617
|
-
topic: { name: 'test-topic' },
|
|
618
|
-
});
|
|
619
|
-
expect(config.topicSettings.isFifoTopic).to.equal(true);
|
|
620
|
-
restoreEnv(savedEnv);
|
|
621
|
-
});
|
|
622
|
-
|
|
623
|
-
it('should set contentBasedDeduplication when fifo and SET_SNS_CONTENT_DEDUPLICATION is yes', async () => {
|
|
624
|
-
const { mod, savedEnv } = await importModule({
|
|
625
|
-
TOPIC_SET: 'on',
|
|
626
|
-
SET_SNS_TOPIC_FIFO: 'yes',
|
|
627
|
-
SET_SNS_CONTENT_DEDUPLICATION: 'yes',
|
|
628
|
-
});
|
|
629
|
-
const config = mod.setConfig(basePack, {
|
|
630
|
-
topic: { name: 'test-topic' },
|
|
631
|
-
});
|
|
632
|
-
expect(config.topicSettings.contentBasedDeduplication).to.equal(true);
|
|
633
|
-
restoreEnv(savedEnv);
|
|
634
|
-
});
|
|
635
|
-
|
|
636
|
-
it('should include AWS credentials when set', async () => {
|
|
637
|
-
const { mod, savedEnv } = await importModule({
|
|
638
|
-
TOPIC_SET: 'on',
|
|
639
|
-
SNS_AWS_ACCESS_KEY_ID: 'sns-key',
|
|
640
|
-
SNS_AWS_SECRET_ACCESS_KEY: 'sns-secret',
|
|
641
|
-
});
|
|
642
|
-
const config = mod.setConfig(basePack, {
|
|
643
|
-
topic: { name: 'test-topic' },
|
|
644
|
-
});
|
|
645
|
-
expect(config.topicSettings.accessKeyId).to.equal('sns-key');
|
|
646
|
-
expect(config.topicSettings.secretAccessKey).to.equal('sns-secret');
|
|
647
|
-
restoreEnv(savedEnv);
|
|
648
|
-
});
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
// ----------------------------------------------------------
|
|
652
|
-
// setConfig - Encryption
|
|
653
|
-
// ----------------------------------------------------------
|
|
654
|
-
describe('setConfig - encryption', () => {
|
|
655
|
-
it('should setup encryption when ENCRYPTION_SET is on', async () => {
|
|
656
|
-
const { mod, savedEnv } = await importModule({
|
|
657
|
-
ENCRYPTION_SET: 'on',
|
|
658
|
-
ENCRYPTION_DATABASE: 'admin',
|
|
659
|
-
KEY_VAULT_TABLE: 'keystore',
|
|
660
|
-
LOCAL_MASTER_KEY: 'test-local-master-key',
|
|
661
|
-
});
|
|
662
|
-
const config = mod.setConfig(basePack, {
|
|
663
|
-
encryption: { set: 'on', keys: {} },
|
|
664
|
-
});
|
|
665
|
-
expect(config.encryption).to.be.an('object');
|
|
666
|
-
expect(config.encryption.database).to.equal('admin');
|
|
667
|
-
expect(config.encryption.keyVaultTable).to.equal('keystore');
|
|
668
|
-
expect(config.encryption.kmsProvider).to.equal('local');
|
|
669
|
-
restoreEnv(savedEnv);
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
it('should configure AWS KMS when kmsProvider is aws', async () => {
|
|
673
|
-
const { mod, savedEnv } = await importModule({
|
|
674
|
-
ENCRYPTION_SET: 'on',
|
|
675
|
-
ENCRYPTION_DATABASE: 'admin',
|
|
676
|
-
KEY_VAULT_TABLE: 'keystore',
|
|
677
|
-
KMS_PROVIDER: 'aws',
|
|
678
|
-
MASTER_KEY_AWS_REGION: 'us-east-1',
|
|
679
|
-
MASTER_KEY_ARN: 'arn:aws:kms:us-east-1:123:key/abc',
|
|
680
|
-
ENCRYPTION_ACCESS_KEY_ID: 'enc-key',
|
|
681
|
-
ENCRYPTION_SECRET_ACCESS_KEY: 'enc-secret',
|
|
682
|
-
});
|
|
683
|
-
const config = mod.setConfig(basePack, {
|
|
684
|
-
encryption: { set: 'on', keys: {} },
|
|
685
|
-
});
|
|
686
|
-
expect(config.encryption.kmsProvider).to.equal('aws');
|
|
687
|
-
expect(config.encryption.region).to.equal('us-east-1');
|
|
688
|
-
expect(config.encryption.masterKeyARN).to.equal('arn:aws:kms:us-east-1:123:key/abc');
|
|
689
|
-
expect(config.encryption.aws.accessKeyId).to.equal('enc-key');
|
|
690
|
-
expect(config.encryption.aws.secretAccessKey).to.equal('enc-secret');
|
|
691
|
-
restoreEnv(savedEnv);
|
|
692
|
-
});
|
|
693
|
-
|
|
694
|
-
it('should use local master key when kmsProvider is local', async () => {
|
|
695
|
-
const { mod, savedEnv } = await importModule({
|
|
696
|
-
ENCRYPTION_SET: 'on',
|
|
697
|
-
ENCRYPTION_DATABASE: 'admin',
|
|
698
|
-
KEY_VAULT_TABLE: 'keystore',
|
|
699
|
-
LOCAL_MASTER_KEY: 'local-master-key-value',
|
|
700
|
-
});
|
|
701
|
-
const config = mod.setConfig(basePack, {
|
|
702
|
-
encryption: { set: 'on', keys: {} },
|
|
703
|
-
});
|
|
704
|
-
expect(config.encryption.localMasterKey).to.equal('local-master-key-value');
|
|
705
|
-
restoreEnv(savedEnv);
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
it('should include encryption keys when provided', async () => {
|
|
709
|
-
const { mod, savedEnv } = await importModule({
|
|
710
|
-
ENCRYPTION_SET: 'on',
|
|
711
|
-
ENCRYPTION_DATABASE: 'admin',
|
|
712
|
-
KEY_VAULT_TABLE: 'keystore',
|
|
713
|
-
LOCAL_MASTER_KEY: 'test-local-master-key',
|
|
714
|
-
});
|
|
715
|
-
const keys = { field1: 'keyId1', field2: 'keyId2' };
|
|
716
|
-
const config = mod.setConfig(basePack, {
|
|
717
|
-
encryption: { set: 'on', keys },
|
|
718
|
-
});
|
|
719
|
-
expect(config.encryption.keys).to.deep.equal(keys);
|
|
720
|
-
restoreEnv(savedEnv);
|
|
721
|
-
});
|
|
722
|
-
});
|
|
723
|
-
|
|
724
|
-
// ----------------------------------------------------------
|
|
725
|
-
// setConfig - User Definitions
|
|
726
|
-
// ----------------------------------------------------------
|
|
727
|
-
describe('setConfig - userDefinitions', () => {
|
|
728
|
-
it('should return default userDefinitions when file is "not set"', async () => {
|
|
729
|
-
const { mod, savedEnv } = await importModule();
|
|
730
|
-
const config = mod.setConfig(basePack, {
|
|
731
|
-
userDefinitions: { file: 'not set' },
|
|
732
|
-
});
|
|
733
|
-
expect(config.userDefinitions.file).to.equal('not set');
|
|
734
|
-
expect(config.userDefinitions.all).to.deep.equal(mockUserDefinitions.all);
|
|
735
|
-
restoreEnv(savedEnv);
|
|
736
|
-
});
|
|
737
|
-
|
|
738
|
-
it('should merge custom definitions from a valid JSON file', async () => {
|
|
739
|
-
const customDefs = { custom: { attributes: ['email'] } };
|
|
740
|
-
const mod = await esmock('../index.js', {
|
|
741
|
-
'@mimik/sumologic-winston-logger': { default: mockLogger },
|
|
742
|
-
'@mimik/request-helper': { getCorrelationId: mockGetCorrelationId },
|
|
743
|
-
'@mimik/user-filters': { userDefinitions: mockUserDefinitions },
|
|
744
|
-
'ip': { address: mockIpAddress },
|
|
745
|
-
'node:fs': {
|
|
746
|
-
readFileSync: stub().returns(Buffer.from(JSON.stringify(customDefs))),
|
|
747
|
-
},
|
|
748
|
-
});
|
|
749
|
-
const config = mod.setConfig(basePack, {
|
|
750
|
-
userDefinitions: { file: '/path/to/definitions.json' },
|
|
751
|
-
});
|
|
752
|
-
expect(config.userDefinitions.custom).to.deep.equal(customDefs.custom);
|
|
753
|
-
expect(config.userDefinitions.file).to.equal('/path/to/definitions.json');
|
|
754
|
-
});
|
|
755
|
-
|
|
756
|
-
it('should throw Error when file read fails', async () => {
|
|
757
|
-
const mod = await esmock('../index.js', {
|
|
758
|
-
'@mimik/sumologic-winston-logger': { default: mockLogger },
|
|
759
|
-
'@mimik/request-helper': { getCorrelationId: mockGetCorrelationId },
|
|
760
|
-
'@mimik/user-filters': { userDefinitions: mockUserDefinitions },
|
|
761
|
-
'ip': { address: mockIpAddress },
|
|
762
|
-
'node:fs': {
|
|
763
|
-
readFileSync: stub().throws(new Error('ENOENT: no such file')),
|
|
764
|
-
},
|
|
765
|
-
});
|
|
766
|
-
expect(() => mod.setConfig(basePack, {
|
|
767
|
-
userDefinitions: { file: '/bad/path.json' },
|
|
768
|
-
})).to.throw('Invalid file for user definitions');
|
|
769
|
-
});
|
|
770
|
-
});
|
|
771
|
-
|
|
772
|
-
// ----------------------------------------------------------
|
|
773
|
-
// setConfig - Dependencies
|
|
774
|
-
// ----------------------------------------------------------
|
|
775
|
-
describe('setConfig - dependencies', () => {
|
|
776
|
-
it('should merge dependencies when isMSTSet is true', async () => {
|
|
777
|
-
const { mod, savedEnv } = await importModule();
|
|
778
|
-
const config = mod.setConfig(basePack, {
|
|
779
|
-
dependencies: {
|
|
780
|
-
mCustom: { url: 'http://custom:8080', audience: 'custom-aud' },
|
|
781
|
-
},
|
|
782
|
-
});
|
|
783
|
-
expect(config.dependencies.mCustom).to.deep.equal({
|
|
784
|
-
url: 'http://custom:8080',
|
|
785
|
-
audience: 'custom-aud',
|
|
786
|
-
});
|
|
787
|
-
restoreEnv(savedEnv);
|
|
788
|
-
});
|
|
789
|
-
|
|
790
|
-
it('should only include url and apiKey when isMSTSet is false and apiKey exists', async () => {
|
|
791
|
-
const { mod, savedEnv } = await importModule({
|
|
792
|
-
MST_SET: 'off',
|
|
793
|
-
API_KEYS: 'testKey1',
|
|
794
|
-
});
|
|
795
|
-
const config = mod.setConfig(basePack, {
|
|
796
|
-
dependencies: {
|
|
797
|
-
mCustom: { url: 'http://custom:8080', apiKey: 'key123', audience: 'custom-aud' },
|
|
798
|
-
},
|
|
799
|
-
});
|
|
800
|
-
expect(config.dependencies.mCustom).to.deep.equal({
|
|
801
|
-
url: 'http://custom:8080',
|
|
802
|
-
apiKey: 'key123',
|
|
803
|
-
});
|
|
804
|
-
restoreEnv(savedEnv);
|
|
805
|
-
});
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
// ----------------------------------------------------------
|
|
809
|
-
// setConfig - Custom and Security
|
|
810
|
-
// ----------------------------------------------------------
|
|
811
|
-
describe('setConfig - custom options', () => {
|
|
812
|
-
it('should merge custom properties into configuration', async () => {
|
|
813
|
-
const { mod, savedEnv } = await importModule();
|
|
814
|
-
const config = mod.setConfig(basePack, {
|
|
815
|
-
custom: { myCustomProp: { key: 'value' } },
|
|
816
|
-
});
|
|
817
|
-
expect(config.myCustomProp).to.deep.equal({ key: 'value' });
|
|
818
|
-
restoreEnv(savedEnv);
|
|
819
|
-
});
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
describe('setConfig - security options', () => {
|
|
823
|
-
it('should merge into existing security sections', async () => {
|
|
824
|
-
const { mod, savedEnv } = await importModule();
|
|
825
|
-
const config = mod.setConfig(basePack, {
|
|
826
|
-
security: { admin: { role: 'superadmin' } },
|
|
827
|
-
});
|
|
828
|
-
expect(config.security.admin.role).to.equal('superadmin');
|
|
829
|
-
expect(config.security.admin.externalId).to.equal('admin');
|
|
830
|
-
restoreEnv(savedEnv);
|
|
831
|
-
});
|
|
832
|
-
|
|
833
|
-
it('should add new security sections', async () => {
|
|
834
|
-
const { mod, savedEnv } = await importModule();
|
|
835
|
-
const config = mod.setConfig(basePack, {
|
|
836
|
-
security: { customAuth: { provider: 'oauth2' } },
|
|
837
|
-
});
|
|
838
|
-
expect(config.security.customAuth).to.deep.equal({ provider: 'oauth2' });
|
|
839
|
-
restoreEnv(savedEnv);
|
|
840
|
-
});
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
// ----------------------------------------------------------
|
|
844
|
-
// setConfig - MST_SET off
|
|
845
|
-
// ----------------------------------------------------------
|
|
846
|
-
describe('setConfig - MST_SET off', () => {
|
|
847
|
-
it('should disable registration and cluster when MST_SET is off', async () => {
|
|
848
|
-
const { mod, savedEnv } = await importModule({
|
|
849
|
-
MST_SET: 'off',
|
|
850
|
-
API_KEYS: 'testKey1',
|
|
851
|
-
});
|
|
852
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
853
|
-
expect(config.registration.set).to.equal('off');
|
|
854
|
-
expect(config.cluster.management).to.equal('off');
|
|
855
|
-
restoreEnv(savedEnv);
|
|
856
|
-
});
|
|
857
|
-
|
|
858
|
-
it('should clear security.server when MST_SET is off', async () => {
|
|
859
|
-
const { mod, savedEnv } = await importModule({
|
|
860
|
-
MST_SET: 'off',
|
|
861
|
-
API_KEYS: 'testKey1',
|
|
862
|
-
});
|
|
863
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
864
|
-
expect(config.security.server).to.deep.equal({});
|
|
865
|
-
restoreEnv(savedEnv);
|
|
866
|
-
});
|
|
867
|
-
|
|
868
|
-
it('should throw when MST_SET is off and apiKeys is empty', async () => {
|
|
869
|
-
const { mod, savedEnv } = await importModule({
|
|
870
|
-
MST_SET: 'off',
|
|
871
|
-
API_KEYS: undefined,
|
|
872
|
-
});
|
|
873
|
-
expect(() => mod.setConfig(basePack, baseOptions))
|
|
874
|
-
.to.throw('Errors in configuration');
|
|
875
|
-
restoreEnv(savedEnv);
|
|
876
|
-
});
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
// ----------------------------------------------------------
|
|
880
|
-
// setupLog (called during module load)
|
|
881
|
-
// ----------------------------------------------------------
|
|
882
|
-
describe('setupLog', () => {
|
|
883
|
-
it('should default to sumologic mode', async () => {
|
|
884
|
-
const { mod, savedEnv } = await importModule({
|
|
885
|
-
LOG_MODE: 'sumologic',
|
|
886
|
-
SUMO_LOGIC_ENDPOINT: 'https://sumo.test',
|
|
887
|
-
SUMO_LOGIC_COLLECTOR_CODE: 'collector-123',
|
|
888
|
-
});
|
|
889
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
890
|
-
expect(config.logInfo.mode).to.equal('sumologic');
|
|
891
|
-
expect(config.logInfo.sumologic).to.be.an('object');
|
|
892
|
-
restoreEnv(savedEnv);
|
|
893
|
-
});
|
|
894
|
-
|
|
895
|
-
it('should include awsS3 config when LOG_MODE is awsS3', async () => {
|
|
896
|
-
const { mod, savedEnv } = await importModule({
|
|
897
|
-
LOG_MODE: 'awsS3',
|
|
898
|
-
S3_AWS_REGION: 'us-east-1',
|
|
899
|
-
S3_AWS_BUCKET_NAME: 'test-bucket',
|
|
900
|
-
});
|
|
901
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
902
|
-
expect(config.logInfo.mode).to.equal('awsS3');
|
|
903
|
-
expect(config.logInfo.awsS3).to.be.an('object');
|
|
904
|
-
expect(config.logInfo.sumologic).to.equal(undefined);
|
|
905
|
-
restoreEnv(savedEnv);
|
|
906
|
-
});
|
|
907
|
-
|
|
908
|
-
it('should include both sumologic and awsS3 when LOG_MODE is all', async () => {
|
|
909
|
-
const { mod, savedEnv } = await importModule({
|
|
910
|
-
LOG_MODE: 'all',
|
|
911
|
-
SUMO_LOGIC_ENDPOINT: 'https://sumo.test',
|
|
912
|
-
SUMO_LOGIC_COLLECTOR_CODE: 'collector-123',
|
|
913
|
-
S3_AWS_REGION: 'us-east-1',
|
|
914
|
-
S3_AWS_BUCKET_NAME: 'test-bucket',
|
|
915
|
-
});
|
|
916
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
917
|
-
expect(config.logInfo.mode).to.equal('all');
|
|
918
|
-
expect(config.logInfo.sumologic).to.be.an('object');
|
|
919
|
-
expect(config.logInfo.awsS3).to.be.an('object');
|
|
920
|
-
restoreEnv(savedEnv);
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
it('should include S3 AWS credentials when set', async () => {
|
|
924
|
-
const { mod, savedEnv } = await importModule({
|
|
925
|
-
LOG_MODE: 'awsS3',
|
|
926
|
-
S3_AWS_REGION: 'us-east-1',
|
|
927
|
-
S3_AWS_BUCKET_NAME: 'test-bucket',
|
|
928
|
-
S3_AWS_ACCESS_KEY_ID: 's3-key',
|
|
929
|
-
S3_AWS_SECRET_ACCESS_KEY: 's3-secret',
|
|
930
|
-
});
|
|
931
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
932
|
-
expect(config.logInfo.awsS3.accessKeyId).to.equal('s3-key');
|
|
933
|
-
expect(config.logInfo.awsS3.secretAccessKey).to.equal('s3-secret');
|
|
934
|
-
restoreEnv(savedEnv);
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
it('should use default exit delay and noStack', async () => {
|
|
938
|
-
const { mod, savedEnv } = await importModule();
|
|
939
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
940
|
-
expect(config.logInfo.exitDelay).to.equal(2000);
|
|
941
|
-
expect(config.logInfo.noStack).to.equal('yes');
|
|
942
|
-
restoreEnv(savedEnv);
|
|
943
|
-
});
|
|
944
|
-
});
|
|
945
|
-
|
|
946
|
-
// ----------------------------------------------------------
|
|
947
|
-
// setupLocationProvider (called during module load)
|
|
948
|
-
// ----------------------------------------------------------
|
|
949
|
-
describe('setupLocationProvider', () => {
|
|
950
|
-
it('should return noPublic when LOCATION_PROVIDER is not set', async () => {
|
|
951
|
-
const { mod, savedEnv } = await importModule();
|
|
952
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
953
|
-
expect(config.locationProvider).to.equal('noPublic');
|
|
954
|
-
restoreEnv(savedEnv);
|
|
955
|
-
});
|
|
956
|
-
|
|
957
|
-
it('should return "environment" when LOCATION_PROVIDER is "environment"', async () => {
|
|
958
|
-
const { mod, savedEnv } = await importModule({ LOCATION_PROVIDER: 'environment' });
|
|
959
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
960
|
-
expect(config.locationProvider).to.equal('environment');
|
|
961
|
-
restoreEnv(savedEnv);
|
|
962
|
-
});
|
|
963
|
-
|
|
964
|
-
it('should return URL object when LOCATION_PROVIDER is a custom URL', async () => {
|
|
965
|
-
const { mod, savedEnv } = await importModule({ LOCATION_PROVIDER: 'https://geo.api.com' });
|
|
966
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
967
|
-
expect(config.locationProvider).to.deep.equal({ url: 'https://geo.api.com' });
|
|
968
|
-
restoreEnv(savedEnv);
|
|
969
|
-
});
|
|
970
|
-
|
|
971
|
-
it('should include key when LOCATION_PROVIDER_KEY is set', async () => {
|
|
972
|
-
const { mod, savedEnv } = await importModule({
|
|
973
|
-
LOCATION_PROVIDER: 'https://geo.api.com',
|
|
974
|
-
LOCATION_PROVIDER_KEY: 'abc123',
|
|
975
|
-
});
|
|
976
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
977
|
-
expect(config.locationProvider).to.deep.equal({
|
|
978
|
-
url: 'https://geo.api.com',
|
|
979
|
-
key: 'abc123',
|
|
980
|
-
});
|
|
981
|
-
restoreEnv(savedEnv);
|
|
982
|
-
});
|
|
983
|
-
});
|
|
984
|
-
|
|
985
|
-
// ----------------------------------------------------------
|
|
986
|
-
// checkConfig
|
|
987
|
-
// ----------------------------------------------------------
|
|
988
|
-
describe('checkConfig', () => {
|
|
989
|
-
it('should not throw when all required values are present', async () => {
|
|
990
|
-
const { mod, savedEnv } = await importModule();
|
|
991
|
-
expect(() => mod.setConfig(basePack, baseOptions)).to.not.throw();
|
|
992
|
-
restoreEnv(savedEnv);
|
|
993
|
-
});
|
|
994
|
-
|
|
995
|
-
it('should throw when required configuration values are undefined', async () => {
|
|
996
|
-
const { mod, savedEnv } = await importModule({
|
|
997
|
-
OAUTH_CLIENT_ID: undefined,
|
|
998
|
-
});
|
|
999
|
-
resetStubs();
|
|
1000
|
-
expect(() => mod.setConfig(basePack, baseOptions))
|
|
1001
|
-
.to.throw('Errors in configuration');
|
|
1002
|
-
expect(mockLogger.error.calledOnce).to.equal(true);
|
|
1003
|
-
restoreEnv(savedEnv);
|
|
1004
|
-
});
|
|
1005
|
-
});
|
|
1006
|
-
|
|
1007
|
-
// ----------------------------------------------------------
|
|
1008
|
-
// Conditional config properties
|
|
1009
|
-
// ----------------------------------------------------------
|
|
1010
|
-
describe('Conditional configuration properties', () => {
|
|
1011
|
-
it('should include apiBasicAuth when BITBUCKET_USERNAME is set', async () => {
|
|
1012
|
-
const { mod, savedEnv } = await importModule({
|
|
1013
|
-
BITBUCKET_USERNAME: 'testuser',
|
|
1014
|
-
BITBUCKET_PASSWORD: 'testpass',
|
|
1015
|
-
});
|
|
1016
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
1017
|
-
expect(config.serverSettings.apiBasicAuth).to.deep.equal({
|
|
1018
|
-
username: 'testuser',
|
|
1019
|
-
password: 'testpass',
|
|
1020
|
-
});
|
|
1021
|
-
restoreEnv(savedEnv);
|
|
1022
|
-
});
|
|
1023
|
-
|
|
1024
|
-
it('should include apiApiKey when SWAGGERHUB_API_KEY is set', async () => {
|
|
1025
|
-
const { mod, savedEnv } = await importModule({ SWAGGERHUB_API_KEY: 'test-key' });
|
|
1026
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
1027
|
-
expect(config.serverSettings.apiApiKey).to.equal('test-key');
|
|
1028
|
-
restoreEnv(savedEnv);
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
it('should include generic.previousKey when OAUTH_GENERIC_PREVIOUS_KEY is set', async () => {
|
|
1032
|
-
const { mod, savedEnv } = await importModule({ OAUTH_GENERIC_PREVIOUS_KEY: 'prev-key' });
|
|
1033
|
-
const config = mod.setConfig(basePack, baseOptions);
|
|
1034
|
-
expect(config.security.generic.previousKey).to.equal('prev-key');
|
|
1035
|
-
restoreEnv(savedEnv);
|
|
1036
|
-
});
|
|
1037
|
-
});
|
|
1038
|
-
});
|
package/test/testEnv.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/* eslint no-process-env: "off" */
|
|
2
|
-
import process from 'node:process';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The following environment variables are set for the test:
|
|
6
|
-
*
|
|
7
|
-
* | Env variable name | Description | Default | Comments |
|
|
8
|
-
* | ----------------- | ----------- | ------- | -------- |
|
|
9
|
-
* | SUMO_LOGIC_ENDPOINT | endpoint to use to log on sumologic | null
|
|
10
|
-
* | SUMO_LOGIC_COLLECTOR_CODE | code to use to log on sumologic | null
|
|
11
|
-
* | NO_STACK | flag to have a stack associated with the log | yes
|
|
12
|
-
* | LOG_LEVEL | log level to log | error
|
|
13
|
-
* | CONSOLE_LEVEL | log level to display | debug
|
|
14
|
-
* | LOG_MODE | log mode | none
|
|
15
|
-
* | MST_SET | to setup configuration without mST | on
|
|
16
|
-
* | API_KEYS | list of API Keys | testKey1,testKey2
|
|
17
|
-
* | SERVER_PORT | port of the server | 3000
|
|
18
|
-
* | OAUTH_CLIENT_ID | security id | test-client-id
|
|
19
|
-
* | OAUTH_CLIENT_SECRET | secret | test-client-secret
|
|
20
|
-
* | OAUTH_CLIENT_ACCESS_KEY | access key | test-access-key
|
|
21
|
-
* | OAUTH_CLIENT_AUDIENCE | audience | test-audience
|
|
22
|
-
* | OAUTH_ISSUER | issuer | test-issuer
|
|
23
|
-
* | MIT_URL | mIT URL | http://localhost:8080
|
|
24
|
-
* | MIT_AUDIENCE | mIT audience | test-mit-audience
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
delete process.env.SUMO_LOGIC_ENDPOINT;
|
|
28
|
-
delete process.env.SUMO_LOGIC_COLLECTOR_CODE;
|
|
29
|
-
process.env.NO_STACK = 'yes';
|
|
30
|
-
process.env.LOG_LEVEL = 'error';
|
|
31
|
-
process.env.LOG_MODE = 'none';
|
|
32
|
-
process.env.CONSOLE_LEVEL = 'debug';
|
|
33
|
-
|
|
34
|
-
process.env.MST_SET = 'on';
|
|
35
|
-
process.env.API_KEYS = 'testKey1,testKey2';
|
|
36
|
-
process.env.SERVER_PORT = '3000';
|
|
37
|
-
process.env.OAUTH_CLIENT_ID = 'test-client-id';
|
|
38
|
-
process.env.OAUTH_CLIENT_SECRET = 'test-client-secret';
|
|
39
|
-
process.env.OAUTH_CLIENT_ACCESS_KEY = 'test-access-key';
|
|
40
|
-
process.env.OAUTH_CLIENT_AUDIENCE = 'test-audience';
|
|
41
|
-
process.env.OAUTH_ISSUER = 'test-issuer';
|
|
42
|
-
process.env.MIT_URL = 'http://localhost:8080';
|
|
43
|
-
process.env.MIT_AUDIENCE = 'test-mit-audience';
|
|
44
|
-
|
|
45
|
-
// Server type audience for basePack.mimik.type = 'mTest'
|
|
46
|
-
process.env.MTEST_AUDIENCE = 'test-mtest-audience';
|