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