kayvee 3.17.0 → 3.18.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.
@@ -18,13 +18,13 @@ kayee_logger.setGlobalRouting(path.join(__dirname, "/kvconfig.yml"));
18
18
  function afterTest(count, callback) {
19
19
  var args = new Array(3);
20
20
  var i = 0;
21
- return function (err, arg1, arg2) {
22
- assert.ok(i++ < count, "callback called " + count + " times");
21
+ return (err, arg1, arg2) => {
22
+ assert.ok(i++ < count, `callback called ${count} times`);
23
23
  args[0] = args[0] || err;
24
24
  args[1] = args[1] || arg1;
25
25
  args[2] = args[2] || arg2;
26
26
  if (count === i) {
27
- callback.apply(null, args);
27
+ callback(...args);
28
28
  }
29
29
  };
30
30
  }
@@ -39,10 +39,10 @@ function createServer(server_type, clever_options, morgan_options, fn) {
39
39
  var middle = fn || noopMiddleware;
40
40
  var server = null;
41
41
  if (server_type === "http") {
42
- server = http.createServer(function (req, res) {
43
- logger(req, res, function (err) {
42
+ server = http.createServer((req, res) => {
43
+ logger(req, res, (err) => {
44
44
  // allow req, res alterations
45
- middle(req, res, function () {
45
+ middle(req, res, () => {
46
46
  if (err) {
47
47
  res.statusCode = 500;
48
48
  res.end(err.message);
@@ -57,26 +57,26 @@ function createServer(server_type, clever_options, morgan_options, fn) {
57
57
  else if (server_type === "express") {
58
58
  var app = express();
59
59
  app.use(logger);
60
- app.use(express.static(__dirname + "/static"));
61
- app.get("*", function (req, res) {
60
+ app.use(express.static(`${__dirname}/static`));
61
+ app.get("*", (req, res) => {
62
62
  res.header("Content-Length", 12345);
63
63
  res.end();
64
64
  });
65
65
  server = app;
66
66
  }
67
67
  else {
68
- throw new Error("unknown server type: " + server_type);
68
+ throw new Error(`unknown server type: ${server_type}`);
69
69
  }
70
70
  return server;
71
71
  }
72
- _.each(["http", "express"], function (serverType) {
73
- describe("middleware for *" + serverType + "* server: prototype pollution testing", function () {
74
- it("params with toString is stripped", function (done) {
75
- var cb = afterTest(2, function (err, res, line) {
72
+ _.each(["http", "express"], (serverType) => {
73
+ describe(`middleware for *${serverType}* server: prototype pollution testing`, () => {
74
+ it("params with toString is stripped", (done) => {
75
+ var cb = afterTest(2, (err, res, line) => {
76
76
  if (err) {
77
77
  return done(err);
78
78
  }
79
- var expected = {
79
+ const expected = {
80
80
  method: "GET",
81
81
  path: "/hello/world",
82
82
  params: "?",
@@ -105,27 +105,27 @@ _.each(["http", "express"], function (serverType) {
105
105
  assert.deepEqual(actual, expected);
106
106
  return done();
107
107
  });
108
- var stream = createLineStream(function (line) {
108
+ var stream = createLineStream((line) => {
109
109
  cb(null, null, line);
110
110
  });
111
111
  var options = {
112
112
  source: "test-app",
113
113
  ignore_dir: {
114
- directory: __dirname + "/static",
114
+ directory: `${__dirname}/static`,
115
115
  },
116
116
  };
117
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
117
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
118
118
  next();
119
119
  });
120
120
  // this one is logged
121
121
  request(server).get("/hello/world?toString=foo").expect(200, cb);
122
122
  });
123
- it("params from actual attack is stripped", function (done) {
124
- var cb = afterTest(2, function (err, res, line) {
123
+ it("params from actual attack is stripped", (done) => {
124
+ var cb = afterTest(2, (err, res, line) => {
125
125
  if (err) {
126
126
  return done(err);
127
127
  }
128
- var expected = {
128
+ const expected = {
129
129
  method: "GET",
130
130
  path: "/hello/world",
131
131
  params: "?",
@@ -154,41 +154,40 @@ _.each(["http", "express"], function (serverType) {
154
154
  assert.deepEqual(actual, expected);
155
155
  return done();
156
156
  });
157
- var stream = createLineStream(function (line) {
157
+ var stream = createLineStream((line) => {
158
158
  cb(null, null, line);
159
159
  });
160
160
  var options = {
161
161
  source: "test-app",
162
162
  ignore_dir: {
163
- directory: __dirname + "/static",
163
+ directory: `${__dirname}/static`,
164
164
  },
165
165
  };
166
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
166
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
167
167
  next();
168
168
  });
169
- var params = "__proto__[Expect]=xxx\n &constructor[prototype][Expect]=xxx";
169
+ const params = `__proto__[Expect]=xxx
170
+ &constructor[prototype][Expect]=xxx`;
170
171
  // this one is logged
171
- request(server).get("/hello/world?" + params).expect(200, cb);
172
+ request(server).get(`/hello/world?${params}`).expect(200, cb);
172
173
  });
173
174
  });
174
- describe("middleware for *" + serverType + "* server", function () {
175
- it("should throw error on intialization if `source` not set in `options`", function (done) {
175
+ describe(`middleware for *${serverType}* server`, () => {
176
+ it("should throw error on intialization if `source` not set in `options`", (done) => {
176
177
  var options = {};
177
- var erroringServer = function () {
178
- return createServer(serverType, options, null, function (req, res, next) {
179
- res.setHeader("some-header", "some-header-value");
180
- next();
181
- });
182
- };
178
+ var erroringServer = () => createServer(serverType, options, null, (req, res, next) => {
179
+ res.setHeader("some-header", "some-header-value");
180
+ next();
181
+ });
183
182
  assert.throws(erroringServer, Error, "Expected an error to be thrown");
184
183
  return done();
185
184
  });
186
- it("should pass default fields", function (done) {
187
- var cb = afterTest(2, function (err, res, line) {
185
+ it("should pass default fields", (done) => {
186
+ var cb = afterTest(2, (err, res, line) => {
188
187
  if (err) {
189
188
  return done(err);
190
189
  }
191
- var expected = {
190
+ const expected = {
192
191
  method: "GET",
193
192
  path: "/hello/world",
194
193
  params: "?a=1&b=2",
@@ -217,22 +216,22 @@ _.each(["http", "express"], function (serverType) {
217
216
  assert.deepEqual(actual, expected);
218
217
  return done();
219
218
  });
220
- var stream = createLineStream(function (line) {
219
+ var stream = createLineStream((line) => {
221
220
  cb(null, null, line);
222
221
  });
223
222
  var options = { source: "test-app" };
224
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
223
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
225
224
  res.setHeader("some-header", "some-header-value");
226
225
  next();
227
226
  });
228
227
  request(server).get("/hello/world?a=1&b=2").expect(200, cb);
229
228
  });
230
- it("should allow logging user-specified request headers", function (done) {
231
- var cb = afterTest(2, function (err, res, line) {
229
+ it("should allow logging user-specified request headers", (done) => {
230
+ var cb = afterTest(2, (err, res, line) => {
232
231
  if (err) {
233
232
  return done(err);
234
233
  }
235
- var expected = {
234
+ const expected = {
236
235
  "some-header": "some-header-value",
237
236
  "another-header": "another-header-value",
238
237
  method: "GET",
@@ -263,14 +262,14 @@ _.each(["http", "express"], function (serverType) {
263
262
  assert.deepEqual(actual, expected);
264
263
  return done();
265
264
  });
266
- var stream = createLineStream(function (line) {
265
+ var stream = createLineStream((line) => {
267
266
  cb(null, null, line);
268
267
  });
269
268
  var options = {
270
269
  source: "test-app",
271
270
  headers: ["some-header", "another-header"],
272
271
  };
273
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
272
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
274
273
  next();
275
274
  });
276
275
  request(server)
@@ -279,12 +278,12 @@ _.each(["http", "express"], function (serverType) {
279
278
  .set("another-header", "another-header-value")
280
279
  .expect(200, cb);
281
280
  });
282
- it("should allow logging from user-specified handlers", function (done) {
283
- var cb = afterTest(2, function (err, res, line) {
281
+ it("should allow logging from user-specified handlers", (done) => {
282
+ var cb = afterTest(2, (err, res, line) => {
284
283
  if (err) {
285
284
  return done(err);
286
285
  }
287
- var expected = {
286
+ const expected = {
288
287
  global: 1,
289
288
  global2: 2,
290
289
  url: "/hello/world?a=1&b=2",
@@ -316,24 +315,24 @@ _.each(["http", "express"], function (serverType) {
316
315
  assert.deepEqual(actual, expected);
317
316
  return done();
318
317
  });
319
- var stream = createLineStream(function (line) {
318
+ var stream = createLineStream((line) => {
320
319
  cb(null, null, line);
321
320
  });
322
321
  var options = {
323
322
  source: "test-app",
324
- handlers: [function () { return ({ global: 1 }); }, function () { return ({ global2: 2 }); }, function (req) { return ({ url: req.url }); }],
323
+ handlers: [() => ({ global: 1 }), () => ({ global2: 2 }), (req) => ({ url: req.url })],
325
324
  };
326
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
325
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
327
326
  next();
328
327
  });
329
328
  request(server).get("/hello/world?a=1&b=2").expect(200, cb);
330
329
  });
331
- it("should not log null or undefined values", function (done) {
332
- var cb = afterTest(2, function (err, res, line) {
330
+ it("should not log null or undefined values", (done) => {
331
+ var cb = afterTest(2, (err, res, line) => {
333
332
  if (err) {
334
333
  return done(err);
335
334
  }
336
- var expected = {
335
+ const expected = {
337
336
  method: "GET",
338
337
  path: "/hello/world",
339
338
  params: "?a=1&b=2",
@@ -362,26 +361,26 @@ _.each(["http", "express"], function (serverType) {
362
361
  assert.deepEqual(actual, expected);
363
362
  return done();
364
363
  });
365
- var stream = createLineStream(function (line) {
364
+ var stream = createLineStream((line) => {
366
365
  cb(null, null, line);
367
366
  });
368
367
  var options = {
369
368
  source: "test-app",
370
369
  // These values should not be logged
371
370
  headers: ["this-header-dne"],
372
- handlers: [function () { return ({ undef: undefined }); }],
371
+ handlers: [() => ({ undef: undefined })],
373
372
  };
374
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
373
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
375
374
  next();
376
375
  });
377
376
  request(server).get("/hello/world?a=1&b=2").expect(200, cb);
378
377
  });
379
- it("should keep processing if there are broken user-specified handlers", function (done) {
380
- var cb = afterTest(2, function (err, res, line) {
378
+ it("should keep processing if there are broken user-specified handlers", (done) => {
379
+ var cb = afterTest(2, (err, res, line) => {
381
380
  if (err) {
382
381
  return done(err);
383
382
  }
384
- var expected = {
383
+ const expected = {
385
384
  global: 1,
386
385
  method: "GET",
387
386
  path: "/hello/world",
@@ -411,31 +410,31 @@ _.each(["http", "express"], function (serverType) {
411
410
  assert.deepEqual(actual, expected);
412
411
  return done();
413
412
  });
414
- var stream = createLineStream(function (line) {
413
+ var stream = createLineStream((line) => {
415
414
  cb(null, null, line);
416
415
  });
417
416
  var options = {
418
417
  source: "test-app",
419
418
  handlers: [
420
419
  // This handler should be ignored, because it has an error
421
- function () {
420
+ () => {
422
421
  throw new Error("handler that throws an error");
423
422
  },
424
423
  // This handler should still work
425
- function () { return ({ global: 1 }); },
424
+ () => ({ global: 1 }),
426
425
  ],
427
426
  };
428
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
427
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
429
428
  next();
430
429
  });
431
430
  request(server).get("/hello/world?a=1&b=2").expect(200, cb);
432
431
  });
433
- it("should allow the user to override `base_handlers`", function (done) {
434
- var cb = afterTest(2, function (err, res, line) {
432
+ it("should allow the user to override `base_handlers`", (done) => {
433
+ var cb = afterTest(2, (err, res, line) => {
435
434
  if (err) {
436
435
  return done(err);
437
436
  }
438
- var expected = {
437
+ const expected = {
439
438
  global: 1,
440
439
  base: 1,
441
440
  deploy_env: "testing",
@@ -453,25 +452,25 @@ _.each(["http", "express"], function (serverType) {
453
452
  assert.deepEqual(actual, expected);
454
453
  return done();
455
454
  });
456
- var stream = createLineStream(function (line) {
455
+ var stream = createLineStream((line) => {
457
456
  cb(null, null, line);
458
457
  });
459
458
  var options = {
460
459
  source: "test-app",
461
- base_handlers: [function () { return ({ base: 1 }); }],
462
- handlers: [function () { return ({ global: 1 }); }],
460
+ base_handlers: [() => ({ base: 1 })],
461
+ handlers: [() => ({ global: 1 })],
463
462
  };
464
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
463
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
465
464
  next();
466
465
  });
467
466
  request(server).get("/hello/world?a=1&b=2").expect(200, cb);
468
467
  });
469
- it("should be robust to handlers that return non Objects", function (done) {
470
- var cb = afterTest(2, function (err, res, line) {
468
+ it("should be robust to handlers that return non Objects", (done) => {
469
+ var cb = afterTest(2, (err, res, line) => {
471
470
  if (err) {
472
471
  return done(err);
473
472
  }
474
- var expected = {
473
+ const expected = {
475
474
  global: 1,
476
475
  base: 1,
477
476
  source: "test-app",
@@ -489,25 +488,25 @@ _.each(["http", "express"], function (serverType) {
489
488
  assert.deepEqual(actual, expected);
490
489
  return done();
491
490
  });
492
- var stream = createLineStream(function (line) {
491
+ var stream = createLineStream((line) => {
493
492
  cb(null, null, line);
494
493
  });
495
494
  var options = {
496
495
  source: "test-app",
497
- base_handlers: [function () { return 1; }, function () { return "a"; }, function () { return []; }, function () { return ({}); }, function () { return ({ base: 1 }); }],
498
- handlers: [function () { return 1; }, function () { return "a"; }, function () { return []; }, function () { return ({}); }, function () { return ({ global: 1 }); }],
496
+ base_handlers: [() => 1, () => "a", () => [], () => ({}), () => ({ base: 1 })],
497
+ handlers: [() => 1, () => "a", () => [], () => ({}), () => ({ global: 1 })],
499
498
  };
500
- var server = createServer(serverType, options, { stream: stream, skip: null }, function (req, res, next) {
499
+ var server = createServer(serverType, options, { stream, skip: null }, (req, res, next) => {
501
500
  next();
502
501
  });
503
502
  request(server).get("/hello/world?a=1&b=2").expect(200, cb);
504
503
  });
505
- it("allows ignoring requests to files in a static directory", function (done) {
506
- var cb = afterTest(2, function (err, res, line) {
504
+ it("allows ignoring requests to files in a static directory", (done) => {
505
+ var cb = afterTest(2, (err, res, line) => {
507
506
  if (err) {
508
507
  return done(err);
509
508
  }
510
- var expected = {
509
+ const expected = {
511
510
  method: "GET",
512
511
  path: "/hello/world",
513
512
  params: "?",
@@ -536,16 +535,16 @@ _.each(["http", "express"], function (serverType) {
536
535
  assert.deepEqual(actual, expected);
537
536
  return done();
538
537
  });
539
- var stream = createLineStream(function (line) {
538
+ var stream = createLineStream((line) => {
540
539
  cb(null, null, line);
541
540
  });
542
541
  var options = {
543
542
  source: "test-app",
544
543
  ignore_dir: {
545
- directory: __dirname + "/static",
544
+ directory: `${__dirname}/static`,
546
545
  },
547
546
  };
548
- var server = createServer(serverType, options, { stream: stream }, function (req, res, next) {
547
+ var server = createServer(serverType, options, { stream }, (req, res, next) => {
549
548
  next();
550
549
  });
551
550
  // this line is never logged