aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/external-plugins
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/external-plugins')
-rw-r--r--server/tests/external-plugins/auto-block-videos.ts190
-rw-r--r--server/tests/external-plugins/index.ts1
2 files changed, 191 insertions, 0 deletions
diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts
new file mode 100644
index 000000000..3ec03d558
--- /dev/null
+++ b/server/tests/external-plugins/auto-block-videos.ts
@@ -0,0 +1,190 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { expect } from 'chai'
5import { Video, VideoBlacklist } from '@shared/models'
6import {
7 doubleFollow,
8 getBlacklistedVideosList,
9 getVideosList,
10 installPlugin,
11 MockBlocklist,
12 removeVideoFromBlacklist,
13 setAccessTokensToServers,
14 updatePluginSettings,
15 uploadVideoAndGetId,
16 wait
17} from '../../../shared/extra-utils'
18import {
19 cleanupTests,
20 flushAndRunMultipleServers,
21 killallServers,
22 reRunServer,
23 ServerInfo
24} from '../../../shared/extra-utils/server/servers'
25
26async function check (server: ServerInfo, videoUUID: string, exists = true) {
27 const res = await getVideosList(server.url)
28
29 const video = res.body.data.find(v => v.uuid === videoUUID)
30
31 if (exists) {
32 expect(video).to.not.be.undefined
33 } else {
34 expect(video).to.be.undefined
35 }
36}
37
38describe('Official plugin auto-block videos', function () {
39 let servers: ServerInfo[]
40 let blocklistServer: MockBlocklist
41 let server1Videos: Video[] = []
42 let server2Videos: Video[] = []
43
44 before(async function () {
45 this.timeout(60000)
46
47 servers = await flushAndRunMultipleServers(2)
48 await setAccessTokensToServers(servers)
49
50 for (const server of servers) {
51 await installPlugin({
52 url: server.url,
53 accessToken: server.accessToken,
54 npmName: 'peertube-plugin-auto-block-videos'
55 })
56 }
57
58 blocklistServer = new MockBlocklist()
59 await blocklistServer.initialize()
60
61 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
62 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
63 await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2 server 2' })
64 await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3 server 2' })
65
66 {
67 const res = await getVideosList(servers[0].url)
68 server1Videos = res.body.data.map(v => Object.assign(v, { url: servers[0].url + '/videos/watch/' + v.uuid }))
69 }
70
71 {
72 const res = await getVideosList(servers[1].url)
73 server2Videos = res.body.data.map(v => Object.assign(v, { url: servers[1].url + '/videos/watch/' + v.uuid }))
74 }
75
76 await doubleFollow(servers[0], servers[1])
77 })
78
79 it('Should update plugin settings', async function () {
80 await updatePluginSettings({
81 url: servers[0].url,
82 accessToken: servers[0].accessToken,
83 npmName: 'peertube-plugin-auto-block-videos',
84 settings: {
85 'blocklist-urls': 'http://localhost:42100/blocklist',
86 'check-seconds-interval': 1
87 }
88 })
89 })
90
91 it('Should auto block a video', async function () {
92 this.timeout(10000)
93
94 await check(servers[0], server2Videos[0].uuid, true)
95
96 blocklistServer.replace({
97 data: [
98 {
99 value: server2Videos[0].url
100 }
101 ]
102 })
103
104 await wait(2000)
105
106 await check(servers[0], server2Videos[0].uuid, false)
107 })
108
109 it('Should have video in blacklists', async function () {
110 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken })
111
112 const videoBlacklists = res.body.data as VideoBlacklist[]
113
114 expect(videoBlacklists).to.have.lengthOf(1)
115 expect(videoBlacklists[0].reason).to.contains('Automatically blocked from auto block plugin')
116 expect(videoBlacklists[0].video.name).to.equal(server2Videos[0].name)
117 })
118
119 it('Should not block a local video', async function () {
120 this.timeout(10000)
121
122 await check(servers[0], server1Videos[0].uuid, true)
123
124 blocklistServer.replace({
125 data: [
126 {
127 value: server1Videos[0].url
128 }
129 ]
130 })
131
132 await wait(2000)
133
134 await check(servers[0], server1Videos[0].uuid, true)
135 })
136
137 it('Should remove a video block', async function () {
138 this.timeout(10000)
139
140 await check(servers[0], server2Videos[0].uuid, false)
141
142 blocklistServer.replace({
143 data: [
144 {
145 value: server2Videos[0].url,
146 action: 'remove'
147 }
148 ]
149 })
150
151 await wait(2000)
152
153 await check(servers[0], server2Videos[0].uuid, true)
154 })
155
156 it('Should auto block a video, manually unblock it and do not reblock it automatically', async function () {
157 this.timeout(20000)
158
159 const video = server2Videos[1]
160
161 await check(servers[0], video.uuid, true)
162
163 blocklistServer.replace({
164 data: [
165 {
166 value: video.url,
167 updatedAt: new Date().toISOString()
168 }
169 ]
170 })
171
172 await wait(2000)
173
174 await check(servers[0], video.uuid, false)
175
176 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video.uuid)
177
178 await check(servers[0], video.uuid, true)
179
180 killallServers([ servers[0] ])
181 await reRunServer(servers[0])
182 await wait(2000)
183
184 await check(servers[0], video.uuid, true)
185 })
186
187 after(async function () {
188 await cleanupTests(servers)
189 })
190})
diff --git a/server/tests/external-plugins/index.ts b/server/tests/external-plugins/index.ts
index d17894c15..31d818b51 100644
--- a/server/tests/external-plugins/index.ts
+++ b/server/tests/external-plugins/index.ts
@@ -1,2 +1,3 @@
1import './auth-ldap' 1import './auth-ldap'
2import './auto-block-videos'
2import './auto-mute' 3import './auto-mute'