X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Flogs.ts;h=ed7555fd76691023f3825c9df40acc4a7ed42674;hb=073deef8862f462de5f159a57877ef415ebe4c69;hp=bcd94dda30618e6310d31c774e372b16d51c4fd3;hpb=9e8789497377cac5554a622da605f5b89587aa9c;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/logs.ts b/server/tests/api/server/logs.ts index bcd94dda3..ed7555fd7 100644 --- a/server/tests/api/server/logs.ts +++ b/server/tests/api/server/logs.ts @@ -2,6 +2,7 @@ import 'mocha' import * as chai from 'chai' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -10,7 +11,7 @@ import { PeerTubeServer, setAccessTokensToServers, waitJobs -} from '@shared/extra-utils' +} from '@shared/server-commands' const expect = chai.expect @@ -71,7 +72,7 @@ describe('Test logs', function () { expect(logsString.includes('video 5')).to.be.false }) - it('Should get filter by level', async function () { + it('Should filter by level', async function () { this.timeout(20000) const now = new Date() @@ -94,6 +95,27 @@ describe('Test logs', function () { } }) + it('Should filter by tag', async function () { + const now = new Date() + + const { uuid } = await server.videos.upload({ attributes: { name: 'video 6' } }) + await waitJobs([ server ]) + + { + const body = await logsCommand.getLogs({ startDate: now, level: 'debug', tagsOneOf: [ 'toto' ] }) + expect(body).to.have.lengthOf(0) + } + + { + const body = await logsCommand.getLogs({ startDate: now, level: 'debug', tagsOneOf: [ uuid ] }) + expect(body).to.not.have.lengthOf(0) + + for (const line of body) { + expect(line.tags).to.contain(uuid) + } + } + }) + it('Should log ping requests', async function () { this.timeout(10000) @@ -177,6 +199,70 @@ describe('Test logs', function () { }) }) + describe('When creating log from the client', function () { + + it('Should create a warn client log', async function () { + const now = new Date() + + await server.logs.createLogClient({ + payload: { + level: 'warn', + url: 'http://example.com', + message: 'my super client message' + }, + token: null + }) + + const body = await logsCommand.getLogs({ startDate: now }) + const logsString = JSON.stringify(body) + + expect(logsString.includes('my super client message')).to.be.true + }) + + it('Should create an error authenticated client log', async function () { + const now = new Date() + + await server.logs.createLogClient({ + payload: { + url: 'https://example.com/page1', + level: 'error', + message: 'my super client message 2', + userAgent: 'super user agent', + meta: '{hello}', + stackTrace: 'super stack trace' + } + }) + + const body = await logsCommand.getLogs({ startDate: now }) + const logsString = JSON.stringify(body) + + expect(logsString.includes('my super client message 2')).to.be.true + expect(logsString.includes('super user agent')).to.be.true + expect(logsString.includes('super stack trace')).to.be.true + expect(logsString.includes('{hello}')).to.be.true + expect(logsString.includes('https://example.com/page1')).to.be.true + }) + + it('Should refuse to create client logs', async function () { + await server.kill() + + await server.run({ + log: { + accept_client_log: false + } + }) + + await server.logs.createLogClient({ + payload: { + level: 'warn', + url: 'http://example.com', + message: 'my super client message' + }, + expectedStatus: HttpStatusCode.FORBIDDEN_403 + }) + }) + }) + after(async function () { await cleanupTests([ server ]) })