]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | acceptFollower, | |
7 | cleanupTests, | |
8 | flushAndRunMultipleServers, | |
9 | ServerInfo, | |
10 | setAccessTokensToServers, | |
11 | updateCustomSubConfig | |
12 | } from '../../../../shared/extra-utils/index' | |
13 | import { | |
14 | follow, | |
15 | getFollowersListPaginationAndSort, | |
16 | getFollowingListPaginationAndSort, | |
17 | rejectFollower, | |
18 | removeFollower | |
19 | } from '../../../../shared/extra-utils/server/follows' | |
20 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
21 | import { ActorFollow } from '../../../../shared/models/actors' | |
22 | ||
23 | const expect = chai.expect | |
24 | ||
25 | async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') { | |
26 | { | |
27 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) | |
28 | expect(res.body.total).to.equal(1) | |
29 | ||
30 | const follow = res.body.data[0] as ActorFollow | |
31 | expect(follow.state).to.equal(state) | |
32 | expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') | |
33 | expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') | |
34 | } | |
35 | ||
36 | { | |
37 | const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' }) | |
38 | expect(res.body.total).to.equal(1) | |
39 | ||
40 | const follow = res.body.data[0] as ActorFollow | |
41 | expect(follow.state).to.equal(state) | |
42 | expect(follow.follower.url).to.equal('http://localhost:' + servers[0].port + '/accounts/peertube') | |
43 | expect(follow.following.url).to.equal('http://localhost:' + servers[1].port + '/accounts/peertube') | |
44 | } | |
45 | } | |
46 | ||
47 | async function checkNoFollowers (servers: ServerInfo[]) { | |
48 | { | |
49 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) | |
50 | expect(res.body.total).to.equal(0) | |
51 | } | |
52 | ||
53 | { | |
54 | const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' }) | |
55 | expect(res.body.total).to.equal(0) | |
56 | } | |
57 | } | |
58 | ||
59 | describe('Test follows moderation', function () { | |
60 | let servers: ServerInfo[] = [] | |
61 | ||
62 | before(async function () { | |
63 | this.timeout(30000) | |
64 | ||
65 | servers = await flushAndRunMultipleServers(3) | |
66 | ||
67 | // Get the access tokens | |
68 | await setAccessTokensToServers(servers) | |
69 | }) | |
70 | ||
71 | it('Should have server 1 following server 2', async function () { | |
72 | this.timeout(30000) | |
73 | ||
74 | await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) | |
75 | ||
76 | await waitJobs(servers) | |
77 | }) | |
78 | ||
79 | it('Should have correct follows', async function () { | |
80 | await checkServer1And2HasFollowers(servers) | |
81 | }) | |
82 | ||
83 | it('Should remove follower on server 2', async function () { | |
84 | this.timeout(10000) | |
85 | ||
86 | await removeFollower(servers[1].url, servers[1].accessToken, servers[0]) | |
87 | ||
88 | await waitJobs(servers) | |
89 | }) | |
90 | ||
91 | it('Should not not have follows anymore', async function () { | |
92 | await checkNoFollowers(servers) | |
93 | }) | |
94 | ||
95 | it('Should disable followers on server 2', async function () { | |
96 | this.timeout(10000) | |
97 | ||
98 | const subConfig = { | |
99 | followers: { | |
100 | instance: { | |
101 | enabled: false, | |
102 | manualApproval: false | |
103 | } | |
104 | } | |
105 | } | |
106 | ||
107 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
108 | ||
109 | await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) | |
110 | await waitJobs(servers) | |
111 | ||
112 | await checkNoFollowers(servers) | |
113 | }) | |
114 | ||
115 | it('Should re enable followers on server 2', async function () { | |
116 | this.timeout(10000) | |
117 | ||
118 | const subConfig = { | |
119 | followers: { | |
120 | instance: { | |
121 | enabled: true, | |
122 | manualApproval: false | |
123 | } | |
124 | } | |
125 | } | |
126 | ||
127 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
128 | ||
129 | await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) | |
130 | await waitJobs(servers) | |
131 | ||
132 | await checkServer1And2HasFollowers(servers) | |
133 | }) | |
134 | ||
135 | it('Should manually approve followers', async function () { | |
136 | this.timeout(20000) | |
137 | ||
138 | await removeFollower(servers[1].url, servers[1].accessToken, servers[0]) | |
139 | await waitJobs(servers) | |
140 | ||
141 | const subConfig = { | |
142 | followers: { | |
143 | instance: { | |
144 | enabled: true, | |
145 | manualApproval: true | |
146 | } | |
147 | } | |
148 | } | |
149 | ||
150 | await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig) | |
151 | await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig) | |
152 | ||
153 | await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) | |
154 | await waitJobs(servers) | |
155 | ||
156 | await checkServer1And2HasFollowers(servers, 'pending') | |
157 | }) | |
158 | ||
159 | it('Should accept a follower', async function () { | |
160 | this.timeout(10000) | |
161 | ||
162 | await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:' + servers[0].port) | |
163 | await waitJobs(servers) | |
164 | ||
165 | await checkServer1And2HasFollowers(servers) | |
166 | }) | |
167 | ||
168 | it('Should reject another follower', async function () { | |
169 | this.timeout(20000) | |
170 | ||
171 | await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) | |
172 | await waitJobs(servers) | |
173 | ||
174 | { | |
175 | const res = await getFollowingListPaginationAndSort({ url: servers[0].url, start: 0, count: 5, sort: 'createdAt' }) | |
176 | expect(res.body.total).to.equal(2) | |
177 | } | |
178 | ||
179 | { | |
180 | const res = await getFollowersListPaginationAndSort({ url: servers[1].url, start: 0, count: 5, sort: 'createdAt' }) | |
181 | expect(res.body.total).to.equal(1) | |
182 | } | |
183 | ||
184 | { | |
185 | const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' }) | |
186 | expect(res.body.total).to.equal(1) | |
187 | } | |
188 | ||
189 | await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:' + servers[0].port) | |
190 | await waitJobs(servers) | |
191 | ||
192 | await checkServer1And2HasFollowers(servers) | |
193 | ||
194 | { | |
195 | const res = await getFollowersListPaginationAndSort({ url: servers[2].url, start: 0, count: 5, sort: 'createdAt' }) | |
196 | expect(res.body.total).to.equal(0) | |
197 | } | |
198 | }) | |
199 | ||
200 | after(async function () { | |
201 | await cleanupTests(servers) | |
202 | }) | |
203 | }) |