]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/external-plugins/auto-mute.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / external-plugins / auto-mute.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { HttpStatusCode } from '@shared/models'
6 import {
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 killallServers,
11 makeGetRequest,
12 PeerTubeServer,
13 setAccessTokensToServers
14 } from '@shared/server-commands'
15 import { MockBlocklist } from '../shared'
16
17 describe('Official plugin auto-mute', function () {
18 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
19 let servers: PeerTubeServer[]
20 let blocklistServer: MockBlocklist
21 let port: number
22
23 before(async function () {
24 this.timeout(120000)
25
26 servers = await createMultipleServers(2)
27 await setAccessTokensToServers(servers)
28
29 for (const server of servers) {
30 await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
31 }
32
33 blocklistServer = new MockBlocklist()
34 port = await blocklistServer.initialize()
35
36 await servers[0].videos.quickUpload({ name: 'video server 1' })
37 await servers[1].videos.quickUpload({ name: 'video server 2' })
38
39 await doubleFollow(servers[0], servers[1])
40 })
41
42 it('Should update plugin settings', async function () {
43 await servers[0].plugins.updateSettings({
44 npmName: 'peertube-plugin-auto-mute',
45 settings: {
46 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
47 'check-seconds-interval': 1
48 }
49 })
50 })
51
52 it('Should add a server blocklist', async function () {
53 this.timeout(10000)
54
55 blocklistServer.replace({
56 data: [
57 {
58 value: servers[1].host
59 }
60 ]
61 })
62
63 await wait(2000)
64
65 const { total } = await servers[0].videos.list()
66 expect(total).to.equal(1)
67 })
68
69 it('Should remove a server blocklist', async function () {
70 this.timeout(10000)
71
72 blocklistServer.replace({
73 data: [
74 {
75 value: servers[1].host,
76 action: 'remove'
77 }
78 ]
79 })
80
81 await wait(2000)
82
83 const { total } = await servers[0].videos.list()
84 expect(total).to.equal(2)
85 })
86
87 it('Should add an account blocklist', async function () {
88 this.timeout(10000)
89
90 blocklistServer.replace({
91 data: [
92 {
93 value: 'root@' + servers[1].host
94 }
95 ]
96 })
97
98 await wait(2000)
99
100 const { total } = await servers[0].videos.list()
101 expect(total).to.equal(1)
102 })
103
104 it('Should remove an account blocklist', async function () {
105 this.timeout(10000)
106
107 blocklistServer.replace({
108 data: [
109 {
110 value: 'root@' + servers[1].host,
111 action: 'remove'
112 }
113 ]
114 })
115
116 await wait(2000)
117
118 const { total } = await servers[0].videos.list()
119 expect(total).to.equal(2)
120 })
121
122 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
123 this.timeout(20000)
124
125 const account = 'root@' + servers[1].host
126
127 blocklistServer.replace({
128 data: [
129 {
130 value: account,
131 updatedAt: new Date().toISOString()
132 }
133 ]
134 })
135
136 await wait(2000)
137
138 {
139 const { total } = await servers[0].videos.list()
140 expect(total).to.equal(1)
141 }
142
143 await servers[0].blocklist.removeFromServerBlocklist({ account })
144
145 {
146 const { total } = await servers[0].videos.list()
147 expect(total).to.equal(2)
148 }
149
150 await killallServers([ servers[0] ])
151 await servers[0].run()
152 await wait(2000)
153
154 {
155 const { total } = await servers[0].videos.list()
156 expect(total).to.equal(2)
157 }
158 })
159
160 it('Should not expose the auto mute list', async function () {
161 await makeGetRequest({
162 url: servers[0].url,
163 path: '/plugins/auto-mute/router/api/v1/mute-list',
164 expectedStatus: HttpStatusCode.FORBIDDEN_403
165 })
166 })
167
168 it('Should enable auto mute list', async function () {
169 await servers[0].plugins.updateSettings({
170 npmName: 'peertube-plugin-auto-mute',
171 settings: {
172 'blocklist-urls': '',
173 'check-seconds-interval': 1,
174 'expose-mute-list': true
175 }
176 })
177
178 await makeGetRequest({
179 url: servers[0].url,
180 path: '/plugins/auto-mute/router/api/v1/mute-list',
181 expectedStatus: HttpStatusCode.OK_200
182 })
183 })
184
185 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
186 this.timeout(20000)
187
188 await servers[1].plugins.updateSettings({
189 npmName: 'peertube-plugin-auto-mute',
190 settings: {
191 'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath,
192 'check-seconds-interval': 1,
193 'expose-mute-list': false
194 }
195 })
196
197 await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
198 await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host })
199
200 const res = await makeGetRequest({
201 url: servers[0].url,
202 path: '/plugins/auto-mute/router/api/v1/mute-list',
203 expectedStatus: HttpStatusCode.OK_200
204 })
205
206 const data = res.body.data
207 expect(data).to.have.lengthOf(1)
208 expect(data[0].updatedAt).to.exist
209 expect(data[0].value).to.equal('root@' + servers[1].host)
210
211 await wait(2000)
212
213 for (const server of servers) {
214 const { total } = await server.videos.list()
215 expect(total).to.equal(1)
216 }
217 })
218
219 after(async function () {
220 await blocklistServer.terminate()
221
222 await cleanupTests(servers)
223 })
224 })