aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-09-23 11:38:18 +0200
committerChocobozzz <me@florianbigard.com>2022-09-23 11:38:18 +0200
commitb2a70e3ca2611a8831b6e490cc25dbf3066562c0 (patch)
treeb07d2effb206ad3fd1d39002b69c5cc20d862b5b /server/tests
parentb569b2c607bec0e671228131a5b1fe6ddf9717a0 (diff)
downloadPeerTube-b2a70e3ca2611a8831b6e490cc25dbf3066562c0.tar.gz
PeerTube-b2a70e3ca2611a8831b6e490cc25dbf3066562c0.tar.zst
PeerTube-b2a70e3ca2611a8831b6e490cc25dbf3066562c0.zip
Support refusing remote comments
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js9
-rw-r--r--server/tests/plugins/filter-hooks.ts383
2 files changed, 229 insertions, 163 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 813482a27..19dccf26e 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -178,6 +178,8 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
178 } 178 }
179 }) 179 })
180 180
181 // ---------------------------------------------------------------------------
182
181 registerHook({ 183 registerHook({
182 target: 'filter:api.video-thread.create.accept.result', 184 target: 'filter:api.video-thread.create.accept.result',
183 handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody) 185 handler: ({ accepted }, { commentBody }) => checkCommentBadWord(accepted, commentBody)
@@ -189,6 +191,13 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
189 }) 191 })
190 192
191 registerHook({ 193 registerHook({
194 target: 'filter:activity-pub.remote-video-comment.create.accept.result',
195 handler: ({ accepted }, { comment }) => checkCommentBadWord(accepted, comment)
196 })
197
198 // ---------------------------------------------------------------------------
199
200 registerHook({
192 target: 'filter:api.video-threads.list.params', 201 target: 'filter:api.video-threads.list.params',
193 handler: obj => addToCount(obj) 202 handler: obj => addToCount(obj)
194 }) 203 })
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 026c7e856..ae4b3cf5f 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -64,232 +64,289 @@ describe('Test plugin filter hooks', function () {
64 }) 64 })
65 }) 65 })
66 66
67 it('Should run filter:api.videos.list.params', async function () { 67 describe('Videos', function () {
68 const { data } = await servers[0].videos.list({ start: 0, count: 2 })
69 68
70 // 2 plugins do +1 to the count parameter 69 it('Should run filter:api.videos.list.params', async function () {
71 expect(data).to.have.lengthOf(4) 70 const { data } = await servers[0].videos.list({ start: 0, count: 2 })
72 })
73 71
74 it('Should run filter:api.videos.list.result', async function () { 72 // 2 plugins do +1 to the count parameter
75 const { total } = await servers[0].videos.list({ start: 0, count: 0 }) 73 expect(data).to.have.lengthOf(4)
74 })
76 75
77 // Plugin do +1 to the total result 76 it('Should run filter:api.videos.list.result', async function () {
78 expect(total).to.equal(11) 77 const { total } = await servers[0].videos.list({ start: 0, count: 0 })
79 })
80 78
81 it('Should run filter:api.video-playlist.videos.list.params', async function () { 79 // Plugin do +1 to the total result
82 const { data } = await servers[0].playlists.listVideos({ 80 expect(total).to.equal(11)
83 count: 2,
84 playlistId: videoPlaylistUUID
85 }) 81 })
86 82
87 // 1 plugin do +1 to the count parameter 83 it('Should run filter:api.video-playlist.videos.list.params', async function () {
88 expect(data).to.have.lengthOf(3) 84 const { data } = await servers[0].playlists.listVideos({
89 }) 85 count: 2,
86 playlistId: videoPlaylistUUID
87 })
90 88
91 it('Should run filter:api.video-playlist.videos.list.result', async function () { 89 // 1 plugin do +1 to the count parameter
92 const { total } = await servers[0].playlists.listVideos({ 90 expect(data).to.have.lengthOf(3)
93 count: 0,
94 playlistId: videoPlaylistUUID
95 }) 91 })
96 92
97 // Plugin do +1 to the total result 93 it('Should run filter:api.video-playlist.videos.list.result', async function () {
98 expect(total).to.equal(11) 94 const { total } = await servers[0].playlists.listVideos({
99 }) 95 count: 0,
96 playlistId: videoPlaylistUUID
97 })
100 98
101 it('Should run filter:api.accounts.videos.list.params', async function () { 99 // Plugin do +1 to the total result
102 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) 100 expect(total).to.equal(11)
101 })
103 102
104 // 1 plugin do +1 to the count parameter 103 it('Should run filter:api.accounts.videos.list.params', async function () {
105 expect(data).to.have.lengthOf(3) 104 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
106 })
107 105
108 it('Should run filter:api.accounts.videos.list.result', async function () { 106 // 1 plugin do +1 to the count parameter
109 const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 }) 107 expect(data).to.have.lengthOf(3)
108 })
110 109
111 // Plugin do +2 to the total result 110 it('Should run filter:api.accounts.videos.list.result', async function () {
112 expect(total).to.equal(12) 111 const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
113 })
114 112
115 it('Should run filter:api.video-channels.videos.list.params', async function () { 113 // Plugin do +2 to the total result
116 const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) 114 expect(total).to.equal(12)
115 })
117 116
118 // 1 plugin do +3 to the count parameter 117 it('Should run filter:api.video-channels.videos.list.params', async function () {
119 expect(data).to.have.lengthOf(5) 118 const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
120 })
121 119
122 it('Should run filter:api.video-channels.videos.list.result', async function () { 120 // 1 plugin do +3 to the count parameter
123 const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 }) 121 expect(data).to.have.lengthOf(5)
122 })
124 123
125 // Plugin do +3 to the total result 124 it('Should run filter:api.video-channels.videos.list.result', async function () {
126 expect(total).to.equal(13) 125 const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
127 })
128 126
129 it('Should run filter:api.user.me.videos.list.params', async function () { 127 // Plugin do +3 to the total result
130 const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) 128 expect(total).to.equal(13)
129 })
131 130
132 // 1 plugin do +4 to the count parameter 131 it('Should run filter:api.user.me.videos.list.params', async function () {
133 expect(data).to.have.lengthOf(6) 132 const { data } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
134 })
135 133
136 it('Should run filter:api.user.me.videos.list.result', async function () { 134 // 1 plugin do +4 to the count parameter
137 const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 }) 135 expect(data).to.have.lengthOf(6)
136 })
138 137
139 // Plugin do +4 to the total result 138 it('Should run filter:api.user.me.videos.list.result', async function () {
140 expect(total).to.equal(14) 139 const { total } = await servers[0].videos.listMyVideos({ start: 0, count: 2 })
141 })
142 140
143 it('Should run filter:api.video.get.result', async function () { 141 // Plugin do +4 to the total result
144 const video = await servers[0].videos.get({ id: videoUUID }) 142 expect(total).to.equal(14)
145 expect(video.name).to.contain('<3') 143 })
146 })
147 144
148 it('Should run filter:api.video.upload.accept.result', async function () { 145 it('Should run filter:api.video.get.result', async function () {
149 await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 146 const video = await servers[0].videos.get({ id: videoUUID })
147 expect(video.name).to.contain('<3')
148 })
150 }) 149 })
151 150
152 it('Should run filter:api.live-video.create.accept.result', async function () { 151 describe('Video/live/import accept', function () {
153 const attributes = {
154 name: 'video with bad word',
155 privacy: VideoPrivacy.PUBLIC,
156 channelId: servers[0].store.channel.id
157 }
158 152
159 await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 153 it('Should run filter:api.video.upload.accept.result', async function () {
160 }) 154 await servers[0].videos.upload({ attributes: { name: 'video with bad word' }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
161 155 })
162 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
163 const attributes = {
164 name: 'normal title',
165 privacy: VideoPrivacy.PUBLIC,
166 channelId: servers[0].store.channel.id,
167 targetUrl: FIXTURE_URLS.goodVideo + 'bad'
168 }
169 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
170 })
171 156
172 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () { 157 it('Should run filter:api.live-video.create.accept.result', async function () {
173 const attributes = { 158 const attributes = {
174 name: 'bad torrent', 159 name: 'video with bad word',
175 privacy: VideoPrivacy.PUBLIC, 160 privacy: VideoPrivacy.PUBLIC,
176 channelId: servers[0].store.channel.id, 161 channelId: servers[0].store.channel.id
177 torrentfile: 'video-720p.torrent' as any 162 }
178 }
179 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
180 })
181 163
182 it('Should run filter:api.video.post-import-url.accept.result', async function () { 164 await servers[0].live.create({ fields: attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
183 this.timeout(60000) 165 })
184 166
185 let videoImportId: number 167 it('Should run filter:api.video.pre-import-url.accept.result', async function () {
168 const attributes = {
169 name: 'normal title',
170 privacy: VideoPrivacy.PUBLIC,
171 channelId: servers[0].store.channel.id,
172 targetUrl: FIXTURE_URLS.goodVideo + 'bad'
173 }
174 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
175 })
186 176
187 { 177 it('Should run filter:api.video.pre-import-torrent.accept.result', async function () {
188 const attributes = { 178 const attributes = {
189 name: 'title with bad word', 179 name: 'bad torrent',
190 privacy: VideoPrivacy.PUBLIC, 180 privacy: VideoPrivacy.PUBLIC,
191 channelId: servers[0].store.channel.id, 181 channelId: servers[0].store.channel.id,
192 targetUrl: FIXTURE_URLS.goodVideo 182 torrentfile: 'video-720p.torrent' as any
193 } 183 }
194 const body = await servers[0].imports.importVideo({ attributes }) 184 await servers[0].imports.importVideo({ attributes, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
195 videoImportId = body.id 185 })
196 }
197 186
198 await waitJobs(servers) 187 it('Should run filter:api.video.post-import-url.accept.result', async function () {
188 this.timeout(60000)
199 189
200 { 190 let videoImportId: number
201 const body = await servers[0].imports.getMyVideoImports()
202 const videoImports = body.data
203 191
204 const videoImport = videoImports.find(i => i.id === videoImportId) 192 {
193 const attributes = {
194 name: 'title with bad word',
195 privacy: VideoPrivacy.PUBLIC,
196 channelId: servers[0].store.channel.id,
197 targetUrl: FIXTURE_URLS.goodVideo
198 }
199 const body = await servers[0].imports.importVideo({ attributes })
200 videoImportId = body.id
201 }
205 202
206 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) 203 await waitJobs(servers)
207 expect(videoImport.state.label).to.equal('Rejected')
208 }
209 })
210 204
211 it('Should run filter:api.video.post-import-torrent.accept.result', async function () { 205 {
212 this.timeout(60000) 206 const body = await servers[0].imports.getMyVideoImports()
207 const videoImports = body.data
213 208
214 let videoImportId: number 209 const videoImport = videoImports.find(i => i.id === videoImportId)
215 210
216 { 211 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
217 const attributes = { 212 expect(videoImport.state.label).to.equal('Rejected')
218 name: 'title with bad word',
219 privacy: VideoPrivacy.PUBLIC,
220 channelId: servers[0].store.channel.id,
221 torrentfile: 'video-720p.torrent' as any
222 } 213 }
223 const body = await servers[0].imports.importVideo({ attributes }) 214 })
224 videoImportId = body.id
225 }
226 215
227 await waitJobs(servers) 216 it('Should run filter:api.video.post-import-torrent.accept.result', async function () {
217 this.timeout(60000)
228 218
229 { 219 let videoImportId: number
230 const { data: videoImports } = await servers[0].imports.getMyVideoImports()
231 220
232 const videoImport = videoImports.find(i => i.id === videoImportId) 221 {
222 const attributes = {
223 name: 'title with bad word',
224 privacy: VideoPrivacy.PUBLIC,
225 channelId: servers[0].store.channel.id,
226 torrentfile: 'video-720p.torrent' as any
227 }
228 const body = await servers[0].imports.importVideo({ attributes })
229 videoImportId = body.id
230 }
233 231
234 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED) 232 await waitJobs(servers)
235 expect(videoImport.state.label).to.equal('Rejected') 233
236 } 234 {
237 }) 235 const { data: videoImports } = await servers[0].imports.getMyVideoImports()
236
237 const videoImport = videoImports.find(i => i.id === videoImportId)
238 238
239 it('Should run filter:api.video-thread.create.accept.result', async function () { 239 expect(videoImport.state.id).to.equal(VideoImportState.REJECTED)
240 await servers[0].comments.createThread({ 240 expect(videoImport.state.label).to.equal('Rejected')
241 videoId: videoUUID, 241 }
242 text: 'comment with bad word',
243 expectedStatus: HttpStatusCode.FORBIDDEN_403
244 }) 242 })
245 }) 243 })
246 244
247 it('Should run filter:api.video-comment-reply.create.accept.result', async function () { 245 describe('Video comments accept', function () {
248 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
249 threadId = created.id
250 246
251 await servers[0].comments.addReply({ 247 it('Should run filter:api.video-thread.create.accept.result', async function () {
252 videoId: videoUUID, 248 await servers[0].comments.createThread({
253 toCommentId: threadId, 249 videoId: videoUUID,
254 text: 'comment with bad word', 250 text: 'comment with bad word',
255 expectedStatus: HttpStatusCode.FORBIDDEN_403 251 expectedStatus: HttpStatusCode.FORBIDDEN_403
252 })
256 }) 253 })
257 await servers[0].comments.addReply({ 254
258 videoId: videoUUID, 255 it('Should run filter:api.video-comment-reply.create.accept.result', async function () {
259 toCommentId: threadId, 256 const created = await servers[0].comments.createThread({ videoId: videoUUID, text: 'thread' })
260 text: 'comment with good word', 257 threadId = created.id
261 expectedStatus: HttpStatusCode.OK_200 258
259 await servers[0].comments.addReply({
260 videoId: videoUUID,
261 toCommentId: threadId,
262 text: 'comment with bad word',
263 expectedStatus: HttpStatusCode.FORBIDDEN_403
264 })
265 await servers[0].comments.addReply({
266 videoId: videoUUID,
267 toCommentId: threadId,
268 text: 'comment with good word',
269 expectedStatus: HttpStatusCode.OK_200
270 })
262 }) 271 })
263 })
264 272
265 it('Should run filter:api.video-threads.list.params', async function () { 273 it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a thread creation', async function () {
266 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 }) 274 this.timeout(30000)
267 275
268 // our plugin do +1 to the count parameter 276 await servers[1].comments.createThread({ videoId: videoUUID, text: 'comment with bad word' })
269 expect(data).to.have.lengthOf(1)
270 })
271 277
272 it('Should run filter:api.video-threads.list.result', async function () { 278 await waitJobs(servers)
273 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
274 279
275 // Plugin do +1 to the total result 280 {
276 expect(total).to.equal(2) 281 const thread = await servers[0].comments.listThreads({ videoId: videoUUID })
277 }) 282 expect(thread.data).to.have.lengthOf(1)
283 expect(thread.data[0].text).to.not.include(' bad ')
284 }
285
286 {
287 const thread = await servers[1].comments.listThreads({ videoId: videoUUID })
288 expect(thread.data).to.have.lengthOf(2)
289 }
290 })
278 291
279 it('Should run filter:api.video-thread-comments.list.params') 292 it('Should run filter:activity-pub.remote-video-comment.create.accept.result on a reply creation', async function () {
293 this.timeout(30000)
280 294
281 it('Should run filter:api.video-thread-comments.list.result', async function () { 295 const { data } = await servers[1].comments.listThreads({ videoId: videoUUID })
282 const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId }) 296 const threadIdServer2 = data.find(t => t.text === 'thread').id
283 297
284 expect(thread.comment.text.endsWith(' <3')).to.be.true 298 await servers[1].comments.addReply({
299 videoId: videoUUID,
300 toCommentId: threadIdServer2,
301 text: 'comment with bad word'
302 })
303
304 await waitJobs(servers)
305
306 {
307 const tree = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
308 expect(tree.children).to.have.lengthOf(1)
309 expect(tree.children[0].comment.text).to.not.include(' bad ')
310 }
311
312 {
313 const tree = await servers[1].comments.getThread({ videoId: videoUUID, threadId: threadIdServer2 })
314 expect(tree.children).to.have.lengthOf(2)
315 }
316 })
285 }) 317 })
286 318
287 it('Should run filter:api.overviews.videos.list.{params,result}', async function () { 319 describe('Video comments', function () {
288 await servers[0].overviews.getVideos({ page: 1 }) 320
321 it('Should run filter:api.video-threads.list.params', async function () {
322 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
323
324 // our plugin do +1 to the count parameter
325 expect(data).to.have.lengthOf(1)
326 })
289 327
290 // 3 because we get 3 samples per page 328 it('Should run filter:api.video-threads.list.result', async function () {
291 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3) 329 const { total } = await servers[0].comments.listThreads({ videoId: videoUUID, start: 0, count: 0 })
292 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3) 330
331 // Plugin do +1 to the total result
332 expect(total).to.equal(2)
333 })
334
335 it('Should run filter:api.video-thread-comments.list.params')
336
337 it('Should run filter:api.video-thread-comments.list.result', async function () {
338 const thread = await servers[0].comments.getThread({ videoId: videoUUID, threadId })
339
340 expect(thread.comment.text.endsWith(' <3')).to.be.true
341 })
342
343 it('Should run filter:api.overviews.videos.list.{params,result}', async function () {
344 await servers[0].overviews.getVideos({ page: 1 })
345
346 // 3 because we get 3 samples per page
347 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
348 await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
349 })
293 }) 350 })
294 351
295 describe('filter:video.auto-blacklist.result', function () { 352 describe('filter:video.auto-blacklist.result', function () {