update dependencies and devDependencies, fix lint issues
[squeep-indie-auther] / test / src / logger.js
1 'use strict';
2
3 const assert = require('assert');
4 const sinon = require('sinon');
5 const Logger = require('../../src/logger');
6 const Config = require('../../config');
7
8 describe('Logger', function () {
9 let config;
10 let logger;
11
12 beforeEach(function () {
13 config = new Config('test');
14 logger = new Logger(config);
15 Object.keys(Logger.nullLogger).forEach((level) => sinon.stub(logger.backend, level));
16 });
17
18 afterEach(function () {
19 sinon.restore();
20 });
21
22 it('logs', function () {
23 logger.info('testScope', 'message', { baz: 'quux' }, { foo: 1 }, 'more other');
24 assert(logger.backend.info.called);
25 });
26
27 it('logs BigInts', function () {
28 logger.info('testScope', 'message', { aBigInteger: BigInt(2) });
29 assert(logger.backend.info.called);
30 assert(logger.backend.info.args[0][0].includes('"2"'));
31 });
32
33 it('logs Errors', function () {
34 logger.error('testScope', 'message', { e: new Error('an error') });
35 assert(logger.backend.error.called);
36 assert(logger.backend.error.args[0][0].includes('an error'));
37 });
38
39 it('masks credentials', function () {
40 logger.info('testScope', 'message', {
41 ctx: {
42 parsedBody: {
43 identity: 'username',
44 credential: 'password',
45 },
46 },
47 });
48 assert(logger.backend.info.called);
49 assert(logger.backend.info.args[0][0].includes('"username"'));
50 assert(logger.backend.info.args[0][0].includes('"********"'));
51 });
52
53 it('masks noisy cookie header', function () {
54 logger.info('testScope', 'message', {
55 ctx: {
56 cookie: {
57 squeepSession: 'blahblahblahblahblah',
58 },
59 },
60 });
61 assert(logger.backend.info.called);
62 assert(logger.backend.info.args[0][0].includes('[scrubbed 20 bytes]'));
63 });
64
65 it('masks otp values', function () {
66 logger.info('teestScope', 'message', {
67 ctx: {
68 otpKey: '1234567890123456789012',
69 otpConfirmKey: '1234567890123456789012',
70 otpConfirmBox: 'xxxMysteryxxx',
71 otpState: 'xxxMysteryxxx',
72 },
73 });
74 assert(logger.backend.info.called);
75 assert(!logger.backend.info.args[0][0].includes('"1234567890123456789012"'));
76 assert(!logger.backend.info.args[0][0].includes('"xxxMysteryxxx"'));
77 });
78
79 it('strips uninteresting scope dross', function () {
80 logger.info('testScope', 'message', {
81 ctx: {
82 profilesScopes: {
83 profileScopes: {
84 'https://thuza.ratfeathers.com/': {
85 profile: {
86 description: 'Access detailed profile information, including name, image, and url.',
87 application: 'IndieAuth',
88 profiles: [
89 'https://thuza.ratfeathers.com/',
90 ],
91 isPermanent: true,
92 isManuallyAdded: false,
93 },
94 },
95 },
96 scopeIndex: {
97 profile: {
98 description: 'Access detailed profile information, including name, image, and url.',
99 application: 'IndieAuth',
100 profiles: [
101 'https://thuza.ratfeathers.com/',
102 ],
103 isPermanent: true,
104 isManuallyAdded: false,
105 },
106 email: {
107 description: 'Include email address with detailed profile information.',
108 application: 'IndieAuth',
109 profiles: [],
110 isPermanent: true,
111 isManuallyAdded: false,
112 },
113 },
114 },
115 },
116 });
117 assert(logger.backend.info.called);
118 });
119
120 it('strips uninteresting scope dross from session', function () {
121 logger.info('testScope', 'message', {
122 ctx: {
123 session: {
124 profileScopes: {
125 'https://thuza.ratfeathers.com/': {
126 profile: {
127 description: 'Access detailed profile information, including name, image, and url.',
128 application: 'IndieAuth',
129 profiles: [
130 'https://thuza.ratfeathers.com/',
131 ],
132 isPermanent: true,
133 isManuallyAdded: false,
134 },
135 },
136 },
137 scopeIndex: {
138 profile: {
139 description: 'Access detailed profile information, including name, image, and url.',
140 application: 'IndieAuth',
141 profiles: [
142 'https://thuza.ratfeathers.com/',
143 ],
144 isPermanent: true,
145 isManuallyAdded: false,
146 },
147 email: {
148 description: 'Include email address with detailed profile information.',
149 application: 'IndieAuth',
150 profiles: [],
151 isPermanent: true,
152 isManuallyAdded: false,
153 },
154 },
155 },
156 },
157 });
158 assert(logger.backend.info.called);
159 });
160
161 }); // Logger