]>
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, |
ae2abfd3 | 10 | killallServers, |
3a7a261f | 11 | makeGetRequest, |
91b8e675 | 12 | MockBlocklist, |
ae2abfd3 C |
13 | reRunServer, |
14 | ServerInfo, | |
91b8e675 | 15 | setAccessTokensToServers, |
91b8e675 | 16 | wait |
ae2abfd3 | 17 | } from '@shared/extra-utils' |
8bff1fe0 C |
18 | |
19 | describe('Official plugin auto-mute', function () { | |
3a7a261f | 20 | const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' |
8bff1fe0 C |
21 | let servers: ServerInfo[] |
22 | let blocklistServer: MockBlocklist | |
63da15eb | 23 | let port: number |
8bff1fe0 C |
24 | |
25 | before(async function () { | |
26 | this.timeout(30000) | |
27 | ||
28 | servers = await flushAndRunMultipleServers(2) | |
29 | await setAccessTokensToServers(servers) | |
30 | ||
3a7a261f | 31 | for (const server of servers) { |
89d241a7 | 32 | await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' }) |
3a7a261f | 33 | } |
8bff1fe0 C |
34 | |
35 | blocklistServer = new MockBlocklist() | |
63da15eb | 36 | port = await blocklistServer.initialize() |
8bff1fe0 | 37 | |
89d241a7 C |
38 | await await servers[0].videos.quickUpload({ name: 'video server 1' }) |
39 | await await servers[1].videos.quickUpload({ name: 'video server 2' }) | |
8bff1fe0 C |
40 | |
41 | await doubleFollow(servers[0], servers[1]) | |
42 | }) | |
43 | ||
44 | it('Should update plugin settings', async function () { | |
89d241a7 | 45 | await servers[0].plugins.updateSettings({ |
8bff1fe0 C |
46 | npmName: 'peertube-plugin-auto-mute', |
47 | settings: { | |
63da15eb | 48 | 'blocklist-urls': `http://localhost:${port}/blocklist`, |
8bff1fe0 C |
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 | ||
89d241a7 | 67 | const { total } = await servers[0].videos.list() |
d23dd9fb | 68 | expect(total).to.equal(1) |
8bff1fe0 C |
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 | ||
89d241a7 | 85 | const { total } = await servers[0].videos.list() |
d23dd9fb | 86 | expect(total).to.equal(2) |
8bff1fe0 C |
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 | ||
89d241a7 | 102 | const { total } = await servers[0].videos.list() |
d23dd9fb | 103 | expect(total).to.equal(1) |
8bff1fe0 C |
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 | ||
89d241a7 | 120 | const { total } = await servers[0].videos.list() |
d23dd9fb | 121 | expect(total).to.equal(2) |
8bff1fe0 C |
122 | }) |
123 | ||
91b8e675 C |
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 | { | |
89d241a7 | 141 | const { total } = await servers[0].videos.list() |
d23dd9fb | 142 | expect(total).to.equal(1) |
91b8e675 C |
143 | } |
144 | ||
89d241a7 | 145 | await servers[0].blocklist.removeFromServerBlocklist({ account }) |
91b8e675 C |
146 | |
147 | { | |
89d241a7 | 148 | const { total } = await servers[0].videos.list() |
d23dd9fb | 149 | expect(total).to.equal(2) |
91b8e675 C |
150 | } |
151 | ||
9293139f | 152 | await killallServers([ servers[0] ]) |
91b8e675 C |
153 | await reRunServer(servers[0]) |
154 | await wait(2000) | |
155 | ||
156 | { | |
89d241a7 | 157 | const { total } = await servers[0].videos.list() |
d23dd9fb | 158 | expect(total).to.equal(2) |
91b8e675 C |
159 | } |
160 | }) | |
161 | ||
3a7a261f C |
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', | |
2d53be02 | 166 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
3a7a261f C |
167 | }) |
168 | }) | |
169 | ||
170 | it('Should enable auto mute list', async function () { | |
89d241a7 | 171 | await servers[0].plugins.updateSettings({ |
3a7a261f C |
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', | |
2d53be02 | 183 | statusCodeExpected: HttpStatusCode.OK_200 |
3a7a261f C |
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 | ||
89d241a7 | 190 | await servers[1].plugins.updateSettings({ |
3a7a261f C |
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 | ||
89d241a7 C |
199 | await servers[0].blocklist.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port }) |
200 | await servers[0].blocklist.addToMyBlocklist({ server: 'localhost:' + servers[1].port }) | |
3a7a261f C |
201 | |
202 | const res = await makeGetRequest({ | |
203 | url: servers[0].url, | |
204 | path: '/plugins/auto-mute/router/api/v1/mute-list', | |
2d53be02 | 205 | statusCodeExpected: HttpStatusCode.OK_200 |
3a7a261f C |
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) { | |
89d241a7 | 216 | const { total } = await server.videos.list() |
d23dd9fb | 217 | expect(total).to.equal(1) |
3a7a261f C |
218 | } |
219 | }) | |
220 | ||
8bff1fe0 | 221 | after(async function () { |
7820a54e C |
222 | await blocklistServer.terminate() |
223 | ||
8bff1fe0 C |
224 | await cleanupTests(servers) |
225 | }) | |
226 | }) |