1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { ServerConfig } from '@shared/models'
16 getVideoChannelVideos,
17 getVideoCommentThreads,
19 getVideosListPagination,
20 getVideoThreadComments,
24 setAccessTokensToServers,
25 setDefaultVideoChannel,
26 updateCustomSubConfig,
30 } from '../../../shared/extra-utils'
31 import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers'
32 import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports'
33 import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos'
34 import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
35 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
37 const expect = chai.expect
39 describe('Test plugin filter hooks', function () {
40 let servers: ServerInfo[]
44 before(async function () {
47 servers = await flushAndRunMultipleServers(2)
48 await setAccessTokensToServers(servers)
49 await setDefaultVideoChannel(servers)
50 await doubleFollow(servers[0], servers[1])
54 accessToken: servers[0].accessToken,
55 path: getPluginTestPath()
60 accessToken: servers[0].accessToken,
61 path: getPluginTestPath('-two')
64 for (let i = 0; i < 10; i++) {
65 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
68 const res = await getVideosList(servers[0].url)
69 videoUUID = res.body.data[0].uuid
71 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
72 live: { enabled: true },
73 signup: { enabled: true },
76 http: { enabled: true },
77 torrent: { enabled: true }
83 it('Should run filter:api.videos.list.params', async function () {
84 const res = await getVideosListPagination(servers[0].url, 0, 2)
86 // 2 plugins do +1 to the count parameter
87 expect(res.body.data).to.have.lengthOf(4)
90 it('Should run filter:api.videos.list.result', async function () {
91 const res = await getVideosListPagination(servers[0].url, 0, 0)
93 // Plugin do +1 to the total result
94 expect(res.body.total).to.equal(11)
97 it('Should run filter:api.accounts.videos.list.params', async function () {
98 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2)
100 // 1 plugin do +1 to the count parameter
101 expect(res.body.data).to.have.lengthOf(3)
104 it('Should run filter:api.accounts.videos.list.result', async function () {
105 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2)
107 // Plugin do +2 to the total result
108 expect(res.body.total).to.equal(12)
111 it('Should run filter:api.video-channels.videos.list.params', async function () {
112 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2)
114 // 1 plugin do +3 to the count parameter
115 expect(res.body.data).to.have.lengthOf(5)
118 it('Should run filter:api.video-channels.videos.list.result', async function () {
119 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2)
121 // Plugin do +3 to the total result
122 expect(res.body.total).to.equal(13)
125 it('Should run filter:api.user.me.videos.list.params', async function () {
126 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2)
128 // 1 plugin do +4 to the count parameter
129 expect(res.body.data).to.have.lengthOf(6)
132 it('Should run filter:api.user.me.videos.list.result', async function () {
133 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 2)
135 // Plugin do +4 to the total result
136 expect(res.body.total).to.equal(14)
139 it('Should run filter:api.video.get.result', async function () {
140 const res = await getVideo(servers[0].url, videoUUID)
142 expect(res.body.name).to.contain('<3')
145 it('Should run filter:api.video.upload.accept.result', async function () {
146 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403)
149 it('Should run filter:api.live-video.create.accept.result', async function () {
151 name: 'video with bad word',
152 privacy: VideoPrivacy.PUBLIC,
153 channelId: servers[0].videoChannel.id
156 await createLive(servers[0].url, servers[0].accessToken, attributes, HttpStatusCode.FORBIDDEN_403)
159 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
160 const baseAttributes = {
161 name: 'normal title',
162 privacy: VideoPrivacy.PUBLIC,
163 channelId: servers[0].videoChannel.id,
164 targetUrl: getGoodVideoUrl() + 'bad'
166 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403)
169 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
170 const baseAttributes = {
172 privacy: VideoPrivacy.PUBLIC,
173 channelId: servers[0].videoChannel.id,
174 torrentfile: 'video-720p.torrent' as any
176 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403)
179 it('Should run filter:api.video.post-import-url.accept.result', async function () {
182 let videoImportId: number
185 const baseAttributes = {
186 name: 'title with bad word',
187 privacy: VideoPrivacy.PUBLIC,
188 channelId: servers[0].videoChannel.id,
189 targetUrl: getGoodVideoUrl()
191 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
192 videoImportId = res.body.id
195 await waitJobs(servers)
198 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
199 const videoImports = res.body.data as VideoImport[]
201 const videoImport = videoImports.find(i => i.id === videoImportId)
203 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
204 expect(videoImport.state.label).to.equal('Rejected')
208 it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
211 let videoImportId: number
214 const baseAttributes = {
215 name: 'title with bad word',
216 privacy: VideoPrivacy.PUBLIC,
217 channelId: servers[0].videoChannel.id,
218 torrentfile: 'video-720p.torrent' as any
220 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
221 videoImportId = res.body.id
224 await waitJobs(servers)
227 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
228 const videoImports = res.body.data as VideoImport[]
230 const videoImport = videoImports.find(i => i.id === videoImportId)
232 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
233 expect(videoImport.state.label).to.equal('Rejected')
237 it('Should run filter:api.video-thread.create.accept.result', async function () {
238 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403)
241 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
242 const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread')
243 threadId = res.body.comment.id
245 await addVideoCommentReply(
247 servers[0].accessToken,
250 'comment with bad word',
251 HttpStatusCode.FORBIDDEN_403
253 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200)
256 it('Should run filter:api.video-threads.list.params', async function () {
257 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
259 // our plugin do +1 to the count parameter
260 expect(res.body.data).to.have.lengthOf(1)
263 it('Should run filter:api.video-threads.list.result', async function () {
264 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
266 // Plugin do +1 to the total result
267 expect(res.body.total).to.equal(2)
270 it('Should run filter:api.video-thread-comments.list.params')
272 it('Should run filter:api.video-thread-comments.list.result', async function () {
273 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId)
275 const thread = res.body as VideoCommentThreadTree
276 expect(thread.comment.text.endsWith(' <3')).to.be.true
279 describe('Should run filter:video.auto-blacklist.result', function () {
281 async function checkIsBlacklisted (oldRes: any, value: boolean) {
282 const videoId = oldRes.body.video.uuid
284 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, videoId)
285 const video: VideoDetails = res.body
286 expect(video.blacklisted).to.equal(value)
289 it('Should blacklist on upload', async function () {
290 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' })
291 await checkIsBlacklisted(res, true)
294 it('Should blacklist on import', async function () {
298 name: 'video please blacklist me',
299 targetUrl: getGoodVideoUrl(),
300 channelId: servers[0].videoChannel.id
302 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
303 await checkIsBlacklisted(res, true)
306 it('Should blacklist on update', async function () {
307 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
308 const videoId = res.body.video.uuid
309 await checkIsBlacklisted(res, false)
311 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' })
312 await checkIsBlacklisted(res, true)
315 it('Should blacklist on remote upload', async function () {
318 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
319 await waitJobs(servers)
321 await checkIsBlacklisted(res, true)
324 it('Should blacklist on remote update', async function () {
327 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' })
328 await waitJobs(servers)
330 const videoId = res.body.video.uuid
331 await checkIsBlacklisted(res, false)
333 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
334 await waitJobs(servers)
336 await checkIsBlacklisted(res, true)
340 describe('Should run filter:api.user.signup.allowed.result', function () {
342 it('Should run on config endpoint', async function () {
343 const res = await getConfig(servers[0].url)
344 expect((res.body as ServerConfig).signup.allowed).to.be.true
347 it('Should allow a signup', async function () {
348 await registerUser(servers[0].url, 'john', 'password')
351 it('Should not allow a signup', async function () {
352 const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403)
354 expect(res.body.error).to.equal('No jma')
358 after(async function () {
359 await cleanupTests(servers)