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