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