]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/logs.ts
fix missing title attribute on <iframe> tag suggested for embedding (#3901)
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / logs.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fd8710b8 2
fd8710b8 3import 'mocha'
c9c43612
C
4import * as chai from 'chai'
5import {
6 cleanupTests,
7 flushAndRunServer,
8 killallServers,
9 makePingRequest,
10 reRunServer,
11 ServerInfo,
12 setAccessTokensToServers
13} from '../../../../shared/extra-utils/index'
14import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
94565d52
C
15import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
16import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
fd8710b8
C
17
18const expect = chai.expect
19
20describe('Test logs', function () {
21 let server: ServerInfo
22
23 before(async function () {
24 this.timeout(30000)
25
210feb6c 26 server = await flushAndRunServer(1)
fd8710b8
C
27 await setAccessTokensToServers([ server ])
28 })
29
566c125d 30 describe('With the standard log file', function () {
78d62f4d 31
566c125d 32 it('Should get logs with a start date', async function () {
ff9112ad 33 this.timeout(20000)
fd8710b8 34
566c125d
C
35 await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
36 await waitJobs([ server ])
fd8710b8 37
566c125d 38 const now = new Date()
fd8710b8 39
566c125d
C
40 await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
41 await waitJobs([ server ])
fd8710b8 42
566c125d
C
43 const res = await getLogs(server.url, server.accessToken, now)
44 const logsString = JSON.stringify(res.body)
fd8710b8 45
566c125d
C
46 expect(logsString.includes('video 1')).to.be.false
47 expect(logsString.includes('video 2')).to.be.true
48 })
49
50 it('Should get logs with an end date', async function () {
ff9112ad 51 this.timeout(30000)
566c125d
C
52
53 await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
54 await waitJobs([ server ])
55
56 const now1 = new Date()
57
58 await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
59 await waitJobs([ server ])
60
61 const now2 = new Date()
62
63 await uploadVideo(server.url, server.accessToken, { name: 'video 5' })
64 await waitJobs([ server ])
65
66 const res = await getLogs(server.url, server.accessToken, now1, now2)
67 const logsString = JSON.stringify(res.body)
fd8710b8 68
566c125d
C
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
72 })
fd8710b8 73
566c125d 74 it('Should get filter by level', async function () {
ff9112ad 75 this.timeout(20000)
fd8710b8 76
566c125d 77 const now = new Date()
fd8710b8 78
566c125d
C
79 await uploadVideo(server.url, server.accessToken, { name: 'video 6' })
80 await waitJobs([ server ])
fd8710b8 81
566c125d
C
82 {
83 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
84 const logsString = JSON.stringify(res.body)
fd8710b8 85
566c125d
C
86 expect(logsString.includes('video 6')).to.be.true
87 }
fd8710b8 88
566c125d
C
89 {
90 const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn')
91 const logsString = JSON.stringify(res.body)
fd8710b8 92
566c125d
C
93 expect(logsString.includes('video 6')).to.be.false
94 }
95 })
78d62f4d
C
96
97 it('Should log ping requests', async function () {
ff9112ad
C
98 this.timeout(10000)
99
78d62f4d
C
100 const now = new Date()
101
102 await makePingRequest(server)
103
104 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
105 const logsString = JSON.stringify(res.body)
106
107 expect(logsString.includes('/api/v1/ping')).to.be.true
108 })
109
110 it('Should not log ping requests', async function () {
111 this.timeout(30000)
112
113 killallServers([ server ])
114
115 await reRunServer(server, { log: { log_ping_requests: false } })
116
117 const now = new Date()
118
119 await makePingRequest(server)
120
121 const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
122 const logsString = JSON.stringify(res.body)
123
124 expect(logsString.includes('/api/v1/ping')).to.be.false
125 })
fd8710b8
C
126 })
127
566c125d
C
128 describe('With the audit log', function () {
129 it('Should get logs with a start date', async function () {
ff9112ad 130 this.timeout(20000)
fd8710b8 131
566c125d
C
132 await uploadVideo(server.url, server.accessToken, { name: 'video 7' })
133 await waitJobs([ server ])
fd8710b8 134
566c125d 135 const now = new Date()
fd8710b8 136
566c125d
C
137 await uploadVideo(server.url, server.accessToken, { name: 'video 8' })
138 await waitJobs([ server ])
139
140 const res = await getAuditLogs(server.url, server.accessToken, now)
fd8710b8
C
141 const logsString = JSON.stringify(res.body)
142
566c125d
C
143 expect(logsString.includes('video 7')).to.be.false
144 expect(logsString.includes('video 8')).to.be.true
145
146 expect(res.body).to.have.lengthOf(1)
147
148 const item = res.body[0]
149
150 const message = JSON.parse(item.message)
151 expect(message.domain).to.equal('videos')
152 expect(message.action).to.equal('create')
153 })
154
155 it('Should get logs with an end date', async function () {
ff9112ad 156 this.timeout(30000)
566c125d
C
157
158 await uploadVideo(server.url, server.accessToken, { name: 'video 9' })
159 await waitJobs([ server ])
160
161 const now1 = new Date()
162
163 await uploadVideo(server.url, server.accessToken, { name: 'video 10' })
164 await waitJobs([ server ])
165
166 const now2 = new Date()
167
168 await uploadVideo(server.url, server.accessToken, { name: 'video 11' })
169 await waitJobs([ server ])
fd8710b8 170
566c125d 171 const res = await getAuditLogs(server.url, server.accessToken, now1, now2)
fd8710b8
C
172 const logsString = JSON.stringify(res.body)
173
566c125d
C
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
177 })
fd8710b8
C
178 })
179
7c3b7976
C
180 after(async function () {
181 await cleanupTests([ server ])
fd8710b8
C
182 })
183})