soajs.controller 4.2.33 → 4.2.35
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/mw/gotoService/index.js +0 -1
- package/mw/ip2ban/index.js +52 -0
- package/mw/mt/urac.js +3 -0
- package/mw/mt/utils.js +15 -1
- package/mw/traffic/index.js +13 -10
- package/package.json +7 -7
- package/server/controller.js +6 -1
- package/test/unit/utilities/utils.js +11 -8
- package/utilities/utils.js +6 -3
package/mw/gotoService/index.js
CHANGED
|
@@ -82,7 +82,6 @@ module.exports = (configuration) => {
|
|
|
82
82
|
req.soajs.registry.services[service_n]) {
|
|
83
83
|
req.soajs.log.debug(req.soajs.registry.services[service_n]);
|
|
84
84
|
}
|
|
85
|
-
req.soajs.log.debug(req.headers);
|
|
86
85
|
return req.soajs.controllerResponse(core.error.getError(130));
|
|
87
86
|
}
|
|
88
87
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright SOAJS All Rights Reserved.
|
|
6
|
+
*
|
|
7
|
+
* Use of this source code is governed by an Apache license that can be
|
|
8
|
+
* found in the LICENSE file at the root of this repository
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param configuration
|
|
17
|
+
* @returns {Function}
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// let customRegistry.gateway = {
|
|
21
|
+
// "traffic": {
|
|
22
|
+
// "ip2ban": [
|
|
23
|
+
// "::1"
|
|
24
|
+
// ],
|
|
25
|
+
// "model": "mongo",
|
|
26
|
+
// "throttling": {
|
|
27
|
+
// "oauth": {
|
|
28
|
+
// "publicAPIStrategy": "test",
|
|
29
|
+
// "apis": [
|
|
30
|
+
// "/token"
|
|
31
|
+
// ]
|
|
32
|
+
// }
|
|
33
|
+
// }
|
|
34
|
+
// },
|
|
35
|
+
// };
|
|
36
|
+
module.exports = function () {
|
|
37
|
+
|
|
38
|
+
return (req, res, next) => {
|
|
39
|
+
|
|
40
|
+
let ip2ban = get(["soajs", "registry", "custom", "gateway", "value", "traffic", "ip2ban"], req);
|
|
41
|
+
let clientIP = req.getClientIP();
|
|
42
|
+
|
|
43
|
+
if (ip2ban && Array.isArray(ip2ban) && ip2ban.includes(clientIP)) {
|
|
44
|
+
req.soajs.controllerResponse({
|
|
45
|
+
'status': 403,
|
|
46
|
+
'msg': 'banned'
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
return next();
|
|
51
|
+
};
|
|
52
|
+
};
|
package/mw/mt/urac.js
CHANGED
|
@@ -21,12 +21,15 @@ function Urac(param) {
|
|
|
21
21
|
_self.userRecord = null;
|
|
22
22
|
_self.user_ACL = null;
|
|
23
23
|
_self.id = null;
|
|
24
|
+
_self.bearerTokenUser = null;
|
|
25
|
+
|
|
24
26
|
if (param.oauth && 0 === param.oauth.type) {
|
|
25
27
|
_self.userRecord = param.oauth.bearerToken;
|
|
26
28
|
} else {
|
|
27
29
|
// if type === 2
|
|
28
30
|
if (param.oauth && param.oauth.bearerToken && param.oauth.bearerToken.user) {
|
|
29
31
|
_self.id = param.oauth.bearerToken.user.id;
|
|
32
|
+
_self.bearerTokenUser = param.oauth.bearerToken.user;
|
|
30
33
|
if (param.oauth.bearerToken.user.username) {
|
|
31
34
|
_self.username = param.oauth.bearerToken.user.username;
|
|
32
35
|
}
|
package/mw/mt/utils.js
CHANGED
|
@@ -588,11 +588,25 @@ let utils = {
|
|
|
588
588
|
}
|
|
589
589
|
let callURACDriver = function (roaming) {
|
|
590
590
|
obj.req.soajs.uracDriver = new UracDriver({ "soajs": obj.req.soajs, "oauth": obj.req.oauth });
|
|
591
|
-
obj.req.soajs.uracDriver.init((error) => {
|
|
591
|
+
obj.req.soajs.uracDriver.init((error, record) => {
|
|
592
592
|
if (error && !roaming) {
|
|
593
593
|
obj.req.soajs.log.error(error.message, error.code);
|
|
594
594
|
return cb(146);
|
|
595
595
|
}
|
|
596
|
+
if (obj.keyObj.config && obj.keyObj.config.gateway && obj.keyObj.config.gateway.validateTokenAccount) {
|
|
597
|
+
if (obj.req.soajs.uracDriver.bearerTokenUser && record) {
|
|
598
|
+
if (obj.keyObj.config.gateway.validateTokenAccount.email && record.email) {
|
|
599
|
+
if (record.email !== obj.req.soajs.uracDriver.bearerTokenUser.email) {
|
|
600
|
+
return cb(146);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
if (obj.keyObj.config.gateway.validateTokenAccount.phone && record.phone) {
|
|
604
|
+
if (record.phone !== obj.req.soajs.uracDriver.bearerTokenUser.phone) {
|
|
605
|
+
return cb(146);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
596
610
|
let userServiceConf = obj.req.soajs.uracDriver.getConfig();
|
|
597
611
|
userServiceConf = userServiceConf || {};
|
|
598
612
|
|
package/mw/traffic/index.js
CHANGED
|
@@ -126,17 +126,20 @@ module.exports = function (configuration) {
|
|
|
126
126
|
|
|
127
127
|
return (req, res, next) => {
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
// NOTE: moved to ip2ban MW
|
|
130
|
+
//
|
|
131
|
+
// let ip2ban = get(["soajs", "registry", "custom", "gateway", "value", "traffic", "ip2ban"], req);
|
|
132
|
+
// let clientIP = req.getClientIP();
|
|
133
|
+
|
|
134
|
+
// if (ip2ban && Array.isArray(ip2ban) && ip2ban.includes(clientIP)) {
|
|
135
|
+
// req.soajs.controllerResponse({
|
|
136
|
+
// 'status': 403,
|
|
137
|
+
// 'msg': 'banned'
|
|
138
|
+
// });
|
|
139
|
+
// return;
|
|
140
|
+
// }
|
|
130
141
|
let clientIP = req.getClientIP();
|
|
131
|
-
|
|
132
|
-
if (ip2ban && Array.isArray(ip2ban) && ip2ban.includes(clientIP)) {
|
|
133
|
-
req.soajs.controllerResponse({
|
|
134
|
-
'status': 403,
|
|
135
|
-
'msg': 'banned'
|
|
136
|
-
});
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
142
|
+
|
|
140
143
|
if (req && req.soajs && req.soajs.registry && req.soajs.registry.serviceConfig && req.soajs.registry.serviceConfig.throttling && req.soajs.tenant && req.soajs.controller) {
|
|
141
144
|
|
|
142
145
|
let serviceName = req.soajs.controller.serviceParams.name;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "soajs.controller",
|
|
3
3
|
"description": "soajs multi tenant API gateway",
|
|
4
|
-
"version": "4.2.
|
|
4
|
+
"version": "4.2.35",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "soajs team",
|
|
7
7
|
"email": "team@soajs.org"
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"netmask": "2.0.2",
|
|
29
29
|
"oauth2-server": "2.4.1",
|
|
30
30
|
"path-to-regexp": "6.2.2",
|
|
31
|
-
"soajs.core.libs": "1.2.
|
|
32
|
-
"soajs.core.modules": "5.2.
|
|
33
|
-
"soajs.urac.driver": "3.2.
|
|
31
|
+
"soajs.core.libs": "1.2.1",
|
|
32
|
+
"soajs.core.modules": "5.2.15",
|
|
33
|
+
"soajs.urac.driver": "3.2.12",
|
|
34
34
|
"useragent": "2.3.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
"grunt-istanbul": "0.8.0",
|
|
50
50
|
"grunt-jsdoc": "2.4.1",
|
|
51
51
|
"grunt-mocha-test": "0.13.3",
|
|
52
|
-
"mocha": "
|
|
53
|
-
"nock": "
|
|
52
|
+
"mocha": "11.5.0",
|
|
53
|
+
"nock": "14.0.4",
|
|
54
54
|
"request": "2.88.2",
|
|
55
|
-
"sinon": "
|
|
55
|
+
"sinon": "20.0.0"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/server/controller.js
CHANGED
|
@@ -38,6 +38,7 @@ const gotoService_mw = require("../mw/gotoService/index");
|
|
|
38
38
|
const mt_mw = require("../mw/mt/index");
|
|
39
39
|
const traffic_mw = require("../mw/traffic/index");
|
|
40
40
|
const lastSeen_mw = require("../mw/lastSeen/index");
|
|
41
|
+
const ip2ban_mw = require("../mw/ip2ban/index");
|
|
41
42
|
|
|
42
43
|
const utils = require("../utilities/utils");
|
|
43
44
|
|
|
@@ -87,6 +88,10 @@ Controller.prototype.init = function (callback) {
|
|
|
87
88
|
app.use(cors_mw());
|
|
88
89
|
app.use(favicon_mw());
|
|
89
90
|
app.use(response_mw({ "controllerResponse": true }));
|
|
91
|
+
|
|
92
|
+
app.use(enhancer_mw());
|
|
93
|
+
|
|
94
|
+
app.use(ip2ban_mw());
|
|
90
95
|
app.use(maintenanceMode_mw()); //NOTE: this is for global maintenance mode
|
|
91
96
|
|
|
92
97
|
log.info("Loading Provision ...");
|
|
@@ -128,7 +133,7 @@ Controller.prototype.init = function (callback) {
|
|
|
128
133
|
}));
|
|
129
134
|
log.info("AwarenessEnv middleware initialization done.");
|
|
130
135
|
|
|
131
|
-
app.use(enhancer_mw());
|
|
136
|
+
// app.use(enhancer_mw());
|
|
132
137
|
|
|
133
138
|
app.use(url_mw({ "core": core }));
|
|
134
139
|
|
|
@@ -4,7 +4,7 @@ const helper = require("../../helper.js");
|
|
|
4
4
|
let utils = helper.requireModule('./utilities/utils.js');
|
|
5
5
|
|
|
6
6
|
describe("Testing utilities", () => {
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
let res = {
|
|
9
9
|
status: () => {
|
|
10
10
|
return {
|
|
@@ -17,12 +17,15 @@ describe("Testing utilities", () => {
|
|
|
17
17
|
return 2;
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
let req = {
|
|
22
22
|
soajs: {
|
|
23
23
|
log: {
|
|
24
24
|
error: (input) => {
|
|
25
25
|
// console.error(input);
|
|
26
|
+
},
|
|
27
|
+
warn: (input) => {
|
|
28
|
+
// console.error(input);
|
|
26
29
|
}
|
|
27
30
|
},
|
|
28
31
|
buildResponse: (input) => {
|
|
@@ -33,25 +36,25 @@ describe("Testing utilities", () => {
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
};
|
|
36
|
-
|
|
39
|
+
|
|
37
40
|
it("logErrors - number error", (done) => {
|
|
38
41
|
utils.logErrors(123, req, res, (error) => {
|
|
39
42
|
done();
|
|
40
43
|
});
|
|
41
44
|
});
|
|
42
|
-
|
|
45
|
+
|
|
43
46
|
it("logErrors - object, no code no message", (done) => {
|
|
44
47
|
utils.logErrors({}, req, res, (error) => {
|
|
45
48
|
done();
|
|
46
49
|
});
|
|
47
50
|
});
|
|
48
|
-
|
|
51
|
+
|
|
49
52
|
it("logErrors - string error", (done) => {
|
|
50
53
|
utils.logErrors("error", req, res, (error) => {
|
|
51
54
|
done();
|
|
52
55
|
});
|
|
53
56
|
});
|
|
54
|
-
|
|
57
|
+
|
|
55
58
|
it("controllerClientErrorHandler - request without xhr", (done) => {
|
|
56
59
|
utils.controllerClientErrorHandler(null, req, res, () => {
|
|
57
60
|
done();
|
|
@@ -63,14 +66,14 @@ describe("Testing utilities", () => {
|
|
|
63
66
|
done();
|
|
64
67
|
});
|
|
65
68
|
});
|
|
66
|
-
|
|
69
|
+
|
|
67
70
|
it("controllerErrorHandler - number error", (done) => {
|
|
68
71
|
req.xhr = {};
|
|
69
72
|
utils.controllerErrorHandler(150, req, res, null);
|
|
70
73
|
done();
|
|
71
74
|
});
|
|
72
75
|
it("controllerErrorHandler - with error", (done) => {
|
|
73
|
-
utils.controllerErrorHandler({"code": 200, "msg": "dummy200"}, req, res, null);
|
|
76
|
+
utils.controllerErrorHandler({ "code": 200, "msg": "dummy200" }, req, res, null);
|
|
74
77
|
done();
|
|
75
78
|
});
|
|
76
79
|
});
|
package/utilities/utils.js
CHANGED
|
@@ -28,9 +28,9 @@ function logErrors(err, req, res, next) {
|
|
|
28
28
|
if (err.code && err.message) {
|
|
29
29
|
req.soajs.log.error(err.message);
|
|
30
30
|
if (err.name === "OAuth2Error") {
|
|
31
|
-
|
|
31
|
+
return next({ "code": err.code, "status": err.code, "msg": err.message });
|
|
32
32
|
} else {
|
|
33
|
-
|
|
33
|
+
return next({ "code": err.code, "msg": err.message });
|
|
34
34
|
}
|
|
35
35
|
} else if (err.code && err.msg) {
|
|
36
36
|
err.message = err.msg;
|
|
@@ -62,7 +62,7 @@ function controllerClientErrorHandler(err, req, res, next) {
|
|
|
62
62
|
req.soajs.log.error(core.error.generate(150));
|
|
63
63
|
let errObj = core.error.getError(150);
|
|
64
64
|
errObj.status = 500;
|
|
65
|
-
return next
|
|
65
|
+
return next(errObj);
|
|
66
66
|
} else {
|
|
67
67
|
return next(err);
|
|
68
68
|
}
|
|
@@ -76,6 +76,9 @@ function controllerClientErrorHandler(err, req, res, next) {
|
|
|
76
76
|
* @param next
|
|
77
77
|
*/
|
|
78
78
|
function controllerErrorHandler(err, req, res, next) {
|
|
79
|
+
|
|
80
|
+
req.soajs.log.warn(JSON.stringify({ "url": req.url, "headers": req.headers }));
|
|
81
|
+
|
|
79
82
|
if (err.code && err.msg) {
|
|
80
83
|
err.status = err.status || 500;
|
|
81
84
|
req.soajs.controllerResponse(err, next);
|