@mimik/oauth-helper 3.0.1 → 4.0.0
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/.husky/pre-commit +1 -4
- package/.husky/pre-push +1 -4
- package/eslint.config.js +64 -0
- package/index.js +28 -15
- package/package.json +23 -26
- package/test/oauthHelper.spec.js +29 -30
- package/test/serversMock.js +48 -36
- package/test/testConfig.js +1 -1
- package/test/testEnv.js +1 -0
- package/.eslintrc +0 -43
package/.husky/pre-commit
CHANGED
package/.husky/pre-push
CHANGED
package/eslint.config.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import importPlugin from 'eslint-plugin-import';
|
|
2
|
+
import js from '@eslint/js';
|
|
3
|
+
import processDoc from '@mimik/eslint-plugin-document-env';
|
|
4
|
+
import stylistic from '@stylistic/eslint-plugin';
|
|
5
|
+
|
|
6
|
+
const MAX_LENGTH_LINE = 180;
|
|
7
|
+
const MAX_FUNCTION_PARAMETERS = 6;
|
|
8
|
+
const MAX_LINES_IN_FILES = 600;
|
|
9
|
+
const MAX_LINES_IN_FUNCTION = 150;
|
|
10
|
+
const MAX_STATEMENTS_IN_FUNCTION = 45;
|
|
11
|
+
const MIN_KEYS_IN_OBJECT = 10;
|
|
12
|
+
const MAX_COMPLEXITY = 30;
|
|
13
|
+
|
|
14
|
+
export default [
|
|
15
|
+
{
|
|
16
|
+
ignores: ['mochawesome-report/**', 'node_modules/**', 'dist/**'],
|
|
17
|
+
},
|
|
18
|
+
importPlugin.flatConfigs.recommended,
|
|
19
|
+
stylistic.configs['recommended-flat'],
|
|
20
|
+
js.configs.all,
|
|
21
|
+
{
|
|
22
|
+
plugins: {
|
|
23
|
+
processDoc,
|
|
24
|
+
},
|
|
25
|
+
languageOptions: {
|
|
26
|
+
ecmaVersion: 2022,
|
|
27
|
+
globals: {
|
|
28
|
+
console: 'readonly',
|
|
29
|
+
describe: 'readonly',
|
|
30
|
+
it: 'readonly',
|
|
31
|
+
require: 'readonly',
|
|
32
|
+
},
|
|
33
|
+
sourceType: 'module',
|
|
34
|
+
},
|
|
35
|
+
rules: {
|
|
36
|
+
'@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
|
|
37
|
+
'@stylistic/line-comment-position': ['off'],
|
|
38
|
+
'@stylistic/semi': ['error', 'always'],
|
|
39
|
+
'capitalized-comments': ['off'],
|
|
40
|
+
'complexity': ['error', MAX_COMPLEXITY],
|
|
41
|
+
'curly': ['off'],
|
|
42
|
+
'id-length': ['error', { exceptions: ['x', 'y', 'z', 'i', 'j', 'k'] }],
|
|
43
|
+
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
|
|
44
|
+
'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
|
|
45
|
+
'init-declarations': ['off'],
|
|
46
|
+
'linebreak-style': ['off'],
|
|
47
|
+
'max-depth': ['warn', { max: 5 }],
|
|
48
|
+
'max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true }],
|
|
49
|
+
'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true }],
|
|
50
|
+
'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true }],
|
|
51
|
+
'max-params': ['error', MAX_FUNCTION_PARAMETERS],
|
|
52
|
+
'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
|
|
53
|
+
'no-confusing-arrow': ['off'], // arrow isnt confusing
|
|
54
|
+
'no-inline-comments': ['off'],
|
|
55
|
+
'no-process-env': ['error'],
|
|
56
|
+
'no-ternary': ['off'],
|
|
57
|
+
'no-undefined': ['off'],
|
|
58
|
+
'one-var': ['error', 'never'],
|
|
59
|
+
'processDoc/validate-document-env': ['error'],
|
|
60
|
+
'quotes': ['warn', 'single'],
|
|
61
|
+
'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false }],
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
];
|
package/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/* eslint camelcase: ["error", { properties: "never" }] */
|
|
2
|
+
import Promise from 'bluebird';
|
|
3
|
+
import { URL } from 'url';
|
|
4
|
+
import { getRichError } from '@mimik/response-helper';
|
|
5
|
+
import jwt from 'jsonwebtoken';
|
|
6
|
+
import logger from '@mimik/sumologic-winston-logger';
|
|
7
|
+
import process from 'process';
|
|
8
|
+
import { rpRetry } from '@mimik/request-retry';
|
|
7
9
|
|
|
8
10
|
Promise.config({ cancellation: true });
|
|
9
11
|
/**
|
|
@@ -17,11 +19,20 @@ const CLUSTER = 'cluster';
|
|
|
17
19
|
const CLIENT_CEDENTIALS = 'client_credentials';
|
|
18
20
|
const REFRESH_TOKEN = 'refresh_token';
|
|
19
21
|
|
|
22
|
+
const PARAMETER_ERROR = 400;
|
|
23
|
+
const FORBIDDEN_ERROR = 403;
|
|
24
|
+
const OK = 200;
|
|
25
|
+
const MILLI_SECONDS = 0;
|
|
26
|
+
const MILLI_NANO_SECONDS = 1;
|
|
27
|
+
const MILLI = 1000;
|
|
28
|
+
const NANO = 1e6;
|
|
29
|
+
const ZERO = 0;
|
|
30
|
+
|
|
20
31
|
const tokens = {};
|
|
21
32
|
|
|
22
33
|
const valid = (token) => {
|
|
23
34
|
if (!token) return false;
|
|
24
|
-
if (token.exp - (Math.floor(Date.now() /
|
|
35
|
+
if (token.exp - (Math.floor(Date.now() / MILLI) + TOKEN_REFRESH_TOLERANCE) < ZERO) return false;
|
|
25
36
|
return true;
|
|
26
37
|
};
|
|
27
38
|
|
|
@@ -33,7 +44,7 @@ const createToken = (value) => {
|
|
|
33
44
|
return token;
|
|
34
45
|
};
|
|
35
46
|
|
|
36
|
-
|
|
47
|
+
export default (config) => {
|
|
37
48
|
const { server } = config.security;
|
|
38
49
|
const getToken = (type, origin, correlationId, options) => {
|
|
39
50
|
const tokenOptions = {
|
|
@@ -81,7 +92,7 @@ module.exports = (config) => {
|
|
|
81
92
|
}
|
|
82
93
|
}
|
|
83
94
|
return rpRetry(tokenOptions).catch((err) => {
|
|
84
|
-
if (err.statusCode !==
|
|
95
|
+
if (err.statusCode !== PARAMETER_ERROR || tokenOptions.body.grant_type === CLIENT_CEDENTIALS) {
|
|
85
96
|
throw err;
|
|
86
97
|
}
|
|
87
98
|
logger.silly(`moving from ${REFRESH_TOKEN} to ${CLIENT_CEDENTIALS}`, { error: err.message }, correlationId);
|
|
@@ -132,7 +143,7 @@ module.exports = (config) => {
|
|
|
132
143
|
const measure = (statusCode) => {
|
|
133
144
|
if (metrics && metrics.HTTPRequestDuration) {
|
|
134
145
|
const elapsedHrTime = process.hrtime(startHrTime);
|
|
135
|
-
const elapsedTimeInMs = elapsedHrTime[
|
|
146
|
+
const elapsedTimeInMs = elapsedHrTime[MILLI_SECONDS] * MILLI + elapsedHrTime[MILLI_NANO_SECONDS] / NANO;
|
|
136
147
|
|
|
137
148
|
metrics.HTTPRequestDuration
|
|
138
149
|
.labels('rpAuth', options.method, metrics.url || enteredUrl, enteredUrl.includes('?'), statusCode)
|
|
@@ -144,7 +155,9 @@ module.exports = (config) => {
|
|
|
144
155
|
if (!type) return Promise.reject(new Error(`rpAuth type non existent for ${options.method || 'GET'} on ${enteredUrl}`));
|
|
145
156
|
if (!config.dependencies[type]) return Promise.reject(new Error(`type ${type} used in rpAuth with no dependencies`));
|
|
146
157
|
if (!options.url && !options.uri) return Promise.reject(new Error('uri or url non existent'));
|
|
147
|
-
try {
|
|
158
|
+
try {
|
|
159
|
+
url = new URL(enteredUrl);
|
|
160
|
+
}
|
|
148
161
|
catch (err) { return Promise.reject(new Error(`invalid url address: ${enteredUrl}: ${err.message}`)); }
|
|
149
162
|
const correlationId = (options.headers && options.headers['x-correlation-id']);
|
|
150
163
|
|
|
@@ -156,11 +169,11 @@ module.exports = (config) => {
|
|
|
156
169
|
opts.headers.authorization = `Bearer ${token}`;
|
|
157
170
|
return rpRetry(opts)
|
|
158
171
|
.then((result) => {
|
|
159
|
-
measure(
|
|
172
|
+
measure(OK);
|
|
160
173
|
return result;
|
|
161
174
|
})
|
|
162
175
|
.catch((err) => {
|
|
163
|
-
if (err.statusCode ===
|
|
176
|
+
if (err.statusCode === FORBIDDEN_ERROR) {
|
|
164
177
|
logger.warn('got a unauthorized request, retrying', { error: err.message, type }, correlationId);
|
|
165
178
|
tokens[type].accessToken = null;
|
|
166
179
|
return getToken(type, options.uri || options.url, correlationId, options)
|
|
@@ -168,7 +181,7 @@ module.exports = (config) => {
|
|
|
168
181
|
opts.headers.authorization = `Bearer ${newToken}`;
|
|
169
182
|
return rpRetry(opts)
|
|
170
183
|
.then((result) => {
|
|
171
|
-
measure(
|
|
184
|
+
measure(OK);
|
|
172
185
|
return result;
|
|
173
186
|
});
|
|
174
187
|
});
|
|
@@ -211,7 +224,7 @@ module.exports = (config) => {
|
|
|
211
224
|
.catch((err) => {
|
|
212
225
|
const error = getRichError(err.statusCode, 'could perform operation on identity server', { method, id }, err);
|
|
213
226
|
|
|
214
|
-
if (error.statusCode ===
|
|
227
|
+
if (error.statusCode === PARAMETER_ERROR && method === 'DELETE') {
|
|
215
228
|
logger.warn('profile without authprofile', { id, error }, correlationId);
|
|
216
229
|
return;
|
|
217
230
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/oauth-helper",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Oauth helper for mimik microservices",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
|
-
|
|
8
|
+
"lint": "eslint . --no-error-on-unmatched-pattern",
|
|
8
9
|
"docs": "jsdoc2md index.js > README.md",
|
|
9
10
|
"test": "mocha --reporter mochawesome --bail --check-leaks test/",
|
|
10
|
-
"test-ci": "
|
|
11
|
+
"test-ci": "c8 --reporter=lcov --reporter=text npm test --exit",
|
|
11
12
|
"prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
|
|
12
|
-
"commit-ready": "npm run docs && npm run lint && npm run test-ci"
|
|
13
|
-
"prepare": "husky install"
|
|
13
|
+
"commit-ready": "npm run docs && npm run lint && npm run test-ci"
|
|
14
14
|
},
|
|
15
15
|
"husky": {
|
|
16
16
|
"hooks": {
|
|
@@ -29,29 +29,26 @@
|
|
|
29
29
|
"url": "https://bitbucket.org/mimiktech/oauth-helper"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@mimik/request-retry": "^
|
|
33
|
-
"@mimik/response-helper": "^
|
|
34
|
-
"@mimik/sumologic-winston-logger": "^
|
|
32
|
+
"@mimik/request-retry": "^4.0.1",
|
|
33
|
+
"@mimik/response-helper": "^4.0.1",
|
|
34
|
+
"@mimik/sumologic-winston-logger": "^2.0.2",
|
|
35
35
|
"bluebird": "3.7.2",
|
|
36
36
|
"jsonwebtoken": "9.0.2"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@mimik/eslint-plugin-document-env": "^
|
|
41
|
-
"@mimik/request-helper": "
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"eslint
|
|
47
|
-
"eslint-plugin-
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"mocha": "10.2.0",
|
|
54
|
-
"mochawesome": "7.1.3",
|
|
55
|
-
"nyc": "15.1.0"
|
|
39
|
+
"@eslint/js": "9.24.0",
|
|
40
|
+
"@mimik/eslint-plugin-document-env": "^2.0.5",
|
|
41
|
+
"@mimik/request-helper": "2.0.1",
|
|
42
|
+
"@stylistic/eslint-plugin": "4.2.0",
|
|
43
|
+
"c8": "10.1.3",
|
|
44
|
+
"body-parser": "2.2.0",
|
|
45
|
+
"chai": "5.2.0",
|
|
46
|
+
"eslint": "9.24.0",
|
|
47
|
+
"eslint-plugin-import": "2.31.0",
|
|
48
|
+
"express": "4.21.2",
|
|
49
|
+
"husky": "9.1.7",
|
|
50
|
+
"jsdoc-to-markdown": "9.1.1",
|
|
51
|
+
"mocha": "11.1.0",
|
|
52
|
+
"mochawesome": "7.1.3"
|
|
56
53
|
}
|
|
57
54
|
}
|
package/test/oauthHelper.spec.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import './testEnv.js';
|
|
2
|
+
import { before, describe, it } from 'mocha';
|
|
3
|
+
import { expect, should } from 'chai';
|
|
4
|
+
import { config } from './testConfig.js';
|
|
5
|
+
import { getCorrelationId } from '@mimik/request-helper';
|
|
6
|
+
import { listen } from './serversMock.js';
|
|
7
|
+
import oauthHelper from '../index.js';
|
|
8
|
+
import { rpRetry } from '@mimik/request-retry';
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
should();
|
|
4
11
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const oauthHelper = require('../index');
|
|
9
|
-
const {
|
|
10
|
-
config,
|
|
11
|
-
} = require('./testConfig');
|
|
12
|
-
const mockServer = require('./serversMock');
|
|
13
|
-
|
|
14
|
-
const { expect } = chai;
|
|
15
|
-
chai.should();
|
|
12
|
+
const SYSTEM_ERROR = 500;
|
|
13
|
+
const TIMEOUT = 200000;
|
|
14
|
+
const DELAY = 100;
|
|
16
15
|
|
|
17
16
|
const correlationId = getCorrelationId('--test-OauthHelper--');
|
|
18
17
|
// const oauthImplNoGeneric = oauthHelper(config.implNoGeneric);
|
|
@@ -24,10 +23,10 @@ const oauthAppExpiredTokenAndFail = oauthHelper(config.appExpiredTokenAndFail);
|
|
|
24
23
|
|
|
25
24
|
describe('OauthHelper Unit Tests', () => {
|
|
26
25
|
before(() => {
|
|
27
|
-
|
|
26
|
+
listen();
|
|
28
27
|
});
|
|
29
|
-
describe('rpAuth(type, options)', function
|
|
30
|
-
this.timeout(
|
|
28
|
+
describe('rpAuth(type, options)', function Test() {
|
|
29
|
+
this.timeout(TIMEOUT);
|
|
31
30
|
const requestOptions = {
|
|
32
31
|
method: 'GET',
|
|
33
32
|
headers: {
|
|
@@ -37,19 +36,19 @@ describe('OauthHelper Unit Tests', () => {
|
|
|
37
36
|
json: true,
|
|
38
37
|
};
|
|
39
38
|
it('should generate an error rpAuth type non existent', () => oauthAppGeneric.rpAuth(null, requestOptions)
|
|
40
|
-
.then(
|
|
39
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
41
40
|
.catch((err) => {
|
|
42
41
|
expect(err.message).to.equal(`rpAuth type non existent for ${requestOptions.method} on ${requestOptions.uri}`);
|
|
43
42
|
}));
|
|
44
43
|
it('should generate an error used in rpAuth with no dependencies ', () => oauthAppGeneric.rpAuth('unknownDependency', requestOptions)
|
|
45
|
-
.then(
|
|
44
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
46
45
|
.catch((err) => {
|
|
47
46
|
expect(err.message).to.equal('type unknownDependency used in rpAuth with no dependencies');
|
|
48
47
|
}));
|
|
49
48
|
it('should generate an error uri or url non existent', () => {
|
|
50
49
|
requestOptions.uri = null;
|
|
51
50
|
return oauthAppGeneric.rpAuth('test1', requestOptions)
|
|
52
|
-
.then(
|
|
51
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
53
52
|
.catch((err) => {
|
|
54
53
|
expect(err.message).to.equal('uri or url non existent');
|
|
55
54
|
});
|
|
@@ -57,7 +56,7 @@ describe('OauthHelper Unit Tests', () => {
|
|
|
57
56
|
it('should generate an error invalid url address', () => {
|
|
58
57
|
requestOptions.uri = 'http//test.com/test';
|
|
59
58
|
return oauthAppGeneric.rpAuth('test1', requestOptions)
|
|
60
|
-
.then(
|
|
59
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
61
60
|
.catch((err) => {
|
|
62
61
|
expect(err.message).to.include('invalid url address');
|
|
63
62
|
});
|
|
@@ -65,9 +64,9 @@ describe('OauthHelper Unit Tests', () => {
|
|
|
65
64
|
it('should generate an error request error response from token server ', () => {
|
|
66
65
|
requestOptions.uri = 'http://localhost:9070/getTest';
|
|
67
66
|
return oauthAppUnknownIssuer.rpAuth('test1', requestOptions)
|
|
68
|
-
.then(
|
|
67
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
69
68
|
.catch((err) => {
|
|
70
|
-
expect(err.message).to.include('request error response
|
|
69
|
+
expect(err.message).to.include('request error response');
|
|
71
70
|
});
|
|
72
71
|
});
|
|
73
72
|
it('should get a response test ok, setting up expiredTokenAndFail ', () => oauthAppExpiredTokenAndFail.rpAuth('test1', requestOptions)
|
|
@@ -107,23 +106,23 @@ describe('OauthHelper Unit Tests', () => {
|
|
|
107
106
|
json: true,
|
|
108
107
|
};
|
|
109
108
|
return oauthAppGeneric.rpAuth('test1', requestOptionsFailed)
|
|
110
|
-
.then(
|
|
109
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
111
110
|
.catch((err) => {
|
|
112
|
-
expect(err.statusCode).to.equal(
|
|
111
|
+
expect(err.statusCode).to.equal(SYSTEM_ERROR);
|
|
113
112
|
});
|
|
114
113
|
});
|
|
115
114
|
});
|
|
116
|
-
describe('authProfile(method, id, correlationId)', function
|
|
117
|
-
this.timeout(
|
|
115
|
+
describe('authProfile(method, id, correlationId)', function Test() {
|
|
116
|
+
this.timeout(TIMEOUT);
|
|
118
117
|
it('should generate an error invalid id', () => oauthAppGeneric.authProfile('GET', null, correlationId)
|
|
119
|
-
.then(
|
|
118
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
120
119
|
.catch((err) => {
|
|
121
120
|
expect(err.message).to.equal('Id has to be defined');
|
|
122
121
|
}));
|
|
123
122
|
it('should generate an error on GET', () => oauthAppGeneric.authProfile('GET', '123', correlationId)
|
|
124
|
-
.then(
|
|
123
|
+
.then(response => expect(response).to.equal('should not return a valid response'))
|
|
125
124
|
.catch((err) => {
|
|
126
|
-
expect(err.message).to.include('could perform operation on identity server
|
|
125
|
+
expect(err.message).to.include('could perform operation on identity server');
|
|
127
126
|
}));
|
|
128
127
|
it('should return nothing', () => oauthAppGeneric.authProfile('DELETE', '123', correlationId)
|
|
129
128
|
.then((response) => {
|
|
@@ -136,7 +135,7 @@ describe('OauthHelper Unit Tests', () => {
|
|
|
136
135
|
},
|
|
137
136
|
url: 'http://localhost:9070/stop',
|
|
138
137
|
retry: {
|
|
139
|
-
delayStrategy: () =>
|
|
138
|
+
delayStrategy: () => DELAY,
|
|
140
139
|
retries: 1,
|
|
141
140
|
},
|
|
142
141
|
})
|
package/test/serversMock.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
/* eslint camelcase: ["error", { properties: "never" }] */
|
|
3
|
+
import { URL } from 'url';
|
|
4
|
+
import bodyParser from 'body-parser';
|
|
5
|
+
import { config } from './testConfig.js';
|
|
6
|
+
import express from 'express';
|
|
7
|
+
import jwt from 'jsonwebtoken';
|
|
8
|
+
import process from 'process';
|
|
9
|
+
import { setTimeout } from 'timers';
|
|
5
10
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
const TAB = 2;
|
|
12
|
+
const OK = 200;
|
|
13
|
+
const PARAMETER_ERROR = 400;
|
|
14
|
+
const SYSTEM_ERROR = 500;
|
|
15
|
+
const FORBIDDEN_ERROR = 403;
|
|
16
|
+
const INCR = 1;
|
|
17
|
+
const NONE = 0;
|
|
18
|
+
const ONE = 1;
|
|
19
|
+
const NORMAL_EXIT = 0;
|
|
20
|
+
const TIMEOUT = 3000;
|
|
9
21
|
|
|
10
22
|
const app = express();
|
|
11
23
|
const mockConfig = {
|
|
@@ -21,8 +33,8 @@ let expiredTries = 0;
|
|
|
21
33
|
|
|
22
34
|
app.use(bodyParser.json());
|
|
23
35
|
app.post(issuerUrl.pathname, (req, res) => {
|
|
24
|
-
console.log(`-----> received POST on ${config.appGeneric.security.server.issuer} with body: ${JSON.stringify(req.body, null,
|
|
25
|
-
res.statusCode =
|
|
36
|
+
console.log(`-----> received POST on ${config.appGeneric.security.server.issuer} with body: ${JSON.stringify(req.body, null, TAB)}`);
|
|
37
|
+
res.statusCode = OK;
|
|
26
38
|
res.send({
|
|
27
39
|
data: {
|
|
28
40
|
access_token: fakeJwt,
|
|
@@ -31,8 +43,8 @@ app.post(issuerUrl.pathname, (req, res) => {
|
|
|
31
43
|
});
|
|
32
44
|
});
|
|
33
45
|
app.post(issuerUrlExpiredToken.pathname, (req, res) => {
|
|
34
|
-
console.log(`-----> received POST on ${config.appExpiredToken.security.server.issuer} with body: ${JSON.stringify(req.body, null,
|
|
35
|
-
res.statusCode =
|
|
46
|
+
console.log(`-----> received POST on ${config.appExpiredToken.security.server.issuer} with body: ${JSON.stringify(req.body, null, TAB)}`);
|
|
47
|
+
res.statusCode = OK;
|
|
36
48
|
res.send({
|
|
37
49
|
data: {
|
|
38
50
|
access_token: fakeExpiredJwt,
|
|
@@ -41,11 +53,11 @@ app.post(issuerUrlExpiredToken.pathname, (req, res) => {
|
|
|
41
53
|
});
|
|
42
54
|
});
|
|
43
55
|
app.post(issuerUrlExpiredTokenAndFail.pathname, (req, res) => {
|
|
44
|
-
console.log(`-----> received POST on ${config.appExpiredTokenAndFail.security.server.issuer} with body: ${JSON.stringify(req.body, null,
|
|
45
|
-
if (expiredTries ===
|
|
56
|
+
console.log(`-----> received POST on ${config.appExpiredTokenAndFail.security.server.issuer} with body: ${JSON.stringify(req.body, null, TAB)}`);
|
|
57
|
+
if (expiredTries === NONE) {
|
|
46
58
|
console.log('-----> first POST');
|
|
47
|
-
expiredTries +=
|
|
48
|
-
res.statusCode =
|
|
59
|
+
expiredTries += INCR;
|
|
60
|
+
res.statusCode = OK;
|
|
49
61
|
res.send({
|
|
50
62
|
data: {
|
|
51
63
|
access_token: fakeExpiredJwt,
|
|
@@ -53,15 +65,15 @@ app.post(issuerUrlExpiredTokenAndFail.pathname, (req, res) => {
|
|
|
53
65
|
},
|
|
54
66
|
});
|
|
55
67
|
}
|
|
56
|
-
else if (expiredTries ===
|
|
68
|
+
else if (expiredTries === ONE) {
|
|
57
69
|
console.log('-----> second POST');
|
|
58
|
-
expiredTries +=
|
|
59
|
-
res.statusCode =
|
|
60
|
-
res.send({ statusCode:
|
|
70
|
+
expiredTries += INCR;
|
|
71
|
+
res.statusCode = PARAMETER_ERROR;
|
|
72
|
+
res.send({ statusCode: PARAMETER_ERROR });
|
|
61
73
|
}
|
|
62
74
|
else {
|
|
63
75
|
console.log('-----> third POST');
|
|
64
|
-
res.statusCode =
|
|
76
|
+
res.statusCode = OK;
|
|
65
77
|
res.send({
|
|
66
78
|
data: {
|
|
67
79
|
access_token: fakeExpiredJwt,
|
|
@@ -72,44 +84,44 @@ app.post(issuerUrlExpiredTokenAndFail.pathname, (req, res) => {
|
|
|
72
84
|
});
|
|
73
85
|
app.get('/GetTest', (req, res) => {
|
|
74
86
|
console.log('-----> received GET');
|
|
75
|
-
res.statusCode =
|
|
87
|
+
res.statusCode = OK;
|
|
76
88
|
res.send({ data: 'test ok' });
|
|
77
89
|
});
|
|
78
90
|
app.get('/GetTestUnAuthorized', (req, res) => {
|
|
79
|
-
if (tries ===
|
|
91
|
+
if (tries === NONE) {
|
|
80
92
|
console.log('-----> received first GET to be unAuthorized');
|
|
81
|
-
tries +=
|
|
82
|
-
res.statusCode =
|
|
83
|
-
res.send({ statusCode:
|
|
93
|
+
tries += INCR;
|
|
94
|
+
res.statusCode = FORBIDDEN_ERROR;
|
|
95
|
+
res.send({ statusCode: FORBIDDEN_ERROR });
|
|
84
96
|
}
|
|
85
97
|
else {
|
|
86
98
|
console.log('-----> received second GET to be authorized');
|
|
87
|
-
res.statusCode =
|
|
99
|
+
res.statusCode = OK;
|
|
88
100
|
res.send({ data: 'test ok' });
|
|
89
101
|
}
|
|
90
102
|
});
|
|
91
103
|
app.get('/GetTestFailed', (req, res) => {
|
|
92
104
|
console.log('-----> received GET failed');
|
|
93
|
-
res.statusCode =
|
|
94
|
-
res.send({ statusCode:
|
|
105
|
+
res.statusCode = SYSTEM_ERROR;
|
|
106
|
+
res.send({ statusCode: SYSTEM_ERROR });
|
|
95
107
|
});
|
|
96
108
|
app.get('/mIDUrl/users/:id', (req, res) => {
|
|
97
109
|
console.log('-----> recieved a GET');
|
|
98
|
-
res.statusCode =
|
|
99
|
-
res.send({ statusCode:
|
|
110
|
+
res.statusCode = SYSTEM_ERROR;
|
|
111
|
+
res.send({ statusCode: SYSTEM_ERROR });
|
|
100
112
|
});
|
|
101
113
|
app.delete('/mIDUrl/users/:id', (req, res) => {
|
|
102
114
|
console.log('-----> received a DELETE');
|
|
103
|
-
res.statusCode =
|
|
104
|
-
res.send({ statusCode:
|
|
115
|
+
res.statusCode = PARAMETER_ERROR;
|
|
116
|
+
res.send({ statusCode: PARAMETER_ERROR });
|
|
105
117
|
});
|
|
106
118
|
app.get('/stop', (req, res) => {
|
|
107
119
|
console.log('----->', 'Received a stop');
|
|
108
|
-
res.statusCode =
|
|
109
|
-
res.send({ statusCode:
|
|
120
|
+
res.statusCode = OK;
|
|
121
|
+
res.send({ statusCode: OK });
|
|
110
122
|
setTimeout(() => {
|
|
111
|
-
process.exit(
|
|
112
|
-
},
|
|
123
|
+
process.exit(NORMAL_EXIT);
|
|
124
|
+
}, TIMEOUT);
|
|
113
125
|
});
|
|
114
126
|
|
|
115
127
|
const listen = () => {
|
|
@@ -118,6 +130,6 @@ const listen = () => {
|
|
|
118
130
|
});
|
|
119
131
|
};
|
|
120
132
|
|
|
121
|
-
|
|
133
|
+
export {
|
|
122
134
|
listen,
|
|
123
135
|
};
|
package/test/testConfig.js
CHANGED
package/test/testEnv.js
CHANGED
package/.eslintrc
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": [
|
|
3
|
-
"@mimik/document-env",
|
|
4
|
-
"@mimik/dependencies"
|
|
5
|
-
],
|
|
6
|
-
"env": {
|
|
7
|
-
"node": true
|
|
8
|
-
},
|
|
9
|
-
"parserOptions": {
|
|
10
|
-
"ecmaVersion": 2020
|
|
11
|
-
},
|
|
12
|
-
"extends": "airbnb",
|
|
13
|
-
"rules": {
|
|
14
|
-
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
|
|
15
|
-
"import/no-unresolved": ["error", { "amd": true, "commonjs": true, "caseSensitiveStrict": true }],
|
|
16
|
-
"brace-style": [1, "stroustrup", { "allowSingleLine": true }],
|
|
17
|
-
"no-confusing-arrow": [0], // arrow isnt confusing
|
|
18
|
-
"max-len": [1, 180, { "ignoreComments": true }],
|
|
19
|
-
"linebreak-style": 0,
|
|
20
|
-
"quotes": [1, "single"],
|
|
21
|
-
"semi": [1, "always"],
|
|
22
|
-
"no-process-env": ["error"],
|
|
23
|
-
"@mimik/document-env/validate-document-env": 2,
|
|
24
|
-
"@mimik/dependencies/case-sensitive": 2,
|
|
25
|
-
"@mimik/dependencies/no-cycles": 2,
|
|
26
|
-
"@mimik/dependencies/require-json-ext": 2
|
|
27
|
-
},
|
|
28
|
-
"settings":{
|
|
29
|
-
"react": {
|
|
30
|
-
"version": "detect"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"globals": {
|
|
34
|
-
"module": true,
|
|
35
|
-
"require": true,
|
|
36
|
-
"const": false,
|
|
37
|
-
"it": false,
|
|
38
|
-
"describe": false,
|
|
39
|
-
"before": true,
|
|
40
|
-
"after": true,
|
|
41
|
-
"JSON": true
|
|
42
|
-
}
|
|
43
|
-
}
|