1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
12 setAccessTokensToServers,
14 } from '@shared/extra-utils'
16 const expect = chai.expect
18 describe('Test logs', function () {
19 let server: ServerInfo
20 let logsCommand: LogsCommand
22 before(async function () {
25 server = await flushAndRunServer(1)
26 await setAccessTokensToServers([ server ])
28 logsCommand = server.logs
31 describe('With the standard log file', function () {
33 it('Should get logs with a start date', async function () {
36 await server.videos.upload({ attributes: { name: 'video 1' } })
37 await waitJobs([ server ])
39 const now = new Date()
41 await server.videos.upload({ attributes: { name: 'video 2' } })
42 await waitJobs([ server ])
44 const body = await logsCommand.getLogs({ startDate: now })
45 const logsString = JSON.stringify(body)
47 expect(logsString.includes('video 1')).to.be.false
48 expect(logsString.includes('video 2')).to.be.true
51 it('Should get logs with an end date', async function () {
54 await server.videos.upload({ attributes: { name: 'video 3' } })
55 await waitJobs([ server ])
57 const now1 = new Date()
59 await server.videos.upload({ attributes: { name: 'video 4' } })
60 await waitJobs([ server ])
62 const now2 = new Date()
64 await server.videos.upload({ attributes: { name: 'video 5' } })
65 await waitJobs([ server ])
67 const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 })
68 const logsString = JSON.stringify(body)
70 expect(logsString.includes('video 3')).to.be.false
71 expect(logsString.includes('video 4')).to.be.true
72 expect(logsString.includes('video 5')).to.be.false
75 it('Should get filter by level', async function () {
78 const now = new Date()
80 await server.videos.upload({ attributes: { name: 'video 6' } })
81 await waitJobs([ server ])
84 const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
85 const logsString = JSON.stringify(body)
87 expect(logsString.includes('video 6')).to.be.true
91 const body = await logsCommand.getLogs({ startDate: now, level: 'warn' })
92 const logsString = JSON.stringify(body)
94 expect(logsString.includes('video 6')).to.be.false
98 it('Should log ping requests', async function () {
101 const now = new Date()
103 await server.servers.ping()
105 const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
106 const logsString = JSON.stringify(body)
108 expect(logsString.includes('/api/v1/ping')).to.be.true
111 it('Should not log ping requests', async function () {
114 await killallServers([ server ])
116 await reRunServer(server, { log: { log_ping_requests: false } })
118 const now = new Date()
120 await server.servers.ping()
122 const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
123 const logsString = JSON.stringify(body)
125 expect(logsString.includes('/api/v1/ping')).to.be.false
129 describe('With the audit log', function () {
130 it('Should get logs with a start date', async function () {
133 await server.videos.upload({ attributes: { name: 'video 7' } })
134 await waitJobs([ server ])
136 const now = new Date()
138 await server.videos.upload({ attributes: { name: 'video 8' } })
139 await waitJobs([ server ])
141 const body = await logsCommand.getAuditLogs({ startDate: now })
142 const logsString = JSON.stringify(body)
144 expect(logsString.includes('video 7')).to.be.false
145 expect(logsString.includes('video 8')).to.be.true
147 expect(body).to.have.lengthOf(1)
151 const message = JSON.parse(item.message)
152 expect(message.domain).to.equal('videos')
153 expect(message.action).to.equal('create')
156 it('Should get logs with an end date', async function () {
159 await server.videos.upload({ attributes: { name: 'video 9' } })
160 await waitJobs([ server ])
162 const now1 = new Date()
164 await server.videos.upload({ attributes: { name: 'video 10' } })
165 await waitJobs([ server ])
167 const now2 = new Date()
169 await server.videos.upload({ attributes: { name: 'video 11' } })
170 await waitJobs([ server ])
172 const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 })
173 const logsString = JSON.stringify(body)
175 expect(logsString.includes('video 9')).to.be.false
176 expect(logsString.includes('video 10')).to.be.true
177 expect(logsString.includes('video 11')).to.be.false
181 after(async function () {
182 await cleanupTests([ server ])