]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
fd8710b8 | 2 | |
fd8710b8 | 3 | import 'mocha' |
c9c43612 C |
4 | import * as chai from 'chai' |
5 | import { | |
6 | cleanupTests, | |
254d3579 | 7 | createSingleServer, |
c9c43612 | 8 | killallServers, |
a92ddacb | 9 | LogsCommand, |
254d3579 | 10 | PeerTubeServer, |
a92ddacb | 11 | setAccessTokensToServers, |
a92ddacb | 12 | waitJobs |
bf54587a | 13 | } from '@shared/server-commands' |
fd8710b8 C |
14 | |
15 | const expect = chai.expect | |
16 | ||
17 | describe('Test logs', function () { | |
254d3579 | 18 | let server: PeerTubeServer |
a92ddacb | 19 | let logsCommand: LogsCommand |
fd8710b8 C |
20 | |
21 | before(async function () { | |
22 | this.timeout(30000) | |
23 | ||
254d3579 | 24 | server = await createSingleServer(1) |
fd8710b8 | 25 | await setAccessTokensToServers([ server ]) |
a92ddacb | 26 | |
89d241a7 | 27 | logsCommand = server.logs |
fd8710b8 C |
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 | |
89d241a7 | 35 | await server.videos.upload({ attributes: { name: 'video 1' } }) |
566c125d | 36 | await waitJobs([ server ]) |
fd8710b8 | 37 | |
566c125d | 38 | const now = new Date() |
fd8710b8 | 39 | |
89d241a7 | 40 | await server.videos.upload({ attributes: { name: 'video 2' } }) |
566c125d | 41 | await waitJobs([ server ]) |
fd8710b8 | 42 | |
a92ddacb C |
43 | const body = await logsCommand.getLogs({ startDate: now }) |
44 | const logsString = JSON.stringify(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 | 52 | |
89d241a7 | 53 | await server.videos.upload({ attributes: { name: 'video 3' } }) |
566c125d C |
54 | await waitJobs([ server ]) |
55 | ||
56 | const now1 = new Date() | |
57 | ||
89d241a7 | 58 | await server.videos.upload({ attributes: { name: 'video 4' } }) |
566c125d C |
59 | await waitJobs([ server ]) |
60 | ||
61 | const now2 = new Date() | |
62 | ||
89d241a7 | 63 | await server.videos.upload({ attributes: { name: 'video 5' } }) |
566c125d C |
64 | await waitJobs([ server ]) |
65 | ||
a92ddacb C |
66 | const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 }) |
67 | const logsString = JSON.stringify(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 | |
64553e88 | 74 | it('Should filter by level', async function () { |
ff9112ad | 75 | this.timeout(20000) |
fd8710b8 | 76 | |
566c125d | 77 | const now = new Date() |
fd8710b8 | 78 | |
89d241a7 | 79 | await server.videos.upload({ attributes: { name: 'video 6' } }) |
566c125d | 80 | await waitJobs([ server ]) |
fd8710b8 | 81 | |
566c125d | 82 | { |
a92ddacb C |
83 | const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) |
84 | const logsString = JSON.stringify(body) | |
fd8710b8 | 85 | |
566c125d C |
86 | expect(logsString.includes('video 6')).to.be.true |
87 | } | |
fd8710b8 | 88 | |
566c125d | 89 | { |
a92ddacb C |
90 | const body = await logsCommand.getLogs({ startDate: now, level: 'warn' }) |
91 | const logsString = JSON.stringify(body) | |
fd8710b8 | 92 | |
566c125d C |
93 | expect(logsString.includes('video 6')).to.be.false |
94 | } | |
95 | }) | |
78d62f4d | 96 | |
64553e88 C |
97 | it('Should filter by tag', async function () { |
98 | const now = new Date() | |
99 | ||
100 | const { uuid } = await server.videos.upload({ attributes: { name: 'video 6' } }) | |
101 | await waitJobs([ server ]) | |
102 | ||
103 | { | |
104 | const body = await logsCommand.getLogs({ startDate: now, level: 'debug', tagsOneOf: [ 'toto' ] }) | |
105 | expect(body).to.have.lengthOf(0) | |
106 | } | |
107 | ||
108 | { | |
109 | const body = await logsCommand.getLogs({ startDate: now, level: 'debug', tagsOneOf: [ uuid ] }) | |
110 | expect(body).to.not.have.lengthOf(0) | |
111 | ||
112 | for (const line of body) { | |
113 | expect(line.tags).to.contain(uuid) | |
114 | } | |
115 | } | |
116 | }) | |
117 | ||
78d62f4d | 118 | it('Should log ping requests', async function () { |
ff9112ad C |
119 | this.timeout(10000) |
120 | ||
78d62f4d C |
121 | const now = new Date() |
122 | ||
89d241a7 | 123 | await server.servers.ping() |
78d62f4d | 124 | |
a92ddacb C |
125 | const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) |
126 | const logsString = JSON.stringify(body) | |
78d62f4d C |
127 | |
128 | expect(logsString.includes('/api/v1/ping')).to.be.true | |
129 | }) | |
130 | ||
131 | it('Should not log ping requests', async function () { | |
132 | this.timeout(30000) | |
133 | ||
9293139f | 134 | await killallServers([ server ]) |
78d62f4d | 135 | |
254d3579 | 136 | await server.run({ log: { log_ping_requests: false } }) |
78d62f4d C |
137 | |
138 | const now = new Date() | |
139 | ||
89d241a7 | 140 | await server.servers.ping() |
78d62f4d | 141 | |
a92ddacb C |
142 | const body = await logsCommand.getLogs({ startDate: now, level: 'info' }) |
143 | const logsString = JSON.stringify(body) | |
78d62f4d C |
144 | |
145 | expect(logsString.includes('/api/v1/ping')).to.be.false | |
146 | }) | |
fd8710b8 C |
147 | }) |
148 | ||
566c125d C |
149 | describe('With the audit log', function () { |
150 | it('Should get logs with a start date', async function () { | |
ff9112ad | 151 | this.timeout(20000) |
fd8710b8 | 152 | |
89d241a7 | 153 | await server.videos.upload({ attributes: { name: 'video 7' } }) |
566c125d | 154 | await waitJobs([ server ]) |
fd8710b8 | 155 | |
566c125d | 156 | const now = new Date() |
fd8710b8 | 157 | |
89d241a7 | 158 | await server.videos.upload({ attributes: { name: 'video 8' } }) |
566c125d C |
159 | await waitJobs([ server ]) |
160 | ||
a92ddacb C |
161 | const body = await logsCommand.getAuditLogs({ startDate: now }) |
162 | const logsString = JSON.stringify(body) | |
fd8710b8 | 163 | |
566c125d C |
164 | expect(logsString.includes('video 7')).to.be.false |
165 | expect(logsString.includes('video 8')).to.be.true | |
166 | ||
a92ddacb | 167 | expect(body).to.have.lengthOf(1) |
566c125d | 168 | |
a92ddacb | 169 | const item = body[0] |
566c125d C |
170 | |
171 | const message = JSON.parse(item.message) | |
172 | expect(message.domain).to.equal('videos') | |
173 | expect(message.action).to.equal('create') | |
174 | }) | |
175 | ||
176 | it('Should get logs with an end date', async function () { | |
ff9112ad | 177 | this.timeout(30000) |
566c125d | 178 | |
89d241a7 | 179 | await server.videos.upload({ attributes: { name: 'video 9' } }) |
566c125d C |
180 | await waitJobs([ server ]) |
181 | ||
182 | const now1 = new Date() | |
183 | ||
89d241a7 | 184 | await server.videos.upload({ attributes: { name: 'video 10' } }) |
566c125d C |
185 | await waitJobs([ server ]) |
186 | ||
187 | const now2 = new Date() | |
188 | ||
89d241a7 | 189 | await server.videos.upload({ attributes: { name: 'video 11' } }) |
566c125d | 190 | await waitJobs([ server ]) |
fd8710b8 | 191 | |
a92ddacb C |
192 | const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 }) |
193 | const logsString = JSON.stringify(body) | |
fd8710b8 | 194 | |
566c125d C |
195 | expect(logsString.includes('video 9')).to.be.false |
196 | expect(logsString.includes('video 10')).to.be.true | |
197 | expect(logsString.includes('video 11')).to.be.false | |
198 | }) | |
fd8710b8 C |
199 | }) |
200 | ||
7c3b7976 C |
201 | after(async function () { |
202 | await cleanupTests([ server ]) | |
fd8710b8 C |
203 | }) |
204 | }) |