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