## [Unreleased]
--
+- removed deprecated functions
## [v1.2.10] - 2023-07-20
*/
const get = (obj, prop, def) => obj && prop && (prop in obj) ? obj[prop] : def;
-/**
- * @param {http.ClientRequest} req
- * @param {http.ServerResponse} res
- * @param {Object} ctx
- * @deprecated after v1.2.5 (integrated into logger module)
- */
-const handlerLogData = (req, res, ctx) => ({
- req: requestLogData(req),
- res: responseLogData(res),
- ctx,
-});
-
/**
* Determine whether a client has already requested a resource,
* based on If-Modified-Since and If-None-Match headers.
return picked;
};
-/**
- * Return a subset of a request object, suitable for logging.
- * Obscures sensitive header values.
- * @param {http.ClientRequest} req
- * @deprecated after v1.2.5 (integrated into logger module)
- */
-const requestLogData = (req) => {
- const data = pick(req, [
- 'method',
- 'url',
- 'httpVersion',
- 'headers',
- 'trailers',
- ]);
- scrubHeaderObject(data);
- return data;
-};
-
-
-/**
- * Remove sensitive header data.
- * @param {Object} data
- * @param {Object} data.headers
- * @deprecated after v1.2.5 (integrated into logger module)
- */
-const scrubHeaderObject = (data) => {
- if (data?.headers && 'authorization' in data.headers) {
- data.headers = Object.assign({}, data.headers, {
- authorization: obscureAuthorizationHeader(data.headers['authorization']),
- });
- }
-};
-
-
-/**
- * Hide sensitive part of an Authorization header.
- * @param {String} authHeader
- * @returns {String}
- * @deprecated after v1.2.5 (integrated into logger module)
- */
-const obscureAuthorizationHeader = (authHeader) => {
- if (!authHeader) {
- return authHeader;
- }
- const space = authHeader.indexOf(' ');
- // This blurs entire string if no space found, because -1.
- return authHeader.slice(0, space + 1) + '*'.repeat(authHeader.length - (space + 1));
-};
-
-
-/**
- * Return a subset of a response object, suitable for logging.
- * @param {http.ServerResponse} res
- * @deprecated after v1.2.5 (integrated into logger module)
- */
-const responseLogData = (res) => {
- const response = pick(res, [
- 'statusCode',
- 'statusMessage',
- ]);
- response.headers = res.getHeaders();
- return response;
-};
-
-
/**
* Store all properties in defaultOptions on target from either options or defaultOptions.
* @param {Object} target
return uuid.v1();
};
-/**
- * Do nothing.
- */
-const nop = () => { /**/ };
-
-/**
- * A logger object which does nothing.
- */
-const nullLogger = {
- error: nop,
- warn: nop,
- info: nop,
- log: nop,
- debug: nop,
-};
-
-/**
- * Populates any absent logger level functions on a logger object.
- * @param {Object} logger
- * @returns {Object}
- * @deprecated after v1.2.9 (this is not our responsibility)
- */
-const ensureLoggerLevels = (logger = {}) => {
- for (const level in nullLogger) {
- if (! (level in logger)) {
- logger[level] = nullLogger[level];
- }
- }
- return logger;
-};
-
/**
* Merges folded header lines
* @param {String[]} lines
};
module.exports = {
- ensureLoggerLevels,
fileScope,
generateETag,
get,
- handlerLogData,
httpStatusCodeClass,
isClientCached,
mergeDeep,
mergeEnum,
- nop,
- nullLogger,
- obscureAuthorizationHeader,
pick,
requestId,
- requestLogData,
- responseLogData,
- scrubHeaderObject,
setOptions,
splitFirst,
unfoldHeaderLines,
* @param {Boolean} options.trustProxy trust some header data to be provided by proxy
* @param {Object} options.querystring alternate qs parser to use
*/
- constructor(logger = common.nullLogger, options = {}) {
+ constructor(logger = console, options = {}) {
common.setOptions(this, defaultOptions, options);
this.router = new Router(options);
});
}); // pick
- describe('requestLogData', function () {
- it('gives data', function () {
- const req = {
- method: 'GET',
- somethingElse: 'blah',
- };
- const result = common.requestLogData(req);
- assert.deepStrictEqual(result, {
- method: 'GET',
- });
- });
- }); // requestLogData
-
- describe('obscureAuthorizationHeader', function () {
- it('obscures basic data', function () {
- const authHeader = 'Basic Zm9vOmJhcg==';
- const expected = 'Basic ************';
- const result = common.obscureAuthorizationHeader(authHeader);
- assert.strictEqual(result, expected);
- });
- it('obscures all of other types', function () {
- const authHeader = 'someWeirdAuth';
- const expected = '*************';
- const result = common.obscureAuthorizationHeader(authHeader);
- assert.strictEqual(result, expected);
- });
- it('does nothing when empty', function () {
- const authHeader = undefined;
- const expected = undefined;
- const result = common.obscureAuthorizationHeader(authHeader);
- assert.strictEqual(result, expected);
- });
- }); // obscureAuthorizationHeader
-
- describe('scrubHeaderObject', function () {
- it('', function () {
- const data = {
- headers: {
- 'foo': 'bar',
- 'authorization': 'Basic Zm9vOmJhcg==',
- },
- };
- const expected = {
- headers: {
- 'foo': 'bar',
- 'authorization': 'Basic ************',
- },
- };
- common.scrubHeaderObject(data);
- assert.deepStrictEqual(data, expected);
- });
- }); // scrubHeaderObject
-
- describe('responseLogData', function () {
- it('gives data', function () {
- const res = {
- getHeaders: () => ({}),
- statusCode: 200,
- blah: 'blah',
- };
- const result = common.responseLogData(res);
- assert.deepStrictEqual(result, {
- headers: {},
- statusCode: 200,
- });
- });
- }); // responseLogData
-
- describe('handlerLogData', function () {
- it('covers', function () {
- const req = {
- method: 'GET',
- somethingElse: 'blah',
- };
- const res = {
- getHeaders: () => ({}),
- statusCode: 200,
- blah: 'blah',
- };
- const ctx = {};
- const result = common.handlerLogData(req, res, ctx);
- assert.deepStrictEqual(result, {
- req: {
- method: 'GET',
- },
- res: {
- headers: {},
- statusCode: 200,
- },
- ctx: {},
- });
- });
- }); // handlerLogData
-
describe('setOptions', function () {
it('sets options', function () {
const expected = {
});
}); // requestId
- describe('ensureLoggerLevels', function () {
- it('adds missing levels', function () {
- const result = common.ensureLoggerLevels();
- assert.deepStrictEqual(result, common.nullLogger);
- });
- }); // ensureLoggerLevels
-
describe('httpStatusCodeClass', function () {
it('works', function () {
for (const [statusCode, statusClassExpected] of Object.entries({
const noExpectedException = 'did not get expected exception';
+const noLogger = {
+ debug: () => {},
+ error: () => {},
+};
+
describe('Dingus', function () {
let dingus;
beforeEach(function () {
- dingus = new Dingus();
+ dingus = new Dingus(noLogger, {});
});
afterEach(function () {
sinon.restore();
describe('constructor', function () {
it('covers', function () {
- const d = new Dingus({}, {});
+ const d = new Dingus();
assert(d);
});
}); // constructor
});
it('returns normal path', function () {
const p = '////a///b/./bar/..///c';
- const expected = '/a/b/c'
+ const expected = '/a/b/c';
const r = dingus._normalizePath(p);
assert.strictEqual(r, expected);
});
const expected = {
clientAddress: '',
clientProtocol: 'http',
- }
+ };
dingus.clientAddressContext(req, res, ctx);
assert.deepStrictEqual(ctx, expected);
assert(!req.getHeader.called);
const expected = {
clientAddress: '::1',
clientProtocol: 'https',
- }
+ };
req.connection.remoteAddress = '::1';
req.connection.encrypted = true;
dingus.clientAddressContext(req, res, ctx);
const req = {};
const res = {};
const ctx = {};
- sinon.stub(dingus, 'bodyData').resolves('{"foo":"bar"}')
+ sinon.stub(dingus, 'bodyData').resolves('{"foo":"bar"}');
sinon.stub(Dingus, 'getRequestContentType').returns(Enum.ContentType.ApplicationJson);
await dingus.ingestBody(req, res, ctx);
assert.deepStrictEqual(ctx.parsedBody, { foo: 'bar' });
const assert = require('assert');
const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
const Router = require('../../lib/router');
-const PathParameter = require('../../lib/router/path-parameter')
+const PathParameter = require('../../lib/router/path-parameter');
const { DingusError } = require('../../lib/errors');
const noExpectedException = 'did not get expected exception';