2020-01-31 15:56:52 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2019-04-10 13:26:33 +00:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-01-13 09:15:38 +00:00
|
|
|
import * as chai from 'chai'
|
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
flushAndRunServer,
|
|
|
|
killallServers,
|
2021-07-06 08:34:29 +00:00
|
|
|
LogsCommand,
|
2021-01-13 09:15:38 +00:00
|
|
|
reRunServer,
|
|
|
|
ServerInfo,
|
2021-07-06 08:34:29 +00:00
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
|
|
|
} from '@shared/extra-utils'
|
2019-04-10 13:26:33 +00:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test logs', function () {
|
|
|
|
let server: ServerInfo
|
2021-07-06 08:34:29 +00:00
|
|
|
let logsCommand: LogsCommand
|
2019-04-10 13:26:33 +00:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2019-04-24 08:53:40 +00:00
|
|
|
server = await flushAndRunServer(1)
|
2019-04-10 13:26:33 +00:00
|
|
|
await setAccessTokensToServers([ server ])
|
2021-07-06 08:34:29 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
logsCommand = server.logs
|
2019-04-10 13:26:33 +00:00
|
|
|
})
|
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
describe('With the standard log file', function () {
|
2021-01-13 08:38:19 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
it('Should get logs with a start date', async function () {
|
2021-02-11 13:34:44 +00:00
|
|
|
this.timeout(20000)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 1' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
const now = new Date()
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 2' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getLogs({ startDate: now })
|
|
|
|
const logsString = JSON.stringify(body)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
expect(logsString.includes('video 1')).to.be.false
|
|
|
|
expect(logsString.includes('video 2')).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get logs with an end date', async function () {
|
2021-02-11 13:34:44 +00:00
|
|
|
this.timeout(30000)
|
2019-12-11 13:14:01 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 3' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
|
|
|
|
|
|
|
const now1 = new Date()
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 4' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
|
|
|
|
|
|
|
const now2 = new Date()
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 5' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 })
|
|
|
|
const logsString = JSON.stringify(body)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
expect(logsString.includes('video 3')).to.be.false
|
|
|
|
expect(logsString.includes('video 4')).to.be.true
|
|
|
|
expect(logsString.includes('video 5')).to.be.false
|
|
|
|
})
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
it('Should get filter by level', async function () {
|
2021-02-11 13:34:44 +00:00
|
|
|
this.timeout(20000)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
const now = new Date()
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 6' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
{
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
|
|
|
|
const logsString = JSON.stringify(body)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
expect(logsString.includes('video 6')).to.be.true
|
|
|
|
}
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
{
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getLogs({ startDate: now, level: 'warn' })
|
|
|
|
const logsString = JSON.stringify(body)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
expect(logsString.includes('video 6')).to.be.false
|
|
|
|
}
|
|
|
|
})
|
2021-01-13 08:38:19 +00:00
|
|
|
|
|
|
|
it('Should log ping requests', async function () {
|
2021-02-11 13:34:44 +00:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2021-01-13 08:38:19 +00:00
|
|
|
const now = new Date()
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.servers.ping()
|
2021-01-13 08:38:19 +00:00
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
|
|
|
|
const logsString = JSON.stringify(body)
|
2021-01-13 08:38:19 +00:00
|
|
|
|
|
|
|
expect(logsString.includes('/api/v1/ping')).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not log ping requests', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-09 13:37:43 +00:00
|
|
|
await killallServers([ server ])
|
2021-01-13 08:38:19 +00:00
|
|
|
|
|
|
|
await reRunServer(server, { log: { log_ping_requests: false } })
|
|
|
|
|
|
|
|
const now = new Date()
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.servers.ping()
|
2021-01-13 08:38:19 +00:00
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
|
|
|
|
const logsString = JSON.stringify(body)
|
2021-01-13 08:38:19 +00:00
|
|
|
|
|
|
|
expect(logsString.includes('/api/v1/ping')).to.be.false
|
|
|
|
})
|
2019-04-10 13:26:33 +00:00
|
|
|
})
|
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
describe('With the audit log', function () {
|
|
|
|
it('Should get logs with a start date', async function () {
|
2021-02-11 13:34:44 +00:00
|
|
|
this.timeout(20000)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 7' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
const now = new Date()
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 8' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getAuditLogs({ startDate: now })
|
|
|
|
const logsString = JSON.stringify(body)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
expect(logsString.includes('video 7')).to.be.false
|
|
|
|
expect(logsString.includes('video 8')).to.be.true
|
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
expect(body).to.have.lengthOf(1)
|
2019-12-11 13:14:01 +00:00
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
const item = body[0]
|
2019-12-11 13:14:01 +00:00
|
|
|
|
|
|
|
const message = JSON.parse(item.message)
|
|
|
|
expect(message.domain).to.equal('videos')
|
|
|
|
expect(message.action).to.equal('create')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get logs with an end date', async function () {
|
2021-02-11 13:34:44 +00:00
|
|
|
this.timeout(30000)
|
2019-12-11 13:14:01 +00:00
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 9' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
|
|
|
|
|
|
|
const now1 = new Date()
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 10' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
|
|
|
|
|
|
|
const now2 = new Date()
|
|
|
|
|
2021-07-16 07:04:35 +00:00
|
|
|
await server.videos.upload({ attributes: { name: 'video 11' } })
|
2019-12-11 13:14:01 +00:00
|
|
|
await waitJobs([ server ])
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2021-07-06 08:34:29 +00:00
|
|
|
const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 })
|
|
|
|
const logsString = JSON.stringify(body)
|
2019-04-10 13:26:33 +00:00
|
|
|
|
2019-12-11 13:14:01 +00:00
|
|
|
expect(logsString.includes('video 9')).to.be.false
|
|
|
|
expect(logsString.includes('video 10')).to.be.true
|
|
|
|
expect(logsString.includes('video 11')).to.be.false
|
|
|
|
})
|
2019-04-10 13:26:33 +00:00
|
|
|
})
|
|
|
|
|
2019-04-24 13:10:37 +00:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests([ server ])
|
2019-04-10 13:26:33 +00:00
|
|
|
})
|
|
|
|
})
|