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