1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { ServerConfig } from '@shared/models'
15 getVideoChannelVideos,
16 getVideoCommentThreads,
18 getVideosListPagination,
19 getVideoThreadComments,
23 setAccessTokensToServers,
24 setDefaultVideoChannel,
25 updateCustomSubConfig,
29 } from '../../../shared/extra-utils'
30 import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers'
31 import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports'
32 import { VideoDetails, VideoImport, VideoImportState, VideoPrivacy } from '../../../shared/models/videos'
33 import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
34 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
36 const expect = chai.expect
38 describe('Test plugin filter hooks', function () {
39 let servers: ServerInfo[]
43 before(async function () {
46 servers = await flushAndRunMultipleServers(2)
47 await setAccessTokensToServers(servers)
48 await setDefaultVideoChannel(servers)
49 await doubleFollow(servers[0], servers[1])
53 accessToken: servers[0].accessToken,
54 path: getPluginTestPath()
59 accessToken: servers[0].accessToken,
60 path: getPluginTestPath('-two')
63 for (let i = 0; i < 10; i++) {
64 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'default video ' + i })
67 const res = await getVideosList(servers[0].url)
68 videoUUID = res.body.data[0].uuid
70 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
71 live: { enabled: true },
72 signup: { enabled: true },
75 http: { enabled: true },
76 torrent: { enabled: true }
82 it('Should run filter:api.videos.list.params', async function () {
83 const res = await getVideosListPagination(servers[0].url, 0, 2)
85 // 2 plugins do +1 to the count parameter
86 expect(res.body.data).to.have.lengthOf(4)
89 it('Should run filter:api.videos.list.result', async function () {
90 const res = await getVideosListPagination(servers[0].url, 0, 0)
92 // Plugin do +1 to the total result
93 expect(res.body.total).to.equal(11)
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)
99 // 1 plugin do +1 to the count parameter
100 expect(res.body.data).to.have.lengthOf(3)
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)
106 // Plugin do +2 to the total result
107 expect(res.body.total).to.equal(12)
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)
113 // 1 plugin do +3 to the count parameter
114 expect(res.body.data).to.have.lengthOf(5)
117 it('Should run filter:api.video-channels.videos.list.result', async function () {
118 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2)
120 // Plugin do +3 to the total result
121 expect(res.body.total).to.equal(13)
124 it('Should run filter:api.video.get.result', async function () {
125 const res = await getVideo(servers[0].url, videoUUID)
127 expect(res.body.name).to.contain('<3')
130 it('Should run filter:api.video.upload.accept.result', async function () {
131 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video with bad word' }, HttpStatusCode.FORBIDDEN_403)
134 it('Should run filter:api.live-video.create.accept.result', async function () {
136 name: 'video with bad word',
137 privacy: VideoPrivacy.PUBLIC,
138 channelId: servers[0].videoChannel.id
141 await createLive(servers[0].url, servers[0].accessToken, attributes, HttpStatusCode.FORBIDDEN_403)
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,
149 targetUrl: getGoodVideoUrl() + 'bad'
151 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403)
154 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
155 const baseAttributes = {
157 privacy: VideoPrivacy.PUBLIC,
158 channelId: servers[0].videoChannel.id,
159 torrentfile: 'video-720p.torrent' as any
161 await importVideo(servers[0].url, servers[0].accessToken, baseAttributes, HttpStatusCode.FORBIDDEN_403)
164 it('Should run filter:api.video.post-import-url.accept.result', async function () {
167 let videoImportId: number
170 const baseAttributes = {
171 name: 'title with bad word',
172 privacy: VideoPrivacy.PUBLIC,
173 channelId: servers[0].videoChannel.id,
174 targetUrl: getGoodVideoUrl()
176 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
177 videoImportId = res.body.id
180 await waitJobs(servers)
183 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
184 const videoImports = res.body.data as VideoImport[]
186 const videoImport = videoImports.find(i => i.id === videoImportId)
188 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
189 expect(videoImport.state.label).to.equal('Rejected')
193 it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
196 let videoImportId: number
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
205 const res = await importVideo(servers[0].url, servers[0].accessToken, baseAttributes)
206 videoImportId = res.body.id
209 await waitJobs(servers)
212 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
213 const videoImports = res.body.data as VideoImport[]
215 const videoImport = videoImports.find(i => i.id === videoImportId)
217 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
218 expect(videoImport.state.label).to.equal('Rejected')
222 it('Should run filter:api.video-thread.create.accept.result', async function () {
223 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'comment with bad word', HttpStatusCode.FORBIDDEN_403)
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
230 await addVideoCommentReply(
232 servers[0].accessToken,
235 'comment with bad word',
236 HttpStatusCode.FORBIDDEN_403
238 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'comment with good word', HttpStatusCode.OK_200)
241 it('Should run filter:api.video-threads.list.params', async function () {
242 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
244 // our plugin do +1 to the count parameter
245 expect(res.body.data).to.have.lengthOf(1)
248 it('Should run filter:api.video-threads.list.result', async function () {
249 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 0)
251 // Plugin do +1 to the total result
252 expect(res.body.total).to.equal(2)
255 it('Should run filter:api.video-thread-comments.list.params')
257 it('Should run filter:api.video-thread-comments.list.result', async function () {
258 const res = await getVideoThreadComments(servers[0].url, videoUUID, threadId)
260 const thread = res.body as VideoCommentThreadTree
261 expect(thread.comment.text.endsWith(' <3')).to.be.true
264 describe('Should run filter:video.auto-blacklist.result', function () {
266 async function checkIsBlacklisted (oldRes: any, value: boolean) {
267 const videoId = oldRes.body.video.uuid
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)
274 it('Should blacklist on upload', async function () {
275 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video please blacklist me' })
276 await checkIsBlacklisted(res, true)
279 it('Should blacklist on import', async function () {
283 name: 'video please blacklist me',
284 targetUrl: getGoodVideoUrl(),
285 channelId: servers[0].videoChannel.id
287 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
288 await checkIsBlacklisted(res, true)
291 it('Should blacklist on update', async function () {
292 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
293 const videoId = res.body.video.uuid
294 await checkIsBlacklisted(res, false)
296 await updateVideo(servers[0].url, servers[0].accessToken, videoId, { name: 'please blacklist me' })
297 await checkIsBlacklisted(res, true)
300 it('Should blacklist on remote upload', async function () {
303 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'remote please blacklist me' })
304 await waitJobs(servers)
306 await checkIsBlacklisted(res, true)
309 it('Should blacklist on remote update', async function () {
312 const res = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video' })
313 await waitJobs(servers)
315 const videoId = res.body.video.uuid
316 await checkIsBlacklisted(res, false)
318 await updateVideo(servers[1].url, servers[1].accessToken, videoId, { name: 'please blacklist me' })
319 await waitJobs(servers)
321 await checkIsBlacklisted(res, true)
325 describe('Should run filter:api.user.signup.allowed.result', function () {
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
332 it('Should allow a signup', async function () {
333 await registerUser(servers[0].url, 'john', 'password')
336 it('Should not allow a signup', async function () {
337 const res = await registerUser(servers[0].url, 'jma', 'password', HttpStatusCode.FORBIDDEN_403)
339 expect(res.body.error).to.equal('No jma')
343 after(async function () {
344 await cleanupTests(servers)