update devDependencies, clean up lint issues
[squeep-authentication-module] / test / lib / common.js
1 'use strict';
2
3 const assert = require('node:assert');
4 const sinon = require('sinon');
5 const stubLogger = require('../stub-logger');
6 const common = require('../../lib/common');
7
8 describe('Common', function () {
9
10 describe('freezeDeep', function () {
11 it('covers', function () {
12 const obj = {
13 value: true,
14 subObj: {
15 subValue: true,
16 },
17 };
18 common.freezeDeep(obj);
19 assert.throws(() => obj.value = false, TypeError);
20 assert.throws(() => obj.subObj.subValue = false, TypeError);
21 });
22 }); // freezeDeep
23
24 describe('omit', function () {
25 it('does the expected', function () {
26 const orig = {
27 foo: 'foo',
28 bar: 23,
29 quux: { squawk: true },
30 zounds: false,
31 };
32 const omitted = ['foo', 'quux'];
33 const expected = {
34 bar: 23,
35 zounds: false,
36 };
37 const result = common.omit(orig, omitted);
38 assert.deepStrictEqual(result, expected);
39 });
40 }); // omit
41
42 describe('mysteryBoxLogger', function () {
43 let mbl;
44 beforeEach(function () {
45 stubLogger._reset();
46 mbl = common.mysteryBoxLogger(stubLogger, 'test:scope');
47 });
48 afterEach(function () {
49 sinon.restore();
50 });
51 it('covers', function () {
52 const stat = {
53 packageName: 'fake-mystery-box',
54 packageVersion: '0.0.0',
55 method: 'pack',
56 data: 'exists',
57 };
58 mbl(stat);
59 assert(stubLogger.debug.called);
60 });
61 }); // mysteryBoxLogger
62
63 describe('obscureAuthorizationHeader', function () {
64 it('blurs Bearer token', function () {
65 const result = common.obscureAuthorizationHeader('Bearer foo');
66 assert.strictEqual(result, 'Bearer ***');
67 });
68 it('blurs entire string for other', function () {
69 const result = common.obscureAuthorizationHeader('abcdef');
70 assert.strictEqual(result, '******');
71 });
72 it('covers empty string', function () {
73 const a = '';
74 const result = common.obscureAuthorizationHeader(a);
75 assert.strictEqual(result, a);
76
77 });
78 });
79
80 }); // Common