X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Flib%2Fcommon.js;h=57c4113a9db986dbee499942e6e11ea0a78964b9;hb=aee1a77b22217893a609e581de7e4d3521e2c54e;hp=b802003af74c0a50d5a9ecf538c364df8eb682b7;hpb=29837f0eeb9fcb4c53426e5bd89e9bdf7e9d961b;p=squeep-api-dingus diff --git a/test/lib/common.js b/test/lib/common.js index b802003..57c4113 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -141,6 +141,46 @@ describe('common', function () { }); }); // 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 = { @@ -156,6 +196,32 @@ describe('common', function () { }); }); // 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 = { @@ -258,7 +324,6 @@ describe('common', function () { }); }); // requestId - describe('ensureLoggerLevels', function () { it('adds missing levels', function () { const result = common.ensureLoggerLevels(); @@ -378,4 +443,26 @@ describe('common', function () { }); }); // mergeDeep + describe('unfoldHeaderLines', function () { + it('folds', function () { + const lines = [ + 'Normal-Header: some header data', + 'Folded-Header: more data', + ' second line of data', + ' third line of data', + ]; + const expected = [ + 'Normal-Header: some header data', + 'Folded-Header: more data second line of data third line of data', + ]; + const result = common.unfoldHeaderLines(lines); + assert.deepStrictEqual(result, expected); + }); + it('covers no input', function () { + const lines = undefined; + const result = common.unfoldHeaderLines(); + assert.deepStrictEqual(result, lines); + }); + }); // unfoldHeaderLines + });