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