1142a1371fbac50a0b0b7145f69457bea43fb54b
3 const assert
= require('assert');
4 const sinon
= require('sinon');
5 const Logger
= require('../../src/logger');
6 const Config
= require('../../config');
8 describe('Logger', function () {
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
));
18 afterEach(function () {
22 it('logs', function () {
23 logger
.info('testScope', 'message', { baz: 'quux' }, { foo: 1 }, 'more other');
24 assert(logger
.backend
.info
.called
);
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"'));
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'));
39 it('masks credentials', function () {
40 logger
.info('testScope', 'message', {
44 credential: 'password',
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('"********"'));
53 it('masks noisy cookie header', function () {
54 logger
.info('testScope', 'message', {
57 squeepSession: 'blahblahblahblahblah',
61 assert(logger
.backend
.info
.called
);
62 assert(logger
.backend
.info
.args
[0][0].includes('[scrubbed 20 bytes]'));
65 it('masks otp values', function () {
66 logger
.info('teestScope', 'message', {
68 otpKey: '1234567890123456789012',
69 otpConfirmKey: '1234567890123456789012',
70 otpConfirmBox: 'xxxMysteryxxx',
71 otpState: 'xxxMysteryxxx',
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"'));
79 it('strips uninteresting scope dross', function () {
80 logger
.info('testScope', 'message', {
84 'https://thuza.ratfeathers.com/': {
86 description: 'Access detailed profile information, including name, image, and url.',
87 application: 'IndieAuth',
89 'https://thuza.ratfeathers.com/',
92 isManuallyAdded: false,
98 description: 'Access detailed profile information, including name, image, and url.',
99 application: 'IndieAuth',
101 'https://thuza.ratfeathers.com/',
104 isManuallyAdded: false,
107 description: 'Include email address with detailed profile information.',
108 application: 'IndieAuth',
111 isManuallyAdded: false,
117 assert(logger
.backend
.info
.called
);
120 it('strips uninteresting scope dross from session', function () {
121 logger
.info('testScope', 'message', {
125 'https://thuza.ratfeathers.com/': {
127 description: 'Access detailed profile information, including name, image, and url.',
128 application: 'IndieAuth',
130 'https://thuza.ratfeathers.com/',
133 isManuallyAdded: false,
139 description: 'Access detailed profile information, including name, image, and url.',
140 application: 'IndieAuth',
142 'https://thuza.ratfeathers.com/',
145 isManuallyAdded: false,
148 description: 'Include email address with detailed profile information.',
149 application: 'IndieAuth',
152 isManuallyAdded: false,
158 assert(logger
.backend
.info
.called
);