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