soajs.controller 4.2.41 → 4.2.42

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.
@@ -194,6 +194,9 @@ module.exports = (configuration) => {
194
194
  const extraOptions = {};
195
195
 
196
196
  if (monitor && !monitor_service_blacklist && monitor.req_response) {
197
+ const MAX_RESPONSE_SIZE = process.env.SOAJS_MAX_RESPONSE_SIZE || 10 * 1024 * 1024; // 10MB default
198
+ let responseSize = 0;
199
+ let responseExceeded = false;
197
200
  extraOptions.events = {
198
201
  "response": (_resContentType) => {
199
202
  resContentType = _resContentType;
@@ -209,10 +212,18 @@ module.exports = (configuration) => {
209
212
  },
210
213
  "data": (chunk) => {
211
214
  if (!isStream && allowedContentType) {
212
- if (!monitoObj.response) {
213
- monitoObj.response = chunk;
214
- } else {
215
- monitoObj.response += chunk;
215
+ responseSize += chunk.length;
216
+ if (responseSize > MAX_RESPONSE_SIZE) {
217
+ if (!responseExceeded) {
218
+ responseExceeded = true;
219
+ monitoObj.response = "{\"error\": \"Response body exceeds maximum size limit\"}";
220
+ }
221
+ } else if (!responseExceeded) {
222
+ if (!monitoObj.response) {
223
+ monitoObj.response = chunk;
224
+ } else {
225
+ monitoObj.response += chunk;
226
+ }
216
227
  }
217
228
  } else {
218
229
  monitoObj.response = "{\"contentType\": \"is stream or not allowed\", \"value': \"" + resContentType + "\"}";
@@ -47,6 +47,9 @@ module.exports = () => {
47
47
  "json": true,
48
48
  "method": "POST"
49
49
  };
50
+ if (lastSeen.network) {
51
+ options.body = { "network": lastSeen.network };
52
+ }
50
53
  if (req.headers && req.headers.soajsinjectobj) {
51
54
  options.headers = { "soajsinjectobj": req.headers.soajsinjectobj };
52
55
  }
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.41",
4
+ "version": "4.2.42",
5
5
  "author": {
6
6
  "name": "soajs team",
7
7
  "email": "team@soajs.org"
@@ -166,7 +166,7 @@ describe("Integration for Usecase 1", function () {
166
166
  };
167
167
  requester('get', options, (error, body) => {
168
168
  assert.ok(body);
169
- assert.equal(body.data.type, "endpoint");
169
+ assert.strictEqual(body.data.type, "endpoint");
170
170
  done();
171
171
  });
172
172
  });
@@ -252,7 +252,7 @@ describe("Integration for Usecase 1", function () {
252
252
  }
253
253
  };
254
254
  requester('get', options, (error, body) => {
255
- assert.equal(body.data.id, '/muser/:12?access_token=cfb209a91b23896820f510aadbf1f4284b512123');
255
+ assert.strictEqual(body.data.id, '/muser/:12?access_token=cfb209a91b23896820f510aadbf1f4284b512123');
256
256
  done();
257
257
  });
258
258
  });
@@ -7,7 +7,7 @@ const nock = require('nock')
7
7
 
8
8
  describe("Unit test for: mw - lastSeen", () => {
9
9
 
10
- it("success - default from environment", (done) => {
10
+ it("success - with network", (done) => {
11
11
  let res = {};
12
12
  let req = {
13
13
  getClientIP: () => {
@@ -42,7 +42,8 @@ describe("Unit test for: mw - lastSeen", () => {
42
42
  gateway: {
43
43
  value: {
44
44
  lastSeen: {
45
- active: true
45
+ active: true,
46
+ network: "YAYA"
46
47
  }
47
48
  }
48
49
  }
@@ -51,11 +52,11 @@ describe("Unit test for: mw - lastSeen", () => {
51
52
  }
52
53
  };
53
54
  const scope = nock('http://urac.fake:4001')
54
- .post('/user/last/seen')
55
+ .post('/user/last/seen', "{\"network\":\"YAYA\"}")
55
56
  .reply(200, {
56
57
  result: true,
57
58
  data: true
58
- })
59
+ });
59
60
  let functionMw = mw({});
60
61
  functionMw(req, res, (error) => {
61
62
  assert.ifError(error);
@@ -83,7 +83,7 @@ describe("Unit test for: mw - mt utils", () => {
83
83
  }
84
84
  };
85
85
  utils.securityDeviceCheck(obj, function (error, obj) {
86
- assert.equal(error, 156);
86
+ assert.strictEqual(error, 156);
87
87
  done();
88
88
  });
89
89
  });
@@ -132,7 +132,7 @@ describe("Unit test for: mw - mt utils", () => {
132
132
  }
133
133
  };
134
134
  utils.securityDeviceCheck(obj, function (error, obj) {
135
- assert.equal(error, 156);
135
+ assert.strictEqual(error, 156);
136
136
  done();
137
137
  });
138
138
  });
@@ -181,7 +181,7 @@ describe("Unit test for: mw - mt utils", () => {
181
181
  }
182
182
  };
183
183
  utils.securityDeviceCheck(obj, function (error, obj) {
184
- assert.equal(error, 156);
184
+ assert.strictEqual(error, 156);
185
185
  done();
186
186
  });
187
187
  });
@@ -223,7 +223,7 @@ describe("Unit test for: mw - mt utils", () => {
223
223
  }
224
224
  };
225
225
  utils.securityDeviceCheck(obj, function (error, obj) {
226
- assert.equal(error, 156);
226
+ assert.strictEqual(error, 156);
227
227
  done();
228
228
  });
229
229
  });
@@ -265,7 +265,7 @@ describe("Unit test for: mw - mt utils", () => {
265
265
  }
266
266
  };
267
267
  utils.securityDeviceCheck(obj, function (error, obj) {
268
- assert.equal(error, 156);
268
+ assert.strictEqual(error, 156);
269
269
  done();
270
270
  });
271
271
  });
@@ -305,7 +305,7 @@ describe("Unit test for: mw - mt utils", () => {
305
305
  }
306
306
  };
307
307
  utils.securityDeviceCheck(obj, function (error, obj) {
308
- assert.equal(error, 156);
308
+ assert.strictEqual(error, 156);
309
309
  done();
310
310
  });
311
311
  });