]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
CommitLineData
8bff1fe0
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
8bff1fe0 3import { expect } from 'chai'
c55e3d72
C
4import { wait } from '@shared/core-utils'
5import { HttpStatusCode } from '@shared/models'
3a7a261f 6import {
ae2abfd3 7 cleanupTests,
254d3579 8 createMultipleServers,
4c7e60bc 9 doubleFollow,
ae2abfd3 10 killallServers,
3a7a261f 11 makeGetRequest,
254d3579 12 PeerTubeServer,
c55e3d72 13 setAccessTokensToServers
bf54587a 14} from '@shared/server-commands'
c55e3d72 15import { MockBlocklist } from '../shared'
8bff1fe0
C
16
17describe('Official plugin auto-mute', function () {
3a7a261f 18 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
254d3579 19 let servers: PeerTubeServer[]
8bff1fe0 20 let blocklistServer: MockBlocklist
63da15eb 21 let port: number
8bff1fe0
C
22
23 before(async function () {
9ec435c8 24 this.timeout(120000)
8bff1fe0 25
254d3579 26 servers = await createMultipleServers(2)
8bff1fe0
C
27 await setAccessTokensToServers(servers)
28
3a7a261f 29 for (const server of servers) {
89d241a7 30 await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
3a7a261f 31 }
8bff1fe0
C
32
33 blocklistServer = new MockBlocklist()
63da15eb 34 port = await blocklistServer.initialize()
8bff1fe0 35
c0e8b12e
C
36 await servers[0].videos.quickUpload({ name: 'video server 1' })
37 await servers[1].videos.quickUpload({ name: 'video server 2' })
8bff1fe0
C
38
39 await doubleFollow(servers[0], servers[1])
40 })
41
42 it('Should update plugin settings', async function () {
89d241a7 43 await servers[0].plugins.updateSettings({
8bff1fe0
C
44 npmName: 'peertube-plugin-auto-mute',
45 settings: {
2732eeff 46 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
8bff1fe0
C
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 {
2732eeff 58 value: servers[1].host
8bff1fe0
C
59 }
60 ]
61 })
62
63 await wait(2000)
64
89d241a7 65 const { total } = await servers[0].videos.list()
d23dd9fb 66 expect(total).to.equal(1)
8bff1fe0
C
67 })
68
69 it('Should remove a server blocklist', async function () {
70 this.timeout(10000)
71
72 blocklistServer.replace({
73 data: [
74 {
2732eeff 75 value: servers[1].host,
8bff1fe0
C
76 action: 'remove'
77 }
78 ]
79 })
80
81 await wait(2000)
82
89d241a7 83 const { total } = await servers[0].videos.list()
d23dd9fb 84 expect(total).to.equal(2)
8bff1fe0
C
85 })
86
87 it('Should add an account blocklist', async function () {
88 this.timeout(10000)
89
90 blocklistServer.replace({
91 data: [
92 {
2732eeff 93 value: 'root@' + servers[1].host
8bff1fe0
C
94 }
95 ]
96 })
97
98 await wait(2000)
99
89d241a7 100 const { total } = await servers[0].videos.list()
d23dd9fb 101 expect(total).to.equal(1)
8bff1fe0
C
102 })
103
104 it('Should remove an account blocklist', async function () {
105 this.timeout(10000)
106
107 blocklistServer.replace({
108 data: [
109 {
2732eeff 110 value: 'root@' + servers[1].host,
8bff1fe0
C
111 action: 'remove'
112 }
113 ]
114 })
115
116 await wait(2000)
117
89d241a7 118 const { total } = await servers[0].videos.list()
d23dd9fb 119 expect(total).to.equal(2)
8bff1fe0
C
120 })
121
91b8e675
C
122 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
123 this.timeout(20000)
124
2732eeff 125 const account = 'root@' + servers[1].host
91b8e675
C
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 {
89d241a7 139 const { total } = await servers[0].videos.list()
d23dd9fb 140 expect(total).to.equal(1)
91b8e675
C
141 }
142
89d241a7 143 await servers[0].blocklist.removeFromServerBlocklist({ account })
91b8e675
C
144
145 {
89d241a7 146 const { total } = await servers[0].videos.list()
d23dd9fb 147 expect(total).to.equal(2)
91b8e675
C
148 }
149
9293139f 150 await killallServers([ servers[0] ])
254d3579 151 await servers[0].run()
91b8e675
C
152 await wait(2000)
153
154 {
89d241a7 155 const { total } = await servers[0].videos.list()
d23dd9fb 156 expect(total).to.equal(2)
91b8e675
C
157 }
158 })
159
3a7a261f
C
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',
c0e8b12e 164 expectedStatus: HttpStatusCode.FORBIDDEN_403
3a7a261f
C
165 })
166 })
167
168 it('Should enable auto mute list', async function () {
89d241a7 169 await servers[0].plugins.updateSettings({
3a7a261f
C
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',
c0e8b12e 181 expectedStatus: HttpStatusCode.OK_200
3a7a261f
C
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
89d241a7 188 await servers[1].plugins.updateSettings({
3a7a261f
C
189 npmName: 'peertube-plugin-auto-mute',
190 settings: {
2732eeff 191 'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath,
3a7a261f
C
192 'check-seconds-interval': 1,
193 'expose-mute-list': false
194 }
195 })
196
2732eeff
C
197 await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
198 await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host })
3a7a261f
C
199
200 const res = await makeGetRequest({
201 url: servers[0].url,
202 path: '/plugins/auto-mute/router/api/v1/mute-list',
c0e8b12e 203 expectedStatus: HttpStatusCode.OK_200
3a7a261f
C
204 })
205
206 const data = res.body.data
207 expect(data).to.have.lengthOf(1)
208 expect(data[0].updatedAt).to.exist
2732eeff 209 expect(data[0].value).to.equal('root@' + servers[1].host)
3a7a261f
C
210
211 await wait(2000)
212
213 for (const server of servers) {
89d241a7 214 const { total } = await server.videos.list()
d23dd9fb 215 expect(total).to.equal(1)
3a7a261f
C
216 }
217 })
218
8bff1fe0 219 after(async function () {
7820a54e
C
220 await blocklistServer.terminate()
221
8bff1fe0
C
222 await cleanupTests(servers)
223 })
224})