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