Files
kami-parse-server/spec/WinstonLoggerAdapter.spec.js
Sam Ilic 6ffc41345f Winston 3 upgrade (#5496)
*  Release 3.1.3 (#5267)

*  Release 3.1.3

* Update CHANGELOG.md

* ⬆️ Bump winston and winston-daily-rotate-file

Bumps [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file). These dependencies needed to be updated together.

Updates `winston` from 2.4.4 to 3.1.0
- [Release notes](https://github.com/winstonjs/winston/releases)
- [Changelog](https://github.com/winstonjs/winston/blob/master/CHANGELOG.md)
- [Commits](https://github.com/winstonjs/winston/compare/2.4.4...3.1.0)

Updates `winston-daily-rotate-file` from 1.7.2 to 3.5.1
- [Release notes](https://github.com/winstonjs/winston-daily-rotate-file/releases)
- [Commits](https://github.com/winstonjs/winston-daily-rotate-file/compare/v1.7.2...v3.5.1)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Rewrote WinstonLogger to work with winston 3.x api

* Changed winston logger test to use winston-transport

* Added winston-transport dependency

* Close and remove transports before adding them again

* Changed to strict equal

* Override adapter name

* Updated and added getLogs tests

* Bump winston and winston-daily-rotate-file

Bumps [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file). These dependencies needed to be updated together.

Updates `winston` from 2.4.4 to 3.2.0
- [Release notes](https://github.com/winstonjs/winston/releases)
- [Changelog](https://github.com/winstonjs/winston/blob/master/CHANGELOG.md)
- [Commits](https://github.com/winstonjs/winston/compare/2.4.4...3.2.0)

Updates `winston-daily-rotate-file` from 1.7.2 to 3.6.0
- [Release notes](https://github.com/winstonjs/winston-daily-rotate-file/releases)
- [Commits](https://github.com/winstonjs/winston-daily-rotate-file/compare/v1.7.2...v3.6.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>

* Fixed tests, updated parse logging

* Fixed tests, better error logging

* Fix failing tests

* Updates as per review
2019-04-14 18:03:33 -05:00

117 lines
3.3 KiB
JavaScript

'use strict';
const WinstonLoggerAdapter = require('../lib/Adapters/Logger/WinstonLoggerAdapter')
.WinstonLoggerAdapter;
const request = require('../lib/request');
describe('info logs', () => {
it('Verify INFO logs', done => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('info', 'testing info logs with 1234');
winstonLoggerAdapter.query(
{
from: new Date(Date.now() - 500),
size: 100,
level: 'info',
order: 'desc',
},
results => {
if (results.length == 0) {
fail('The adapter should return non-empty results');
} else {
const log = results.find(
x => x.message === 'testing info logs with 1234'
);
expect(log.level).toEqual('info');
}
// Check the error log
// Regression #2639
winstonLoggerAdapter.query(
{
from: new Date(Date.now() - 200),
size: 100,
level: 'error',
},
errors => {
const log = errors.find(
x => x.message === 'testing info logs with 1234'
);
expect(log).toBeUndefined();
done();
}
);
}
);
});
});
describe('error logs', () => {
it('Verify ERROR logs', done => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs');
winstonLoggerAdapter.query(
{
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
},
results => {
if (results.length == 0) {
fail('The adapter should return non-empty results');
done();
} else {
expect(results[0].message).toEqual('testing error logs');
done();
}
}
);
});
});
describe('verbose logs', () => {
it('mask sensitive information in _User class', done => {
reconfigureServer({ verbose: true })
.then(() => createTestUser())
.then(() => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
return winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'verbose',
});
})
.then(results => {
const logString = JSON.stringify(results);
expect(logString.match(/\*\*\*\*\*\*\*\*/g).length).not.toBe(0);
expect(logString.match(/moon-y/g)).toBe(null);
const headers = {
'X-Parse-Application-Id': 'test',
'X-Parse-REST-API-Key': 'rest',
};
request({
headers: headers,
url: 'http://localhost:8378/1/login?username=test&password=moon-y',
}).then(() => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
return winstonLoggerAdapter
.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'verbose',
})
.then(results => {
const logString = JSON.stringify(results);
expect(logString.match(/\*\*\*\*\*\*\*\*/g).length).not.toBe(0);
expect(logString.match(/moon-y/g)).toBe(null);
done();
});
});
})
.catch(err => {
fail(JSON.stringify(err));
done();
});
});
});