]>
Commit | Line | Data |
---|---|---|
1b05d82d C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
ae2abfd3 | 3 | import { expect } from 'chai' |
2e9c7877 | 4 | import { pathExists } from 'fs-extra' |
c55e3d72 | 5 | import { HttpStatusCode, ThumbnailType } from '@shared/models' |
ab3ead3a | 6 | import { |
ae2abfd3 | 7 | cleanupTests, |
254d3579 | 8 | createMultipleServers, |
4c7e60bc | 9 | doubleFollow, |
ae2abfd3 | 10 | makeGetRequest, |
80fdaf06 | 11 | makePostBodyRequest, |
2e9c7877 | 12 | makeRawRequest, |
254d3579 | 13 | PeerTubeServer, |
4c7e60bc | 14 | PluginsCommand, |
ab3ead3a | 15 | setAccessTokensToServers, |
6c5065a0 | 16 | waitJobs |
bf54587a | 17 | } from '@shared/server-commands' |
c55e3d72 | 18 | import { checkVideoFilesWereRemoved } from '../shared' |
80fdaf06 | 19 | |
254d3579 | 20 | function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) { |
80fdaf06 C |
21 | const body = { command } |
22 | if (bodyArg) Object.assign(body, bodyArg) | |
23 | ||
24 | return makePostBodyRequest({ | |
25 | url: server.url, | |
26 | path: '/plugins/test-four/router/commander', | |
27 | fields: body, | |
c0e8b12e | 28 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
80fdaf06 C |
29 | }) |
30 | } | |
1b05d82d C |
31 | |
32 | describe('Test plugin helpers', function () { | |
254d3579 | 33 | let servers: PeerTubeServer[] |
1b05d82d C |
34 | |
35 | before(async function () { | |
80fdaf06 C |
36 | this.timeout(60000) |
37 | ||
254d3579 | 38 | servers = await createMultipleServers(2) |
80fdaf06 | 39 | await setAccessTokensToServers(servers) |
1b05d82d | 40 | |
80fdaf06 | 41 | await doubleFollow(servers[0], servers[1]) |
1b05d82d | 42 | |
89d241a7 | 43 | await servers[0].plugins.install({ path: PluginsCommand.getPluginTestPath('-four') }) |
1b05d82d C |
44 | }) |
45 | ||
80fdaf06 C |
46 | describe('Logger', function () { |
47 | ||
48 | it('Should have logged things', async function () { | |
89d241a7 C |
49 | await servers[0].servers.waitUntilLog('localhost:' + servers[0].port + ' peertube-plugin-test-four', 1, false) |
50 | await servers[0].servers.waitUntilLog('Hello world from plugin four', 1) | |
80fdaf06 | 51 | }) |
1b05d82d C |
52 | }) |
53 | ||
80fdaf06 C |
54 | describe('Database', function () { |
55 | ||
56 | it('Should have made a query', async function () { | |
89d241a7 | 57 | await servers[0].servers.waitUntilLog(`root email is admin${servers[0].internalServerNumber}@example.com`) |
80fdaf06 C |
58 | }) |
59 | }) | |
60 | ||
61 | describe('Config', function () { | |
62 | ||
63 | it('Should have the correct webserver url', async function () { | |
89d241a7 | 64 | await servers[0].servers.waitUntilLog(`server url is http://localhost:${servers[0].port}`) |
80fdaf06 | 65 | }) |
22820226 C |
66 | |
67 | it('Should have the correct config', async function () { | |
68 | const res = await makeGetRequest({ | |
69 | url: servers[0].url, | |
70 | path: '/plugins/test-four/router/server-config', | |
c0e8b12e | 71 | expectedStatus: HttpStatusCode.OK_200 |
22820226 C |
72 | }) |
73 | ||
74 | expect(res.body.serverConfig).to.exist | |
75 | expect(res.body.serverConfig.instance.name).to.equal('PeerTube') | |
76 | }) | |
80fdaf06 C |
77 | }) |
78 | ||
79 | describe('Server', function () { | |
80 | ||
81 | it('Should get the server actor', async function () { | |
89d241a7 | 82 | await servers[0].servers.waitUntilLog('server actor name is peertube') |
80fdaf06 C |
83 | }) |
84 | }) | |
85 | ||
c43ed8e8 | 86 | describe('Socket', function () { |
87 | ||
88 | it('Should sendNotification without any exceptions', async () => { | |
89 | const user = await servers[0].users.create({ username: 'notis_redding', password: 'secret1234?' }) | |
90 | await makePostBodyRequest({ | |
91 | url: servers[0].url, | |
92 | path: '/plugins/test-four/router/send-notification', | |
93 | fields: { | |
94 | userId: user.id | |
95 | }, | |
96 | expectedStatus: HttpStatusCode.CREATED_201 | |
97 | }) | |
98 | }) | |
99 | ||
100 | it('Should sendVideoLiveNewState without any exceptions', async () => { | |
101 | const res = await servers[0].videos.quickUpload({ name: 'video server 1' }) | |
102 | ||
103 | await makePostBodyRequest({ | |
104 | url: servers[0].url, | |
105 | path: '/plugins/test-four/router/send-video-live-new-state/' + res.uuid, | |
106 | expectedStatus: HttpStatusCode.CREATED_201 | |
107 | }) | |
108 | ||
109 | await servers[0].videos.remove({ id: res.uuid }) | |
110 | }) | |
111 | }) | |
112 | ||
22820226 C |
113 | describe('Plugin', function () { |
114 | ||
115 | it('Should get the base static route', async function () { | |
116 | const res = await makeGetRequest({ | |
117 | url: servers[0].url, | |
118 | path: '/plugins/test-four/router/static-route', | |
c0e8b12e | 119 | expectedStatus: HttpStatusCode.OK_200 |
22820226 C |
120 | }) |
121 | ||
122 | expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') | |
123 | }) | |
302eba0d C |
124 | |
125 | it('Should get the base static route', async function () { | |
126 | const baseRouter = '/plugins/test-four/0.0.1/router/' | |
127 | ||
128 | const res = await makeGetRequest({ | |
129 | url: servers[0].url, | |
130 | path: baseRouter + 'router-route', | |
c0e8b12e | 131 | expectedStatus: HttpStatusCode.OK_200 |
302eba0d C |
132 | }) |
133 | ||
134 | expect(res.body.routerRoute).to.equal(baseRouter) | |
135 | }) | |
136 | }) | |
137 | ||
138 | describe('User', function () { | |
22df69fd | 139 | let rootId: number |
302eba0d C |
140 | |
141 | it('Should not get a user if not authenticated', async function () { | |
62906990 | 142 | await makeGetRequest({ |
302eba0d C |
143 | url: servers[0].url, |
144 | path: '/plugins/test-four/router/user', | |
c0e8b12e | 145 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
302eba0d | 146 | }) |
302eba0d C |
147 | }) |
148 | ||
149 | it('Should get a user if authenticated', async function () { | |
150 | const res = await makeGetRequest({ | |
151 | url: servers[0].url, | |
152 | token: servers[0].accessToken, | |
153 | path: '/plugins/test-four/router/user', | |
c0e8b12e | 154 | expectedStatus: HttpStatusCode.OK_200 |
302eba0d C |
155 | }) |
156 | ||
302eba0d | 157 | expect(res.body.username).to.equal('root') |
b31d7262 | 158 | expect(res.body.displayName).to.equal('root') |
302eba0d C |
159 | expect(res.body.isAdmin).to.be.true |
160 | expect(res.body.isModerator).to.be.false | |
161 | expect(res.body.isUser).to.be.false | |
22df69fd C |
162 | |
163 | rootId = res.body.id | |
164 | }) | |
165 | ||
166 | it('Should load a user by id', async function () { | |
167 | { | |
168 | const res = await makeGetRequest({ | |
169 | url: servers[0].url, | |
170 | path: '/plugins/test-four/router/user/' + rootId, | |
171 | expectedStatus: HttpStatusCode.OK_200 | |
172 | }) | |
173 | ||
174 | expect(res.body.username).to.equal('root') | |
175 | } | |
176 | ||
177 | { | |
178 | await makeGetRequest({ | |
179 | url: servers[0].url, | |
180 | path: '/plugins/test-four/router/user/42', | |
181 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | |
182 | }) | |
183 | } | |
302eba0d | 184 | }) |
22820226 C |
185 | }) |
186 | ||
80fdaf06 C |
187 | describe('Moderation', function () { |
188 | let videoUUIDServer1: string | |
189 | ||
190 | before(async function () { | |
75e12406 | 191 | this.timeout(60000) |
80fdaf06 C |
192 | |
193 | { | |
c0e8b12e | 194 | const res = await servers[0].videos.quickUpload({ name: 'video server 1' }) |
80fdaf06 C |
195 | videoUUIDServer1 = res.uuid |
196 | } | |
197 | ||
198 | { | |
c0e8b12e | 199 | await servers[1].videos.quickUpload({ name: 'video server 2' }) |
80fdaf06 C |
200 | } |
201 | ||
202 | await waitJobs(servers) | |
203 | ||
89d241a7 | 204 | const { data } = await servers[0].videos.list() |
80fdaf06 | 205 | |
d23dd9fb | 206 | expect(data).to.have.lengthOf(2) |
80fdaf06 C |
207 | }) |
208 | ||
209 | it('Should mute server 2', async function () { | |
210 | this.timeout(10000) | |
211 | await postCommand(servers[0], 'blockServer', { hostToBlock: `localhost:${servers[1].port}` }) | |
212 | ||
89d241a7 | 213 | const { data } = await servers[0].videos.list() |
80fdaf06 | 214 | |
d23dd9fb C |
215 | expect(data).to.have.lengthOf(1) |
216 | expect(data[0].name).to.equal('video server 1') | |
80fdaf06 C |
217 | }) |
218 | ||
219 | it('Should unmute server 2', async function () { | |
220 | await postCommand(servers[0], 'unblockServer', { hostToUnblock: `localhost:${servers[1].port}` }) | |
221 | ||
89d241a7 | 222 | const { data } = await servers[0].videos.list() |
80fdaf06 | 223 | |
d23dd9fb | 224 | expect(data).to.have.lengthOf(2) |
80fdaf06 C |
225 | }) |
226 | ||
227 | it('Should mute account of server 2', async function () { | |
228 | await postCommand(servers[0], 'blockAccount', { handleToBlock: `root@localhost:${servers[1].port}` }) | |
229 | ||
89d241a7 | 230 | const { data } = await servers[0].videos.list() |
80fdaf06 | 231 | |
d23dd9fb C |
232 | expect(data).to.have.lengthOf(1) |
233 | expect(data[0].name).to.equal('video server 1') | |
80fdaf06 C |
234 | }) |
235 | ||
236 | it('Should unmute account of server 2', async function () { | |
237 | await postCommand(servers[0], 'unblockAccount', { handleToUnblock: `root@localhost:${servers[1].port}` }) | |
238 | ||
89d241a7 | 239 | const { data } = await servers[0].videos.list() |
80fdaf06 | 240 | |
d23dd9fb | 241 | expect(data).to.have.lengthOf(2) |
80fdaf06 C |
242 | }) |
243 | ||
244 | it('Should blacklist video', async function () { | |
245 | this.timeout(10000) | |
246 | ||
247 | await postCommand(servers[0], 'blacklist', { videoUUID: videoUUIDServer1, unfederate: true }) | |
248 | ||
249 | await waitJobs(servers) | |
250 | ||
251 | for (const server of servers) { | |
89d241a7 | 252 | const { data } = await server.videos.list() |
80fdaf06 | 253 | |
d23dd9fb C |
254 | expect(data).to.have.lengthOf(1) |
255 | expect(data[0].name).to.equal('video server 2') | |
80fdaf06 C |
256 | } |
257 | }) | |
258 | ||
259 | it('Should unblacklist video', async function () { | |
260 | this.timeout(10000) | |
261 | ||
262 | await postCommand(servers[0], 'unblacklist', { videoUUID: videoUUIDServer1 }) | |
263 | ||
264 | await waitJobs(servers) | |
265 | ||
266 | for (const server of servers) { | |
89d241a7 | 267 | const { data } = await server.videos.list() |
80fdaf06 | 268 | |
d23dd9fb | 269 | expect(data).to.have.lengthOf(2) |
80fdaf06 C |
270 | } |
271 | }) | |
1b05d82d C |
272 | }) |
273 | ||
80fdaf06 C |
274 | describe('Videos', function () { |
275 | let videoUUID: string | |
754c52b9 | 276 | let videoPath: string |
80fdaf06 C |
277 | |
278 | before(async () => { | |
2e9c7877 C |
279 | this.timeout(240000) |
280 | ||
281 | await servers[0].config.enableTranscoding() | |
282 | ||
c0e8b12e | 283 | const res = await servers[0].videos.quickUpload({ name: 'video1' }) |
80fdaf06 | 284 | videoUUID = res.uuid |
2e9c7877 C |
285 | |
286 | await waitJobs(servers) | |
287 | }) | |
288 | ||
289 | it('Should get video files', async function () { | |
290 | const { body } = await makeGetRequest({ | |
291 | url: servers[0].url, | |
292 | path: '/plugins/test-four/router/video-files/' + videoUUID, | |
293 | expectedStatus: HttpStatusCode.OK_200 | |
294 | }) | |
295 | ||
296 | // Video files check | |
297 | { | |
298 | expect(body.webtorrent.videoFiles).to.be.an('array') | |
299 | expect(body.hls.videoFiles).to.be.an('array') | |
300 | ||
301 | for (const resolution of [ 144, 240, 360, 480, 720 ]) { | |
302 | for (const files of [ body.webtorrent.videoFiles, body.hls.videoFiles ]) { | |
303 | const file = files.find(f => f.resolution === resolution) | |
304 | expect(file).to.exist | |
305 | ||
306 | expect(file.size).to.be.a('number') | |
307 | expect(file.fps).to.equal(25) | |
308 | ||
309 | expect(await pathExists(file.path)).to.be.true | |
310 | await makeRawRequest(file.url, HttpStatusCode.OK_200) | |
311 | } | |
312 | } | |
754c52b9 C |
313 | |
314 | videoPath = body.webtorrent.videoFiles[0].path | |
2e9c7877 C |
315 | } |
316 | ||
317 | // Thumbnails check | |
318 | { | |
319 | expect(body.thumbnails).to.be.an('array') | |
320 | ||
321 | const miniature = body.thumbnails.find(t => t.type === ThumbnailType.MINIATURE) | |
322 | expect(miniature).to.exist | |
323 | expect(await pathExists(miniature.path)).to.be.true | |
324 | await makeRawRequest(miniature.url, HttpStatusCode.OK_200) | |
325 | ||
326 | const preview = body.thumbnails.find(t => t.type === ThumbnailType.PREVIEW) | |
327 | expect(preview).to.exist | |
328 | expect(await pathExists(preview.path)).to.be.true | |
329 | await makeRawRequest(preview.url, HttpStatusCode.OK_200) | |
330 | } | |
80fdaf06 | 331 | }) |
ab3ead3a | 332 | |
754c52b9 C |
333 | it('Should probe a file', async function () { |
334 | const { body } = await makeGetRequest({ | |
335 | url: servers[0].url, | |
336 | path: '/plugins/test-four/router/ffprobe', | |
337 | query: { | |
338 | path: videoPath | |
339 | }, | |
340 | expectedStatus: HttpStatusCode.OK_200 | |
341 | }) | |
342 | ||
343 | expect(body.streams).to.be.an('array') | |
344 | expect(body.streams).to.have.lengthOf(2) | |
345 | }) | |
346 | ||
80fdaf06 | 347 | it('Should remove a video after a view', async function () { |
59fd824c | 348 | this.timeout(40000) |
ab3ead3a | 349 | |
80fdaf06 | 350 | // Should not throw -> video exists |
83903cb6 | 351 | const video = await servers[0].videos.get({ id: videoUUID }) |
80fdaf06 | 352 | // Should delete the video |
b2111066 | 353 | await servers[0].views.simulateView({ id: videoUUID }) |
ab3ead3a | 354 | |
89d241a7 | 355 | await servers[0].servers.waitUntilLog('Video deleted by plugin four.') |
ab3ead3a | 356 | |
80fdaf06 C |
357 | try { |
358 | // Should throw because the video should have been deleted | |
89d241a7 | 359 | await servers[0].videos.get({ id: videoUUID }) |
80fdaf06 C |
360 | throw new Error('Video exists') |
361 | } catch (err) { | |
362 | if (err.message.includes('exists')) throw err | |
363 | } | |
ab3ead3a | 364 | |
83903cb6 | 365 | await checkVideoFilesWereRemoved({ server: servers[0], video }) |
80fdaf06 C |
366 | }) |
367 | ||
368 | it('Should have fetched the video by URL', async function () { | |
89d241a7 | 369 | await servers[0].servers.waitUntilLog(`video from DB uuid is ${videoUUID}`) |
80fdaf06 | 370 | }) |
ab3ead3a C |
371 | }) |
372 | ||
1b05d82d | 373 | after(async function () { |
80fdaf06 | 374 | await cleanupTests(servers) |
1b05d82d C |
375 | }) |
376 | }) |