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