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