aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/config.ts3
-rw-r--r--server/tests/api/check-params/follows.ts80
-rw-r--r--server/tests/api/server/config.ts5
-rw-r--r--server/tests/api/server/follows-moderation.ts83
4 files changed, 162 insertions, 9 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index d117f26e6..01ab84584 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -90,7 +90,8 @@ describe('Test config API validators', function () {
90 }, 90 },
91 followers: { 91 followers: {
92 instance: { 92 instance: {
93 enabled: false 93 enabled: false,
94 manualApproval: true
94 } 95 }
95 } 96 }
96 } 97 }
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 67fa43778..ed1d2db59 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -184,6 +184,86 @@ describe('Test server follows API validators', function () {
184 }) 184 })
185 }) 185 })
186 186
187 describe('When accepting a follower', function () {
188 const path = '/api/v1/server/followers'
189
190 it('Should fail with an invalid token', async function () {
191 await makePostBodyRequest({
192 url: server.url,
193 path: path + '/toto@localhost:9002/accept',
194 token: 'fake_token',
195 statusCodeExpected: 401
196 })
197 })
198
199 it('Should fail if the user is not an administrator', async function () {
200 await makePostBodyRequest({
201 url: server.url,
202 path: path + '/toto@localhost:9002/accept',
203 token: userAccessToken,
204 statusCodeExpected: 403
205 })
206 })
207
208 it('Should fail with an invalid follower', async function () {
209 await makePostBodyRequest({
210 url: server.url,
211 path: path + '/toto/accept',
212 token: server.accessToken,
213 statusCodeExpected: 400
214 })
215 })
216
217 it('Should fail with an unknown follower', async function () {
218 await makePostBodyRequest({
219 url: server.url,
220 path: path + '/toto@localhost:9003/accept',
221 token: server.accessToken,
222 statusCodeExpected: 404
223 })
224 })
225 })
226
227 describe('When rejecting a follower', function () {
228 const path = '/api/v1/server/followers'
229
230 it('Should fail with an invalid token', async function () {
231 await makePostBodyRequest({
232 url: server.url,
233 path: path + '/toto@localhost:9002/reject',
234 token: 'fake_token',
235 statusCodeExpected: 401
236 })
237 })
238
239 it('Should fail if the user is not an administrator', async function () {
240 await makePostBodyRequest({
241 url: server.url,
242 path: path + '/toto@localhost:9002/reject',
243 token: userAccessToken,
244 statusCodeExpected: 403
245 })
246 })
247
248 it('Should fail with an invalid follower', async function () {
249 await makePostBodyRequest({
250 url: server.url,
251 path: path + '/toto/reject',
252 token: server.accessToken,
253 statusCodeExpected: 400
254 })
255 })
256
257 it('Should fail with an unknown follower', async function () {
258 await makePostBodyRequest({
259 url: server.url,
260 path: path + '/toto@localhost:9003/reject',
261 token: server.accessToken,
262 statusCodeExpected: 404
263 })
264 })
265 })
266
187 describe('When removing following', function () { 267 describe('When removing following', function () {
188 const path = '/api/v1/server/following' 268 const path = '/api/v1/server/following'
189 269
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index cb2700f29..5373d02f2 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -65,6 +65,7 @@ function checkInitialConfig (data: CustomConfig) {
65 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false 65 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
66 66
67 expect(data.followers.instance.enabled).to.be.true 67 expect(data.followers.instance.enabled).to.be.true
68 expect(data.followers.instance.manualApproval).to.be.false
68} 69}
69 70
70function checkUpdatedConfig (data: CustomConfig) { 71function checkUpdatedConfig (data: CustomConfig) {
@@ -109,6 +110,7 @@ function checkUpdatedConfig (data: CustomConfig) {
109 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true 110 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
110 111
111 expect(data.followers.instance.enabled).to.be.false 112 expect(data.followers.instance.enabled).to.be.false
113 expect(data.followers.instance.manualApproval).to.be.true
112} 114}
113 115
114describe('Test config', function () { 116describe('Test config', function () {
@@ -241,7 +243,8 @@ describe('Test config', function () {
241 }, 243 },
242 followers: { 244 followers: {
243 instance: { 245 instance: {
244 enabled: false 246 enabled: false,
247 manualApproval: true
245 } 248 }
246 } 249 }
247 } 250 }
diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts
index a360706f2..0bb3aa866 100644
--- a/server/tests/api/server/follows-moderation.ts
+++ b/server/tests/api/server/follows-moderation.ts
@@ -3,6 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 acceptFollower,
6 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
7 killallServers, 8 killallServers,
8 ServerInfo, 9 ServerInfo,
@@ -13,19 +14,21 @@ import {
13 follow, 14 follow,
14 getFollowersListPaginationAndSort, 15 getFollowersListPaginationAndSort,
15 getFollowingListPaginationAndSort, 16 getFollowingListPaginationAndSort,
16 removeFollower 17 removeFollower,
18 rejectFollower
17} from '../../../../shared/utils/server/follows' 19} from '../../../../shared/utils/server/follows'
18import { waitJobs } from '../../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../../shared/utils/server/jobs'
19import { ActorFollow } from '../../../../shared/models/actors' 21import { ActorFollow } from '../../../../shared/models/actors'
20 22
21const expect = chai.expect 23const expect = chai.expect
22 24
23async function checkHasFollowers (servers: ServerInfo[]) { 25async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') {
24 { 26 {
25 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') 27 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
26 expect(res.body.total).to.equal(1) 28 expect(res.body.total).to.equal(1)
27 29
28 const follow = res.body.data[0] as ActorFollow 30 const follow = res.body.data[0] as ActorFollow
31 expect(follow.state).to.equal(state)
29 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') 32 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
30 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') 33 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
31 } 34 }
@@ -35,6 +38,7 @@ async function checkHasFollowers (servers: ServerInfo[]) {
35 expect(res.body.total).to.equal(1) 38 expect(res.body.total).to.equal(1)
36 39
37 const follow = res.body.data[0] as ActorFollow 40 const follow = res.body.data[0] as ActorFollow
41 expect(follow.state).to.equal(state)
38 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') 42 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
39 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') 43 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
40 } 44 }
@@ -58,7 +62,7 @@ describe('Test follows moderation', function () {
58 before(async function () { 62 before(async function () {
59 this.timeout(30000) 63 this.timeout(30000)
60 64
61 servers = await flushAndRunMultipleServers(2) 65 servers = await flushAndRunMultipleServers(3)
62 66
63 // Get the access tokens 67 // Get the access tokens
64 await setAccessTokensToServers(servers) 68 await setAccessTokensToServers(servers)
@@ -73,7 +77,7 @@ describe('Test follows moderation', function () {
73 }) 77 })
74 78
75 it('Should have correct follows', async function () { 79 it('Should have correct follows', async function () {
76 await checkHasFollowers(servers) 80 await checkServer1And2HasFollowers(servers)
77 }) 81 })
78 82
79 it('Should remove follower on server 2', async function () { 83 it('Should remove follower on server 2', async function () {
@@ -90,7 +94,8 @@ describe('Test follows moderation', function () {
90 const subConfig = { 94 const subConfig = {
91 followers: { 95 followers: {
92 instance: { 96 instance: {
93 enabled: false 97 enabled: false,
98 manualApproval: false
94 } 99 }
95 } 100 }
96 } 101 }
@@ -107,7 +112,8 @@ describe('Test follows moderation', function () {
107 const subConfig = { 112 const subConfig = {
108 followers: { 113 followers: {
109 instance: { 114 instance: {
110 enabled: true 115 enabled: true,
116 manualApproval: false
111 } 117 }
112 } 118 }
113 } 119 }
@@ -117,7 +123,70 @@ describe('Test follows moderation', function () {
117 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) 123 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
118 await waitJobs(servers) 124 await waitJobs(servers)
119 125
120 await checkHasFollowers(servers) 126 await checkServer1And2HasFollowers(servers)
127 })
128
129 it('Should manually approve followers', async function () {
130 this.timeout(20000)
131
132 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
133 await waitJobs(servers)
134
135 const subConfig = {
136 followers: {
137 instance: {
138 enabled: true,
139 manualApproval: true
140 }
141 }
142 }
143
144 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
145 await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig)
146
147 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
148 await waitJobs(servers)
149
150 await checkServer1And2HasFollowers(servers, 'pending')
151 })
152
153 it('Should accept a follower', async function () {
154 await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:9001')
155 await waitJobs(servers)
156
157 await checkServer1And2HasFollowers(servers)
158 })
159
160 it('Should reject another follower', async function () {
161 this.timeout(20000)
162
163 await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
164 await waitJobs(servers)
165
166 {
167 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
168 expect(res.body.total).to.equal(2)
169 }
170
171 {
172 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
173 expect(res.body.total).to.equal(1)
174 }
175
176 {
177 const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 5, 'createdAt')
178 expect(res.body.total).to.equal(1)
179 }
180
181 await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:9001')
182 await waitJobs(servers)
183
184 await checkServer1And2HasFollowers(servers)
185
186 {
187 const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt')
188 expect(res.body.total).to.equal(0)
189 }
121 }) 190 })
122 191
123 after(async function () { 192 after(async function () {