soajs.controller 4.2.36 → 4.2.37
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/lib/header.js +51 -0
- package/mw/mt/index.js +9 -4
- package/package.json +1 -1
- package/test/data/provision/marketplace/httpmethods.js +1 -1
- package/test/data/provision/oauth/token/access_token.js +1 -1
- package/test/data/provision/oauth/token/refresh_token.js +1 -1
- package/test/data/provision/urac/users/owner.js +1 -1
- package/test/integration/UC1-gateway-routes/oauth-service-mock.js +10 -8
- package/test/integration/UC2-http-methods/service-mock/soa.json +1 -1
package/lib/header.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* Encodes a string to be safely used as an HTTP header value.
|
|
14
|
+
* This preserves all data and is the standard, recommended method.
|
|
15
|
+
*
|
|
16
|
+
* @param {string | number | boolean} value The value to encode.
|
|
17
|
+
* @returns {string} The URL-encoded string.
|
|
18
|
+
*/
|
|
19
|
+
function encodeHeaderValue(value) {
|
|
20
|
+
if (value === null || typeof value === 'undefined') {
|
|
21
|
+
return '';
|
|
22
|
+
}
|
|
23
|
+
return encodeURIComponent(String(value));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Decodes a URL-encoded string from an HTTP header.
|
|
28
|
+
* It safely handles potential errors if the input is malformed.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} encodedValue The percent-encoded header value to decode.
|
|
31
|
+
* @returns {string} The decoded (original) string, or the original
|
|
32
|
+
* string if decoding fails.
|
|
33
|
+
*/
|
|
34
|
+
function decodeHeaderValue(encodedValue) {
|
|
35
|
+
// Return empty string or null as is, to avoid errors.
|
|
36
|
+
if (!encodedValue) {
|
|
37
|
+
return encodedValue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
// The standard way to decode a value encoded by encodeURIComponent.
|
|
42
|
+
return decodeURIComponent(encodedValue);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// This catches errors from malformed URI sequences (e.g., a lone '%').
|
|
45
|
+
console.error(`Failed to decode header value: "${encodedValue}"`, e);
|
|
46
|
+
// Return the original, undecoded value so the app doesn't crash.
|
|
47
|
+
return encodedValue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = { encodeHeaderValue, decodeHeaderValue };
|
package/mw/mt/index.js
CHANGED
|
@@ -12,6 +12,9 @@ const async = require("async");
|
|
|
12
12
|
|
|
13
13
|
const utils = require("./utils");
|
|
14
14
|
|
|
15
|
+
|
|
16
|
+
const { encodeHeaderValue } = require("../../lib/header.js");
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
*
|
|
17
20
|
* @param configuration
|
|
@@ -247,8 +250,8 @@ module.exports = (configuration) => {
|
|
|
247
250
|
injectObj.urac = {
|
|
248
251
|
"_id": uracObj._id,
|
|
249
252
|
"username": uracObj.username,
|
|
250
|
-
"firstName": uracObj.firstName,
|
|
251
|
-
"lastName": uracObj.lastName,
|
|
253
|
+
"firstName": encodeHeaderValue(uracObj.firstName),
|
|
254
|
+
"lastName": encodeHeaderValue(uracObj.lastName),
|
|
252
255
|
"email": uracObj.email,
|
|
253
256
|
"groups": uracObj.groups,
|
|
254
257
|
"socialLogin": uracObj.socialLogin,
|
|
@@ -336,12 +339,14 @@ module.exports = (configuration) => {
|
|
|
336
339
|
req.soajs.log.error(err.message);
|
|
337
340
|
}
|
|
338
341
|
let _h = JSON.stringify(injectObj);
|
|
339
|
-
req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
|
|
342
|
+
// req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
|
|
343
|
+
req.headers.soajsinjectobj = _h; //encodeHeaderValue(_h);
|
|
340
344
|
return next();
|
|
341
345
|
});
|
|
342
346
|
} else {
|
|
343
347
|
let _h = JSON.stringify(injectObj);
|
|
344
|
-
req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
|
|
348
|
+
// req.headers.soajsinjectobj = Buffer.from(_h, 'ascii').toString('utf-8');
|
|
349
|
+
req.headers.soajsinjectobj = _h; //encodeHeaderValue(_h);
|
|
345
350
|
return next();
|
|
346
351
|
}
|
|
347
352
|
}
|
package/package.json
CHANGED
|
@@ -20,15 +20,17 @@ function startServer(serverConfig, callback) {
|
|
|
20
20
|
'lastname': "hage"
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
sApp.get('/passport/login', (req, res) =>
|
|
26
|
-
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
sApp.get('/passport/login', (req, res) => {
|
|
26
|
+
res.json(sReply);
|
|
27
|
+
});
|
|
28
|
+
|
|
27
29
|
mApp.get('/heartbeat', (req, res) => res.json(mReply));
|
|
28
|
-
|
|
30
|
+
|
|
29
31
|
let sAppServer = sApp.listen(serverConfig.s.port, () => console.log(`${serverConfig.name} service mock listening on port ${serverConfig.s.port}!`));
|
|
30
32
|
let mAppServer = mApp.listen(serverConfig.m.port, () => console.log(`${serverConfig.name} service mock listening on port ${serverConfig.m.port}!`));
|
|
31
|
-
|
|
33
|
+
|
|
32
34
|
return callback(
|
|
33
35
|
{
|
|
34
36
|
"sAppServer": sAppServer,
|
|
@@ -40,11 +42,11 @@ function startServer(serverConfig, callback) {
|
|
|
40
42
|
|
|
41
43
|
function killServer(config) {
|
|
42
44
|
console.log("killing server ....");
|
|
43
|
-
|
|
45
|
+
|
|
44
46
|
config.mAppServer.close((err) => {
|
|
45
47
|
console.log("...sAppServer: " + config.name);
|
|
46
48
|
});
|
|
47
|
-
|
|
49
|
+
|
|
48
50
|
config.sAppServer.close((err) => {
|
|
49
51
|
console.log("...mAppServer: " + config.name);
|
|
50
52
|
});
|