Files
kami-parse-server/spec/WinstonLoggerAdapter.spec.js

279 lines
9.1 KiB
JavaScript
Raw Normal View History

'use strict';
const WinstonLoggerAdapter = require('../lib/Adapters/Logger/WinstonLoggerAdapter')
.WinstonLoggerAdapter;
const request = require('../lib/request');
describe_only(() => {
return process.env.PARSE_SERVER_LOG_LEVEL !== 'debug';
})('info logs', () => {
it('Verify INFO logs', done => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
Winston 3 upgrade (#5496) * ⚡ Release 3.1.3 (#5267) * ⚡ Release 3.1.3 * Update CHANGELOG.md * :arrow_up: 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-15 09:03:33 +10:00
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');
Winston 3 upgrade (#5496) * ⚡ Release 3.1.3 (#5267) * ⚡ Release 3.1.3 * Update CHANGELOG.md * :arrow_up: 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-15 09:03:33 +10:00
expect(log.level).toEqual('info');
}
Winston 3 upgrade (#5496) * ⚡ Release 3.1.3 (#5267) * ⚡ Release 3.1.3 * Update CHANGELOG.md * :arrow_up: 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-15 09:03:33 +10:00
// 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');
Winston 3 upgrade (#5496) * ⚡ Release 3.1.3 (#5267) * ⚡ Release 3.1.3 * Update CHANGELOG.md * :arrow_up: 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-15 09:03:33 +10:00
expect(log).toBeUndefined();
done();
}
);
}
);
});
it('info logs should interpolate string', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('info', 'testing info logs with %s', 'replace');
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'info',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing info logs with replace');
expect(log);
});
it('info logs should interpolate json', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('info', 'testing info logs with %j', {
hello: 'world',
});
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'info',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing info logs with {"hello":"world"}');
expect(log);
});
it('info logs should interpolate number', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('info', 'testing info logs with %d', 123);
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'info',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing info logs with 123');
expect(log);
});
});
describe_only(() => {
return process.env.PARSE_SERVER_LOG_LEVEL !== 'debug';
})('error logs', () => {
it('Verify ERROR logs', done => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
Winston 3 upgrade (#5496) * ⚡ Release 3.1.3 (#5267) * ⚡ Release 3.1.3 * Update CHANGELOG.md * :arrow_up: 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-15 09:03:33 +10:00
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();
Changed FileLoggerAdapterSpec to fail gracefully on Windows Running tests on Windows caused this error: ``` B:\Projects\Parse Server\parse-server\spec\FileLoggerAdapter.spec.js:38 expect(results[0].message).toEqual('testing info logs'); ^ TypeError: Cannot read property 'message' of undefined at B:\Projects\Parse Server\parse-server\spec\FileLoggerAdapter.spec.js:38:26 at ParsePromise.<anonymous> (B:\Projects\Parse Server\parse-server\src\Adapters\Logger\FileLoggerAdapter.js:9:17440) at ParsePromise.wrappedResolvedCallback (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:139:41) at ParsePromise.resolve (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:72:36) at resolveOne (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:471:29) at ParsePromise.object.then.errors.(anonymous function) (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:480:13) at ParsePromise.wrappedResolvedCallback (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:139:41) at ParsePromise.resolve (B:\Projects\Parse Server\parse-server\node_modules\parse\lib\node\ParsePromise.js:72:36) at ReadFileContext.callback (B:\Projects\Parse Server\parse-server\src\Adapters\Logger\FileLoggerAdapter.js:9:16189) at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:303:13) ``` Rest of the tests could not be run as the test runner would break here. This change adds a check to fail when the FileLoggerAdapter returns an empty array from here: https://github.com/ParsePlatform/parse-server/blob/master/src/Adapters/Logger/FileLoggerAdapter.js#L191 Regarding the cause of the error itself, it is due to different filename separators in *nix and Windows. The FileLoggerAdapter would not save logs (have not tested this). This is a separate issue and should also be fixed.
2016-03-10 11:17:52 +05:30
}
Winston 3 upgrade (#5496) * ⚡ Release 3.1.3 (#5267) * ⚡ Release 3.1.3 * Update CHANGELOG.md * :arrow_up: 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-15 09:03:33 +10:00
}
);
});
it('Should filter on query', done => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs');
winstonLoggerAdapter.query(
{
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
},
results => {
expect(results.filter(e => e.level !== 'error').length).toBe(0);
done();
}
);
});
it('error logs should interpolate string', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs with %s', 'replace');
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing error logs with replace');
expect(log);
});
it('error logs should interpolate json', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs with %j', {
hello: 'world',
});
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing error logs with {"hello":"world"}');
expect(log);
});
it('error logs should interpolate number', async () => {
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('error', 'testing error logs with %d', 123);
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'error',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing error logs with 123');
expect(log);
});
});
describe_only(() => {
return process.env.PARSE_SERVER_LOG_LEVEL !== 'debug';
})('verbose logs', () => {
it_id('9ca72994-d255-4c11-a5a2-693c99ee2cdb')(it)('mask sensitive information in _User class', done => {
reconfigureServer({ verbose: true })
.then(() => createTestUser())
.then(() => {
2016-12-07 15:17:05 -08:00
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();
});
});
it('verbose logs should interpolate string', async () => {
await reconfigureServer({ verbose: true });
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('verbose', 'testing verbose logs with %s', 'replace');
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'verbose',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing verbose logs with replace');
expect(log);
});
it('verbose logs should interpolate json', async () => {
await reconfigureServer({ verbose: true });
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('verbose', 'testing verbose logs with %j', {
hello: 'world',
});
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'verbose',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing verbose logs with {"hello":"world"}');
expect(log);
});
it('verbose logs should interpolate number', async () => {
await reconfigureServer({ verbose: true });
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('verbose', 'testing verbose logs with %d', 123);
const results = await winstonLoggerAdapter.query({
from: new Date(Date.now() - 500),
size: 100,
level: 'verbose',
order: 'desc',
});
expect(results.length > 0).toBeTruthy();
const log = results.find(x => x.message === 'testing verbose logs with 123');
expect(log);
});
it('verbose logs should interpolate stdout', async () => {
await reconfigureServer({ verbose: true, silent: false, logsFolder: null });
spyOn(process.stdout, 'write');
const winstonLoggerAdapter = new WinstonLoggerAdapter();
winstonLoggerAdapter.log('verbose', 'testing verbose logs with %j', {
hello: 'world',
});
const firstLog = process.stdout.write.calls.first().args[0];
expect(firstLog).toBe('verbose: testing verbose logs with {"hello":"world"}\n');
});
});