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