3441f940d40251caa678b4e20f5d1f2c839c2ddb
4 const assert
= require('assert');
5 const sinon
= require('sinon'); // eslint-disable-line node/no-unpublished-require
6 const Logger
= require('../../src/logger');
7 const Config
= require('../../config');
9 describe('Logger', function () {
13 beforeEach(function () {
14 config
= new Config('test');
15 logger
= new Logger(config
);
16 Object
.keys(Logger
.nullLogger
).forEach((level
) => sinon
.stub(logger
.backend
, level
));
19 afterEach(function () {
23 it('logs', function () {
24 logger
.info('testScope', 'message', { baz: 'quux' }, { foo: 1 }, 'more other');
25 assert(logger
.backend
.info
.called
);
28 it('logs BigInts', function () {
29 logger
.info('testScope', 'message', { aBigInteger: BigInt(2) });
30 assert(logger
.backend
.info
.called
);
31 assert(logger
.backend
.info
.args
[0][0].includes('"2"'));
34 it('logs Errors', function () {
35 logger
.error('testScope', 'message', { e: new Error('an error') });
36 assert(logger
.backend
.error
.called
);
37 assert(logger
.backend
.error
.args
[0][0].includes('an error'));
40 it('masks credentials', function () {
41 logger
.info('testScope', 'message', {
45 credential: 'password',
49 assert(logger
.backend
.info
.called
);
50 assert(logger
.backend
.info
.args
[0][0].includes('"username"'));
51 assert(logger
.backend
.info
.args
[0][0].includes('"********"'));
54 it('strips uninteresting scope dross', function () {
55 logger
.info('testScope', 'message', {
59 'https://thuza.ratfeathers.com/': {
61 description: 'Access detailed profile information, including name, image, and url.',
62 application: 'IndieAuth',
64 'https://thuza.ratfeathers.com/',
67 isManuallyAdded: false,
73 description: 'Access detailed profile information, including name, image, and url.',
74 application: 'IndieAuth',
76 'https://thuza.ratfeathers.com/',
79 isManuallyAdded: false,
82 description: 'Include email address with detailed profile information.',
83 application: 'IndieAuth',
86 isManuallyAdded: false,
92 assert(logger
.backend
.info
.called
);
95 it('strips uninteresting scope dross from session', function () {
96 logger
.info('testScope', 'message', {
100 'https://thuza.ratfeathers.com/': {
102 description: 'Access detailed profile information, including name, image, and url.',
103 application: 'IndieAuth',
105 'https://thuza.ratfeathers.com/',
108 isManuallyAdded: false,
114 description: 'Access detailed profile information, including name, image, and url.',
115 application: 'IndieAuth',
117 'https://thuza.ratfeathers.com/',
120 isManuallyAdded: false,
123 description: 'Include email address with detailed profile information.',
124 application: 'IndieAuth',
127 isManuallyAdded: false,
133 assert(logger
.backend
.info
.called
);