]>
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' |
91b8e675 C |
5 | import { removeAccountFromServerBlocklist } from '@shared/extra-utils/users/blocklist' |
6 | import { | |
7 | doubleFollow, | |
8 | getVideosList, | |
9 | installPlugin, | |
10 | MockBlocklist, | |
11 | setAccessTokensToServers, | |
12 | updatePluginSettings, | |
13 | uploadVideoAndGetId, | |
14 | wait | |
15 | } from '../../../shared/extra-utils' | |
16 | import { | |
17 | cleanupTests, | |
18 | flushAndRunMultipleServers, | |
19 | killallServers, | |
20 | reRunServer, | |
21 | ServerInfo | |
22 | } from '../../../shared/extra-utils/server/servers' | |
8bff1fe0 C |
23 | |
24 | describe('Official plugin auto-mute', function () { | |
25 | let servers: ServerInfo[] | |
26 | let blocklistServer: MockBlocklist | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(30000) | |
30 | ||
31 | servers = await flushAndRunMultipleServers(2) | |
32 | await setAccessTokensToServers(servers) | |
33 | ||
34 | await installPlugin({ | |
35 | url: servers[0].url, | |
36 | accessToken: servers[0].accessToken, | |
37 | npmName: 'peertube-plugin-auto-mute' | |
38 | }) | |
39 | ||
40 | blocklistServer = new MockBlocklist() | |
41 | await blocklistServer.initialize() | |
42 | ||
43 | await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' }) | |
44 | await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' }) | |
45 | ||
46 | await doubleFollow(servers[0], servers[1]) | |
47 | }) | |
48 | ||
49 | it('Should update plugin settings', async function () { | |
50 | await updatePluginSettings({ | |
51 | url: servers[0].url, | |
52 | accessToken: servers[0].accessToken, | |
53 | npmName: 'peertube-plugin-auto-mute', | |
54 | settings: { | |
55 | 'blocklist-urls': 'http://localhost:42100/blocklist', | |
56 | 'check-seconds-interval': 1 | |
57 | } | |
58 | }) | |
59 | }) | |
60 | ||
61 | it('Should add a server blocklist', async function () { | |
62 | this.timeout(10000) | |
63 | ||
64 | blocklistServer.replace({ | |
65 | data: [ | |
66 | { | |
67 | value: 'localhost:' + servers[1].port | |
68 | } | |
69 | ] | |
70 | }) | |
71 | ||
72 | await wait(2000) | |
73 | ||
74 | const res = await getVideosList(servers[0].url) | |
75 | expect(res.body.total).to.equal(1) | |
76 | }) | |
77 | ||
78 | it('Should remove a server blocklist', async function () { | |
79 | this.timeout(10000) | |
80 | ||
81 | blocklistServer.replace({ | |
82 | data: [ | |
83 | { | |
84 | value: 'localhost:' + servers[1].port, | |
85 | action: 'remove' | |
86 | } | |
87 | ] | |
88 | }) | |
89 | ||
90 | await wait(2000) | |
91 | ||
92 | const res = await getVideosList(servers[0].url) | |
93 | expect(res.body.total).to.equal(2) | |
94 | }) | |
95 | ||
96 | it('Should add an account blocklist', async function () { | |
97 | this.timeout(10000) | |
98 | ||
99 | blocklistServer.replace({ | |
100 | data: [ | |
101 | { | |
102 | value: 'root@localhost:' + servers[1].port | |
103 | } | |
104 | ] | |
105 | }) | |
106 | ||
107 | await wait(2000) | |
108 | ||
109 | const res = await getVideosList(servers[0].url) | |
110 | expect(res.body.total).to.equal(1) | |
111 | }) | |
112 | ||
113 | it('Should remove an account blocklist', async function () { | |
114 | this.timeout(10000) | |
115 | ||
116 | blocklistServer.replace({ | |
117 | data: [ | |
118 | { | |
119 | value: 'root@localhost:' + servers[1].port, | |
120 | action: 'remove' | |
121 | } | |
122 | ] | |
123 | }) | |
124 | ||
125 | await wait(2000) | |
126 | ||
127 | const res = await getVideosList(servers[0].url) | |
128 | expect(res.body.total).to.equal(2) | |
129 | }) | |
130 | ||
91b8e675 C |
131 | it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () { |
132 | this.timeout(20000) | |
133 | ||
134 | const account = 'root@localhost:' + servers[1].port | |
135 | ||
136 | blocklistServer.replace({ | |
137 | data: [ | |
138 | { | |
139 | value: account, | |
140 | updatedAt: new Date().toISOString() | |
141 | } | |
142 | ] | |
143 | }) | |
144 | ||
145 | await wait(2000) | |
146 | ||
147 | { | |
148 | const res = await getVideosList(servers[0].url) | |
149 | expect(res.body.total).to.equal(1) | |
150 | } | |
151 | ||
152 | await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account) | |
153 | ||
154 | { | |
155 | const res = await getVideosList(servers[0].url) | |
156 | expect(res.body.total).to.equal(2) | |
157 | } | |
158 | ||
159 | killallServers([ servers[0] ]) | |
160 | await reRunServer(servers[0]) | |
161 | await wait(2000) | |
162 | ||
163 | { | |
164 | const res = await getVideosList(servers[0].url) | |
165 | expect(res.body.total).to.equal(2) | |
166 | } | |
167 | }) | |
168 | ||
8bff1fe0 C |
169 | after(async function () { |
170 | await cleanupTests(servers) | |
171 | }) | |
172 | }) |