]>
Commit | Line | Data |
---|---|---|
8bff1fe0 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
8bff1fe0 | 3 | import { expect } from 'chai' |
c55e3d72 C |
4 | import { wait } from '@shared/core-utils' |
5 | import { HttpStatusCode } from '@shared/models' | |
3a7a261f | 6 | import { |
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 | 15 | import { MockBlocklist } from '../shared' |
8bff1fe0 C |
16 | |
17 | describe('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 () { | |
8bff1fe0 C |
53 | blocklistServer.replace({ |
54 | data: [ | |
55 | { | |
2732eeff | 56 | value: servers[1].host |
8bff1fe0 C |
57 | } |
58 | ] | |
59 | }) | |
60 | ||
61 | await wait(2000) | |
62 | ||
89d241a7 | 63 | const { total } = await servers[0].videos.list() |
d23dd9fb | 64 | expect(total).to.equal(1) |
8bff1fe0 C |
65 | }) |
66 | ||
67 | it('Should remove a server blocklist', async function () { | |
8bff1fe0 C |
68 | blocklistServer.replace({ |
69 | data: [ | |
70 | { | |
2732eeff | 71 | value: servers[1].host, |
8bff1fe0 C |
72 | action: 'remove' |
73 | } | |
74 | ] | |
75 | }) | |
76 | ||
77 | await wait(2000) | |
78 | ||
89d241a7 | 79 | const { total } = await servers[0].videos.list() |
d23dd9fb | 80 | expect(total).to.equal(2) |
8bff1fe0 C |
81 | }) |
82 | ||
83 | it('Should add an account blocklist', async function () { | |
8bff1fe0 C |
84 | blocklistServer.replace({ |
85 | data: [ | |
86 | { | |
2732eeff | 87 | value: 'root@' + servers[1].host |
8bff1fe0 C |
88 | } |
89 | ] | |
90 | }) | |
91 | ||
92 | await wait(2000) | |
93 | ||
89d241a7 | 94 | const { total } = await servers[0].videos.list() |
d23dd9fb | 95 | expect(total).to.equal(1) |
8bff1fe0 C |
96 | }) |
97 | ||
98 | it('Should remove an account blocklist', async function () { | |
8bff1fe0 C |
99 | blocklistServer.replace({ |
100 | data: [ | |
101 | { | |
2732eeff | 102 | value: 'root@' + servers[1].host, |
8bff1fe0 C |
103 | action: 'remove' |
104 | } | |
105 | ] | |
106 | }) | |
107 | ||
108 | await wait(2000) | |
109 | ||
89d241a7 | 110 | const { total } = await servers[0].videos.list() |
d23dd9fb | 111 | expect(total).to.equal(2) |
8bff1fe0 C |
112 | }) |
113 | ||
91b8e675 C |
114 | it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () { |
115 | this.timeout(20000) | |
116 | ||
2732eeff | 117 | const account = 'root@' + servers[1].host |
91b8e675 C |
118 | |
119 | blocklistServer.replace({ | |
120 | data: [ | |
121 | { | |
122 | value: account, | |
123 | updatedAt: new Date().toISOString() | |
124 | } | |
125 | ] | |
126 | }) | |
127 | ||
128 | await wait(2000) | |
129 | ||
130 | { | |
89d241a7 | 131 | const { total } = await servers[0].videos.list() |
d23dd9fb | 132 | expect(total).to.equal(1) |
91b8e675 C |
133 | } |
134 | ||
89d241a7 | 135 | await servers[0].blocklist.removeFromServerBlocklist({ account }) |
91b8e675 C |
136 | |
137 | { | |
89d241a7 | 138 | const { total } = await servers[0].videos.list() |
d23dd9fb | 139 | expect(total).to.equal(2) |
91b8e675 C |
140 | } |
141 | ||
9293139f | 142 | await killallServers([ servers[0] ]) |
254d3579 | 143 | await servers[0].run() |
91b8e675 C |
144 | await wait(2000) |
145 | ||
146 | { | |
89d241a7 | 147 | const { total } = await servers[0].videos.list() |
d23dd9fb | 148 | expect(total).to.equal(2) |
91b8e675 C |
149 | } |
150 | }) | |
151 | ||
3a7a261f C |
152 | it('Should not expose the auto mute list', async function () { |
153 | await makeGetRequest({ | |
154 | url: servers[0].url, | |
155 | path: '/plugins/auto-mute/router/api/v1/mute-list', | |
c0e8b12e | 156 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
3a7a261f C |
157 | }) |
158 | }) | |
159 | ||
160 | it('Should enable auto mute list', async function () { | |
89d241a7 | 161 | await servers[0].plugins.updateSettings({ |
3a7a261f C |
162 | npmName: 'peertube-plugin-auto-mute', |
163 | settings: { | |
164 | 'blocklist-urls': '', | |
165 | 'check-seconds-interval': 1, | |
166 | 'expose-mute-list': true | |
167 | } | |
168 | }) | |
169 | ||
170 | await makeGetRequest({ | |
171 | url: servers[0].url, | |
172 | path: '/plugins/auto-mute/router/api/v1/mute-list', | |
c0e8b12e | 173 | expectedStatus: HttpStatusCode.OK_200 |
3a7a261f C |
174 | }) |
175 | }) | |
176 | ||
177 | it('Should mute an account on server 1, and server 2 auto mutes it', async function () { | |
178 | this.timeout(20000) | |
179 | ||
89d241a7 | 180 | await servers[1].plugins.updateSettings({ |
3a7a261f C |
181 | npmName: 'peertube-plugin-auto-mute', |
182 | settings: { | |
2732eeff | 183 | 'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath, |
3a7a261f C |
184 | 'check-seconds-interval': 1, |
185 | 'expose-mute-list': false | |
186 | } | |
187 | }) | |
188 | ||
2732eeff C |
189 | await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host }) |
190 | await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host }) | |
3a7a261f C |
191 | |
192 | const res = await makeGetRequest({ | |
193 | url: servers[0].url, | |
194 | path: '/plugins/auto-mute/router/api/v1/mute-list', | |
c0e8b12e | 195 | expectedStatus: HttpStatusCode.OK_200 |
3a7a261f C |
196 | }) |
197 | ||
198 | const data = res.body.data | |
199 | expect(data).to.have.lengthOf(1) | |
200 | expect(data[0].updatedAt).to.exist | |
2732eeff | 201 | expect(data[0].value).to.equal('root@' + servers[1].host) |
3a7a261f C |
202 | |
203 | await wait(2000) | |
204 | ||
205 | for (const server of servers) { | |
89d241a7 | 206 | const { total } = await server.videos.list() |
d23dd9fb | 207 | expect(total).to.equal(1) |
3a7a261f C |
208 | } |
209 | }) | |
210 | ||
8bff1fe0 | 211 | after(async function () { |
7820a54e C |
212 | await blocklistServer.terminate() |
213 | ||
8bff1fe0 C |
214 | await cleanupTests(servers) |
215 | }) | |
216 | }) |