]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9b474844 | 2 | |
9b474844 | 3 | import 'mocha' |
2158ac90 RK |
4 | import * as chai from 'chai' |
5 | import { ServerConfig } from '@shared/models' | |
89cd1275 C |
6 | import { |
7 | addVideoCommentReply, | |
6691c522 | 8 | addVideoCommentThread, |
3cabf353 | 9 | createLive, |
a1587156 | 10 | doubleFollow, |
38267c0c | 11 | getAccountVideos, |
a1587156 | 12 | getConfig, |
6691c522 | 13 | getPluginTestPath, |
6691c522 | 14 | getVideo, |
38267c0c | 15 | getVideoChannelVideos, |
6691c522 | 16 | getVideoCommentThreads, |
a1587156 C |
17 | getVideosList, |
18 | getVideosListPagination, | |
6691c522 C |
19 | getVideoThreadComments, |
20 | getVideoWithToken, | |
a1587156 C |
21 | installPlugin, |
22 | registerUser, | |
23 | setAccessTokensToServers, | |
6691c522 | 24 | setDefaultVideoChannel, |
3cabf353 | 25 | updateCustomSubConfig, |
a1587156 C |
26 | updateVideo, |
27 | uploadVideo, | |
28 | waitJobs | |
89cd1275 | 29 | } from '../../../shared/extra-utils' |
2158ac90 | 30 | import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' |
b488ba1e | 31 | import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' |
2158ac90 | 32 | import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos' |
6691c522 | 33 | import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' |
9b474844 C |
34 | |
35 | const expect = chai.expect | |
36 | ||
37 | describe('Test plugin filter hooks', function () { | |
89cd1275 C |
38 | let servers: ServerInfo[] |
39 | let videoUUID: string | |
40 | let threadId: number | |
9b474844 C |
41 | |
42 | before(async function () { | |
43 | this.timeout(30000) | |
9b474844 | 44 | |
89cd1275 C |
45 | servers = await flushAndRunMultipleServers(2) |
46 | await setAccessTokensToServers(servers) | |
6691c522 C |
47 | await setDefaultVideoChannel(servers) |
48 | await doubleFollow(servers[0], servers[1]) | |
89cd1275 C |
49 | |
50 | await installPlugin({ | |
51 | url: servers[0].url, | |
52 | accessToken: servers[0].accessToken, | |
53 | path: getPluginTestPath() | |
54 | }) | |
55 | ||
56 | await installPlugin({ | |
57 | url: servers[0].url, | |
58 | accessToken: servers[0].accessToken, | |
59 | path: getPluginTestPath('-two') | |
60 | }) | |
61 | ||
62 | for (let i = 0; i < 10; i++) { | |
63 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i }) | |
64 | } | |
65 | ||
66 | const res = await getVideosList(servers[0].url) | |
67 | videoUUID = res.body.data[0].uuid | |
3cabf353 C |
68 | |
69 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, { | |
70 | live: { enabled: true }, | |
71 | signup: { enabled: true }, | |
72 | import: { | |
73 | videos: { | |
74 | http: { enabled: true }, | |
75 | torrent: { enabled: true } | |
76 | } | |
77 | } | |
78 | }) | |
9b474844 C |
79 | }) |
80 | ||
6691c522 | 81 | it('Should run filter:api.videos.list.params', async function () { |
89cd1275 C |
82 | const res = await getVideosListPagination(servers[0].url, 0, 2) |
83 | ||
84 | // 2 plugins do +1 to the count parameter | |
85 | expect(res.body.data).to.have.lengthOf(4) | |
86 | }) | |
87 | ||
88 | it('Should run filter:api.videos.list.result', async function () { | |
89 | const res = await getVideosListPagination(servers[0].url, 0, 0) | |
90 | ||
91 | // Plugin do +1 to the total result | |
92 | expect(res.body.total).to.equal(11) | |
93 | }) | |
94 | ||
38267c0c C |
95 | it('Should run filter:api.accounts.videos.list.params', async function () { |
96 | const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) | |
97 | ||
98 | // 1 plugin do +1 to the count parameter | |
99 | expect(res.body.data).to.have.lengthOf(3) | |
100 | }) | |
101 | ||
102 | it('Should run filter:api.accounts.videos.list.result', async function () { | |
103 | const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2) | |
104 | ||
105 | // Plugin do +2 to the total result | |
106 | expect(res.body.total).to.equal(12) | |
107 | }) | |
108 | ||
109 | it('Should run filter:api.video-channels.videos.list.params', async function () { | |
110 | const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) | |
111 | ||
112 | // 1 plugin do +3 to the count parameter | |
113 | expect(res.body.data).to.have.lengthOf(5) | |
114 | }) | |
115 | ||
116 | it('Should run filter:api.video-channels.videos.list.result', async function () { | |
c824e8a0 | 117 | const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2) |
38267c0c C |
118 | |
119 | // Plugin do +3 to the total result | |
120 | expect(res.body.total).to.equal(13) | |
121 | }) | |
122 | ||
89cd1275 C |
123 | it('Should run filter:api.video.get.result', async function () { |
124 | const res = await getVideo(servers[0].url, videoUUID) | |
125 | ||
126 | expect(res.body.name).to.contain('<3') | |
9b474844 C |
127 | }) |
128 | ||
6691c522 C |
129 | it('Should run filter:api.video.upload.accept.result', async function () { |
130 | await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, 403) | |
131 | }) | |
132 | ||
3cabf353 C |
133 | it('Should run filter:api.live-video.create.accept.result', async function () { |
134 | const attributes = { | |
135 | name: 'video with bad word', | |
136 | privacy: VideoPrivacy.PUBLIC, | |
137 | channelId: servers[0].videoChannel.id | |
138 | } | |
139 | ||
140 | await createLive(servers[0].url, servers[0].accessToken, attributes, 403) | |
141 | }) | |
142 | ||
2158ac90 RK |
143 | it('Should run filter:api.video.pre-import-url.accept.result', async function () { |
144 | const baseAttributes = { | |
145 | name: 'normal title', | |
146 | privacy: VideoPrivacy.PUBLIC, | |
147 | channelId: servers[0].videoChannel.id, | |
b488ba1e | 148 | targetUrl: getGoodVideoUrl() + 'bad' |
2158ac90 RK |
149 | } |
150 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403) | |
151 | }) | |
152 | ||
153 | it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { | |
154 | const baseAttributes = { | |
155 | name: 'bad torrent', | |
156 | privacy: VideoPrivacy.PUBLIC, | |
157 | channelId: servers[0].videoChannel.id, | |
158 | torrentfile: 'video-720p.torrent' as any | |
159 | } | |
160 | await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, 403) | |
161 | }) | |
162 | ||
163 | it('Should run filter:api.video.post-import-url.accept.result', async function () { | |
164 | this.timeout(60000) | |
165 | ||
166 | let videoImportId: number | |
167 | ||
168 | { | |
169 | const baseAttributes = { | |
170 | name: 'title with bad word', | |
171 | privacy: VideoPrivacy.PUBLIC, | |
172 | channelId: servers[0].videoChannel.id, | |
b488ba1e | 173 | targetUrl: getGoodVideoUrl() |
2158ac90 RK |
174 | } |
175 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | |
176 | videoImportId = res.body.id | |
177 | } | |
178 | ||
179 | await waitJobs(servers) | |
180 | ||
181 | { | |
182 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | |
183 | const videoImports = res.body.data as VideoImport[] | |
184 | ||
185 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
186 | ||
187 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
188 | expect(videoImport.state.label).to.equal('Rejected') | |
189 | } | |
190 | }) | |
191 | ||
192 | it('Should run filter:api.video.post-import-torrent.accept.result', async function () { | |
193 | this.timeout(60000) | |
194 | ||
195 | let videoImportId: number | |
196 | ||
197 | { | |
198 | const baseAttributes = { | |
199 | name: 'title with bad word', | |
200 | privacy: VideoPrivacy.PUBLIC, | |
201 | channelId: servers[0].videoChannel.id, | |
202 | torrentfile: 'video-720p.torrent' as any | |
203 | } | |
204 | const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes) | |
205 | videoImportId = res.body.id | |
206 | } | |
207 | ||
208 | await waitJobs(servers) | |
209 | ||
210 | { | |
211 | const res = await getMyVideoImports(servers[0].url, servers[0].accessToken) | |
212 | const videoImports = res.body.data as VideoImport[] | |
213 | ||
214 | const videoImport = videoImports.find(i => i.id === videoImportId) | |
215 | ||
216 | expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) | |
217 | expect(videoImport.state.label).to.equal('Rejected') | |
218 | } | |
219 | }) | |
220 | ||
6691c522 C |
221 | it('Should run filter:api.video-thread.create.accept.result', async function () { |
222 | await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', 403) | |
223 | }) | |
224 | ||
225 | it('Should run filter:api.video-comment-reply.create.accept.result', async function () { | |
226 | const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') | |
227 | threadId = res.body.comment.id | |
228 | ||
229 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with bad word', 403) | |
230 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', 200) | |
231 | }) | |
232 | ||
233 | it('Should run filter:api.video-threads.list.params', async function () { | |
234 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
235 | ||
236 | // our plugin do +1 to the count parameter | |
237 | expect(res.body.data).to.have.lengthOf(1) | |
238 | }) | |
239 | ||
240 | it('Should run filter:api.video-threads.list.result', async function () { | |
241 | const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0) | |
242 | ||
243 | // Plugin do +1 to the total result | |
244 | expect(res.body.total).to.equal(2) | |
245 | }) | |
246 | ||
247 | it('Should run filter:api.video-thread-comments.list.params') | |
248 | ||
249 | it('Should run filter:api.video-thread-comments.list.result', async function () { | |
250 | const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId) | |
251 | ||
252 | const thread = res.body as VideoCommentThreadTree | |
253 | expect(thread.comment.text.endsWith(' <3')).to.be.true | |
254 | }) | |
255 | ||
256 | describe('Should run filter:video.auto-blacklist.result', function () { | |
257 | ||
258 | async function checkIsBlacklisted (oldRes: any, value: boolean) { | |
259 | const videoId = oldRes.body.video.uuid | |
260 | ||
261 | const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId) | |
262 | const video: VideoDetails = res.body | |
263 | expect(video.blacklisted).to.equal(value) | |
264 | } | |
265 | ||
266 | it('Should blacklist on upload', async function () { | |
a1587156 | 267 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' }) |
6691c522 C |
268 | await checkIsBlacklisted(res, true) |
269 | }) | |
270 | ||
271 | it('Should blacklist on import', async function () { | |
89566f77 C |
272 | this.timeout(15000) |
273 | ||
6691c522 C |
274 | const attributes = { |
275 | name: 'video please blacklist me', | |
b488ba1e | 276 | targetUrl: getGoodVideoUrl(), |
6691c522 C |
277 | channelId: servers[0].videoChannel.id |
278 | } | |
279 | const res = await importVideo(servers[0].url, servers[0].accessToken, attributes) | |
280 | await checkIsBlacklisted(res, true) | |
281 | }) | |
282 | ||
283 | it('Should blacklist on update', async function () { | |
a1587156 | 284 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) |
6691c522 C |
285 | const videoId = res.body.video.uuid |
286 | await checkIsBlacklisted(res, false) | |
287 | ||
a1587156 | 288 | await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' }) |
6691c522 C |
289 | await checkIsBlacklisted(res, true) |
290 | }) | |
291 | ||
292 | it('Should blacklist on remote upload', async function () { | |
293 | this.timeout(45000) | |
294 | ||
a1587156 | 295 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' }) |
6691c522 C |
296 | await waitJobs(servers) |
297 | ||
298 | await checkIsBlacklisted(res, true) | |
299 | }) | |
300 | ||
301 | it('Should blacklist on remote update', async function () { | |
302 | this.timeout(45000) | |
303 | ||
a1587156 | 304 | const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' }) |
6691c522 C |
305 | await waitJobs(servers) |
306 | ||
307 | const videoId = res.body.video.uuid | |
308 | await checkIsBlacklisted(res, false) | |
309 | ||
310 | await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' }) | |
311 | await waitJobs(servers) | |
312 | ||
313 | await checkIsBlacklisted(res, true) | |
314 | }) | |
315 | }) | |
316 | ||
4ce7eb71 C |
317 | describe('Should run filter:api.user.signup.allowed.result', function () { |
318 | ||
319 | it('Should run on config endpoint', async function () { | |
320 | const res = await getConfig(servers[0].url) | |
321 | expect((res.body as ServerConfig).signup.allowed).to.be.true | |
322 | }) | |
323 | ||
324 | it('Should allow a signup', async function () { | |
325 | await registerUser(servers[0].url, 'john', 'password') | |
326 | }) | |
327 | ||
328 | it('Should not allow a signup', async function () { | |
329 | const res = await registerUser(servers[0].url, 'jma', 'password', 403) | |
330 | ||
331 | expect(res.body.error).to.equal('No jma') | |
332 | }) | |
333 | }) | |
334 | ||
9b474844 | 335 | after(async function () { |
89cd1275 | 336 | await cleanupTests(servers) |
9b474844 C |
337 | }) |
338 | }) |