1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
12 setAccessTokensToServers
13 } from '../../../../shared/extra-utils/index'
14 import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
15 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
16 import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
18 const expect = chai.expect
20 describe('Test logs', function () {
21 let server: ServerInfo
23 before(async function () {
26 server = await flushAndRunServer(1)
27 await setAccessTokensToServers([ server ])
30 describe('With the standard log file', function () {
32 it('Should get logs with a start date', async function () {
35 await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
36 await waitJobs([ server ])
38 const now = new Date()
40 await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
41 await waitJobs([ server ])
43 const res = await getLogs(server.url, server.accessToken, now)
44 const logsString = JSON.stringify(res.body)
46 expect(logsString.includes('video 1')).to.be.false
47 expect(logsString.includes('video 2')).to.be.true
50 it('Should get logs with an end date', async function () {
53 await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
54 await waitJobs([ server ])
56 const now1 = new Date()
58 await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
59 await waitJobs([ server ])
61 const now2 = new Date()
63 await uploadVideo(server.url, server.accessToken, { name: 'video 5' })
64 await waitJobs([ server ])
66 const res = await getLogs(server.url, server.accessToken, now1, now2)
67 const logsString = JSON.stringify(res.body)
69 expect(logsString.includes('video 3')).to.be.false
70 expect(logsString.includes('video 4')).to.be.true
71 expect(logsString.includes('video 5')).to.be.false
74 it('Should get filter by level', async function () {
77 const now = new Date()
79 await uploadVideo(server.url, server.accessToken, { name: 'video 6' })
80 await waitJobs([ server ])
83 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
84 const logsString = JSON.stringify(res.body)
86 expect(logsString.includes('video 6')).to.be.true
90 const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn')
91 const logsString = JSON.stringify(res.body)
93 expect(logsString.includes('video 6')).to.be.false
97 it('Should log ping requests', async function () {
100 const now = new Date()
102 await makePingRequest(server)
104 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
105 const logsString = JSON.stringify(res.body)
107 expect(logsString.includes('/api/v1/ping')).to.be.true
110 it('Should not log ping requests', async function () {
113 killallServers([ server ])
115 await reRunServer(server, { log: { log_ping_requests: false } })
117 const now = new Date()
119 await makePingRequest(server)
121 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
122 const logsString = JSON.stringify(res.body)
124 expect(logsString.includes('/api/v1/ping')).to.be.false
128 describe('With the audit log', function () {
129 it('Should get logs with a start date', async function () {
132 await uploadVideo(server.url, server.accessToken, { name: 'video 7' })
133 await waitJobs([ server ])
135 const now = new Date()
137 await uploadVideo(server.url, server.accessToken, { name: 'video 8' })
138 await waitJobs([ server ])
140 const res = await getAuditLogs(server.url, server.accessToken, now)
141 const logsString = JSON.stringify(res.body)
143 expect(logsString.includes('video 7')).to.be.false
144 expect(logsString.includes('video 8')).to.be.true
146 expect(res.body).to.have.lengthOf(1)
148 const item = res.body[0]
150 const message = JSON.parse(item.message)
151 expect(message.domain).to.equal('videos')
152 expect(message.action).to.equal('create')
155 it('Should get logs with an end date', async function () {
158 await uploadVideo(server.url, server.accessToken, { name: 'video 9' })
159 await waitJobs([ server ])
161 const now1 = new Date()
163 await uploadVideo(server.url, server.accessToken, { name: 'video 10' })
164 await waitJobs([ server ])
166 const now2 = new Date()
168 await uploadVideo(server.url, server.accessToken, { name: 'video 11' })
169 await waitJobs([ server ])
171 const res = await getAuditLogs(server.url, server.accessToken, now1, now2)
172 const logsString = JSON.stringify(res.body)
174 expect(logsString.includes('video 9')).to.be.false
175 expect(logsString.includes('video 10')).to.be.true
176 expect(logsString.includes('video 11')).to.be.false
180 after(async function () {
181 await cleanupTests([ server ])