aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-08 14:04:57 +0200
committerChocobozzz <me@florianbigard.com>2019-04-08 14:06:23 +0200
commit5b9c965d5aa747f29b081289f930ee215fdc23c8 (patch)
tree1c726117525230d74235e7fa986eb72e7376fb6c /server/tests/api
parent594d0c6a7c64b045c11508bb4e4b19b75b3fc557 (diff)
downloadPeerTube-5b9c965d5aa747f29b081289f930ee215fdc23c8.tar.gz
PeerTube-5b9c965d5aa747f29b081289f930ee215fdc23c8.tar.zst
PeerTube-5b9c965d5aa747f29b081289f930ee215fdc23c8.zip
Add ability to forbid followers
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/config.ts5
-rw-r--r--server/tests/api/check-params/follows.ts40
-rw-r--r--server/tests/api/server/config.ts9
-rw-r--r--server/tests/api/server/follows-moderation.ts96
4 files changed, 126 insertions, 24 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 0b333e2f4..d117f26e6 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -87,6 +87,11 @@ describe('Test config API validators', function () {
87 enabled: false 87 enabled: false
88 } 88 }
89 } 89 }
90 },
91 followers: {
92 instance: {
93 enabled: false
94 }
90 } 95 }
91 } 96 }
92 97
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 2ad1575a3..67fa43778 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -144,6 +144,46 @@ describe('Test server follows API validators', function () {
144 }) 144 })
145 }) 145 })
146 146
147 describe('When removing a follower', function () {
148 const path = '/api/v1/server/followers'
149
150 it('Should fail with an invalid token', async function () {
151 await makeDeleteRequest({
152 url: server.url,
153 path: path + '/toto@localhost:9002',
154 token: 'fake_token',
155 statusCodeExpected: 401
156 })
157 })
158
159 it('Should fail if the user is not an administrator', async function () {
160 await makeDeleteRequest({
161 url: server.url,
162 path: path + '/toto@localhost:9002',
163 token: userAccessToken,
164 statusCodeExpected: 403
165 })
166 })
167
168 it('Should fail with an invalid follower', async function () {
169 await makeDeleteRequest({
170 url: server.url,
171 path: path + '/toto',
172 token: server.accessToken,
173 statusCodeExpected: 400
174 })
175 })
176
177 it('Should fail with an unknown follower', async function () {
178 await makeDeleteRequest({
179 url: server.url,
180 path: path + '/toto@localhost:9003',
181 token: server.accessToken,
182 statusCodeExpected: 404
183 })
184 })
185 })
186
147 describe('When removing following', function () { 187 describe('When removing following', function () {
148 const path = '/api/v1/server/following' 188 const path = '/api/v1/server/following'
149 189
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index b9f05e952..cb2700f29 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -63,6 +63,8 @@ function checkInitialConfig (data: CustomConfig) {
63 expect(data.import.videos.http.enabled).to.be.true 63 expect(data.import.videos.http.enabled).to.be.true
64 expect(data.import.videos.torrent.enabled).to.be.true 64 expect(data.import.videos.torrent.enabled).to.be.true
65 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false 65 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
66
67 expect(data.followers.instance.enabled).to.be.true
66} 68}
67 69
68function checkUpdatedConfig (data: CustomConfig) { 70function checkUpdatedConfig (data: CustomConfig) {
@@ -105,6 +107,8 @@ function checkUpdatedConfig (data: CustomConfig) {
105 expect(data.import.videos.http.enabled).to.be.false 107 expect(data.import.videos.http.enabled).to.be.false
106 expect(data.import.videos.torrent.enabled).to.be.false 108 expect(data.import.videos.torrent.enabled).to.be.false
107 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true 109 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
110
111 expect(data.followers.instance.enabled).to.be.false
108} 112}
109 113
110describe('Test config', function () { 114describe('Test config', function () {
@@ -234,6 +238,11 @@ describe('Test config', function () {
234 enabled: true 238 enabled: true
235 } 239 }
236 } 240 }
241 },
242 followers: {
243 instance: {
244 enabled: false
245 }
237 } 246 }
238 } 247 }
239 await updateCustomConfig(server.url, server.accessToken, newCustomConfig) 248 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts
index b1cbfb62c..a360706f2 100644
--- a/server/tests/api/server/follows-moderation.ts
+++ b/server/tests/api/server/follows-moderation.ts
@@ -2,7 +2,13 @@
2 2
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { flushAndRunMultipleServers, killallServers, ServerInfo, setAccessTokensToServers } from '../../../../shared/utils/index' 5import {
6 flushAndRunMultipleServers,
7 killallServers,
8 ServerInfo,
9 setAccessTokensToServers,
10 updateCustomSubConfig
11} from '../../../../shared/utils/index'
6import { 12import {
7 follow, 13 follow,
8 getFollowersListPaginationAndSort, 14 getFollowersListPaginationAndSort,
@@ -14,6 +20,38 @@ import { ActorFollow } from '../../../../shared/models/actors'
14 20
15const expect = chai.expect 21const expect = chai.expect
16 22
23async function checkHasFollowers (servers: ServerInfo[]) {
24 {
25 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
26 expect(res.body.total).to.equal(1)
27
28 const follow = res.body.data[0] as ActorFollow
29 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
30 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
31 }
32
33 {
34 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
35 expect(res.body.total).to.equal(1)
36
37 const follow = res.body.data[0] as ActorFollow
38 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
39 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
40 }
41}
42
43async function checkNoFollowers (servers: ServerInfo[]) {
44 {
45 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 5, 'createdAt')
46 expect(res.body.total).to.equal(0)
47 }
48
49 {
50 const res = await getFollowersListPaginationAndSort(servers[ 1 ].url, 0, 5, 'createdAt')
51 expect(res.body.total).to.equal(0)
52 }
53}
54
17describe('Test follows moderation', function () { 55describe('Test follows moderation', function () {
18 let servers: ServerInfo[] = [] 56 let servers: ServerInfo[] = []
19 57
@@ -35,23 +73,7 @@ describe('Test follows moderation', function () {
35 }) 73 })
36 74
37 it('Should have correct follows', async function () { 75 it('Should have correct follows', async function () {
38 { 76 await checkHasFollowers(servers)
39 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
40 expect(res.body.total).to.equal(1)
41
42 const follow = res.body.data[0] as ActorFollow
43 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
44 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
45 }
46
47 {
48 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
49 expect(res.body.total).to.equal(1)
50
51 const follow = res.body.data[0] as ActorFollow
52 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
53 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
54 }
55 }) 77 })
56 78
57 it('Should remove follower on server 2', async function () { 79 it('Should remove follower on server 2', async function () {
@@ -61,15 +83,41 @@ describe('Test follows moderation', function () {
61 }) 83 })
62 84
63 it('Should not not have follows anymore', async function () { 85 it('Should not not have follows anymore', async function () {
64 { 86 await checkNoFollowers(servers)
65 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt') 87 })
66 expect(res.body.total).to.equal(0) 88
89 it('Should disable followers on server 2', async function () {
90 const subConfig = {
91 followers: {
92 instance: {
93 enabled: false
94 }
95 }
67 } 96 }
68 97
69 { 98 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
70 const res = await getFollowingListPaginationAndSort(servers[ 0 ].url, 0, 1, 'createdAt') 99
71 expect(res.body.total).to.equal(0) 100 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
101 await waitJobs(servers)
102
103 await checkNoFollowers(servers)
104 })
105
106 it('Should re enable followers on server 2', async function () {
107 const subConfig = {
108 followers: {
109 instance: {
110 enabled: true
111 }
112 }
72 } 113 }
114
115 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
116
117 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
118 await waitJobs(servers)
119
120 await checkHasFollowers(servers)
73 }) 121 })
74 122
75 after(async function () { 123 after(async function () {