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