diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/server/follows-moderation.ts | 184 |
1 files changed, 171 insertions, 13 deletions
diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index 120bd7f88..a0e94c10e 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts | |||
@@ -2,6 +2,8 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { expectStartWith } from '@server/tests/shared' | ||
6 | import { ActorFollow, FollowState } from '@shared/models' | ||
5 | import { | 7 | import { |
6 | cleanupTests, | 8 | cleanupTests, |
7 | createMultipleServers, | 9 | createMultipleServers, |
@@ -25,8 +27,51 @@ async function checkServer1And2HasFollowers (servers: PeerTubeServer[], state = | |||
25 | 27 | ||
26 | const follow = body.data[0] | 28 | const follow = body.data[0] |
27 | expect(follow.state).to.equal(state) | 29 | expect(follow.state).to.equal(state) |
28 | expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') | 30 | expect(follow.follower.url).to.equal(servers[0].url + '/accounts/peertube') |
29 | expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') | 31 | expect(follow.following.url).to.equal(servers[1].url + '/accounts/peertube') |
32 | } | ||
33 | } | ||
34 | |||
35 | async function checkFollows (options: { | ||
36 | follower: { | ||
37 | server: PeerTubeServer | ||
38 | state?: FollowState // if not provided, it means it does not exist | ||
39 | } | ||
40 | following: { | ||
41 | server: PeerTubeServer | ||
42 | state?: FollowState // if not provided, it means it does not exist | ||
43 | } | ||
44 | }) { | ||
45 | const { follower, following } = options | ||
46 | |||
47 | const followerUrl = follower.server.url + '/accounts/peertube' | ||
48 | const followingUrl = following.server.url + '/accounts/peertube' | ||
49 | const finder = (d: ActorFollow) => d.follower.url === followerUrl && d.following.url === followingUrl | ||
50 | |||
51 | { | ||
52 | const { data } = await follower.server.follows.getFollowings() | ||
53 | const follow = data.find(finder) | ||
54 | |||
55 | if (!follower.state) { | ||
56 | expect(follow).to.not.exist | ||
57 | } else { | ||
58 | expect(follow.state).to.equal(follower.state) | ||
59 | expect(follow.follower.url).to.equal(followerUrl) | ||
60 | expect(follow.following.url).to.equal(followingUrl) | ||
61 | } | ||
62 | } | ||
63 | |||
64 | { | ||
65 | const { data } = await following.server.follows.getFollowers() | ||
66 | const follow = data.find(finder) | ||
67 | |||
68 | if (!following.state) { | ||
69 | expect(follow).to.not.exist | ||
70 | } else { | ||
71 | expect(follow.state).to.equal(following.state) | ||
72 | expect(follow.follower.url).to.equal(followerUrl) | ||
73 | expect(follow.following.url).to.equal(followingUrl) | ||
74 | } | ||
30 | } | 75 | } |
31 | } | 76 | } |
32 | 77 | ||
@@ -37,7 +82,7 @@ async function checkNoFollowers (servers: PeerTubeServer[]) { | |||
37 | ] | 82 | ] |
38 | 83 | ||
39 | for (const fn of fns) { | 84 | for (const fn of fns) { |
40 | const body = await fn({ start: 0, count: 5, sort: 'createdAt' }) | 85 | const body = await fn({ start: 0, count: 5, sort: 'createdAt', state: 'accepted' }) |
41 | expect(body.total).to.equal(0) | 86 | expect(body.total).to.equal(0) |
42 | } | 87 | } |
43 | } | 88 | } |
@@ -124,7 +169,7 @@ describe('Test follows moderation', function () { | |||
124 | it('Should manually approve followers', async function () { | 169 | it('Should manually approve followers', async function () { |
125 | this.timeout(20000) | 170 | this.timeout(20000) |
126 | 171 | ||
127 | await commands[1].removeFollower({ follower: servers[0] }) | 172 | await commands[0].unfollow({ target: servers[1] }) |
128 | await waitJobs(servers) | 173 | await waitJobs(servers) |
129 | 174 | ||
130 | const subConfig = { | 175 | const subConfig = { |
@@ -148,7 +193,7 @@ describe('Test follows moderation', function () { | |||
148 | it('Should accept a follower', async function () { | 193 | it('Should accept a follower', async function () { |
149 | this.timeout(10000) | 194 | this.timeout(10000) |
150 | 195 | ||
151 | await commands[1].acceptFollower({ follower: 'peertube@localhost:' + servers[0].port }) | 196 | await commands[1].acceptFollower({ follower: 'peertube@' + servers[0].host }) |
152 | await waitJobs(servers) | 197 | await waitJobs(servers) |
153 | 198 | ||
154 | await checkServer1And2HasFollowers(servers) | 199 | await checkServer1And2HasFollowers(servers) |
@@ -161,31 +206,144 @@ describe('Test follows moderation', function () { | |||
161 | await waitJobs(servers) | 206 | await waitJobs(servers) |
162 | 207 | ||
163 | { | 208 | { |
164 | const body = await commands[0].getFollowings({ start: 0, count: 5, sort: 'createdAt' }) | 209 | const body = await commands[0].getFollowings() |
165 | expect(body.total).to.equal(2) | 210 | expect(body.total).to.equal(2) |
166 | } | 211 | } |
167 | 212 | ||
168 | { | 213 | { |
169 | const body = await commands[1].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) | 214 | const body = await commands[1].getFollowers() |
170 | expect(body.total).to.equal(1) | 215 | expect(body.total).to.equal(1) |
171 | } | 216 | } |
172 | 217 | ||
173 | { | 218 | { |
174 | const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) | 219 | const body = await commands[2].getFollowers() |
175 | expect(body.total).to.equal(1) | 220 | expect(body.total).to.equal(1) |
176 | } | 221 | } |
177 | 222 | ||
178 | await commands[2].rejectFollower({ follower: 'peertube@localhost:' + servers[0].port }) | 223 | await commands[2].rejectFollower({ follower: 'peertube@' + servers[0].host }) |
179 | await waitJobs(servers) | 224 | await waitJobs(servers) |
180 | 225 | ||
181 | await checkServer1And2HasFollowers(servers) | 226 | { // server 1 |
227 | { | ||
228 | const { data } = await commands[0].getFollowings({ state: 'accepted' }) | ||
229 | expect(data).to.have.lengthOf(1) | ||
230 | } | ||
182 | 231 | ||
183 | { | 232 | { |
184 | const body = await commands[2].getFollowers({ start: 0, count: 5, sort: 'createdAt' }) | 233 | const { data } = await commands[0].getFollowings({ state: 'rejected' }) |
185 | expect(body.total).to.equal(0) | 234 | expect(data).to.have.lengthOf(1) |
235 | expectStartWith(data[0].following.url, servers[2].url) | ||
236 | } | ||
237 | } | ||
238 | |||
239 | { // server 3 | ||
240 | { | ||
241 | const { data } = await commands[2].getFollowers({ state: 'accepted' }) | ||
242 | expect(data).to.have.lengthOf(0) | ||
243 | } | ||
244 | |||
245 | { | ||
246 | const { data } = await commands[2].getFollowers({ state: 'rejected' }) | ||
247 | expect(data).to.have.lengthOf(1) | ||
248 | expectStartWith(data[0].follower.url, servers[0].url) | ||
249 | } | ||
186 | } | 250 | } |
187 | }) | 251 | }) |
188 | 252 | ||
253 | it('Should not change the follow on refollow with and without auto accept', async function () { | ||
254 | const run = async () => { | ||
255 | await commands[0].follow({ hosts: [ servers[2].url ] }) | ||
256 | await waitJobs(servers) | ||
257 | |||
258 | await checkFollows({ | ||
259 | follower: { | ||
260 | server: servers[0], | ||
261 | state: 'rejected' | ||
262 | }, | ||
263 | following: { | ||
264 | server: servers[2], | ||
265 | state: 'rejected' | ||
266 | } | ||
267 | }) | ||
268 | } | ||
269 | |||
270 | await servers[2].config.updateExistingSubConfig({ newConfig: { followers: { instance: { manualApproval: false } } } }) | ||
271 | await run() | ||
272 | |||
273 | await servers[2].config.updateExistingSubConfig({ newConfig: { followers: { instance: { manualApproval: true } } } }) | ||
274 | await run() | ||
275 | }) | ||
276 | |||
277 | it('Should not change the rejected status on unfollow', async function () { | ||
278 | await commands[0].unfollow({ target: servers[2] }) | ||
279 | await waitJobs(servers) | ||
280 | |||
281 | await checkFollows({ | ||
282 | follower: { | ||
283 | server: servers[0] | ||
284 | }, | ||
285 | following: { | ||
286 | server: servers[2], | ||
287 | state: 'rejected' | ||
288 | } | ||
289 | }) | ||
290 | }) | ||
291 | |||
292 | it('Should delete the follower and add again the follower', async function () { | ||
293 | await commands[2].removeFollower({ follower: servers[0] }) | ||
294 | await waitJobs(servers) | ||
295 | |||
296 | await commands[0].follow({ hosts: [ servers[2].url ] }) | ||
297 | await waitJobs(servers) | ||
298 | |||
299 | await checkFollows({ | ||
300 | follower: { | ||
301 | server: servers[0], | ||
302 | state: 'pending' | ||
303 | }, | ||
304 | following: { | ||
305 | server: servers[2], | ||
306 | state: 'pending' | ||
307 | } | ||
308 | }) | ||
309 | }) | ||
310 | |||
311 | it('Should be able to reject a previously accepted follower', async function () { | ||
312 | await commands[1].rejectFollower({ follower: 'peertube@' + servers[0].host }) | ||
313 | await waitJobs(servers) | ||
314 | |||
315 | await checkFollows({ | ||
316 | follower: { | ||
317 | server: servers[0], | ||
318 | state: 'rejected' | ||
319 | }, | ||
320 | following: { | ||
321 | server: servers[1], | ||
322 | state: 'rejected' | ||
323 | } | ||
324 | }) | ||
325 | }) | ||
326 | |||
327 | it('Should be able to re accept a previously rejected follower', async function () { | ||
328 | await commands[1].acceptFollower({ follower: 'peertube@' + servers[0].host }) | ||
329 | await waitJobs(servers) | ||
330 | |||
331 | await checkFollows({ | ||
332 | follower: { | ||
333 | server: servers[0], | ||
334 | state: 'accepted' | ||
335 | }, | ||
336 | following: { | ||
337 | server: servers[1], | ||
338 | state: 'accepted' | ||
339 | } | ||
340 | }) | ||
341 | }) | ||
342 | |||
343 | it('Should ignore follow requests of muted servers', async function () { | ||
344 | |||
345 | }) | ||
346 | |||
189 | after(async function () { | 347 | after(async function () { |
190 | await cleanupTests(servers) | 348 | await cleanupTests(servers) |
191 | }) | 349 | }) |