]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/follow-constraints.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / follow-constraints.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import { expect } from 'chai'
4 import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
5 import {
6 cleanupTests,
7 createMultipleServers,
8 doubleFollow,
9 PeerTubeServer,
10 setAccessTokensToServers,
11 waitJobs
12 } from '@shared/server-commands'
13
14 describe('Test follow constraints', function () {
15 let servers: PeerTubeServer[] = []
16 let video1UUID: string
17 let video2UUID: string
18 let userToken: string
19
20 before(async function () {
21 this.timeout(240000)
22
23 servers = await createMultipleServers(2)
24
25 // Get the access tokens
26 await setAccessTokensToServers(servers)
27
28 {
29 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
30 video1UUID = uuid
31 }
32 {
33 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
34 video2UUID = uuid
35 }
36
37 const user = {
38 username: 'user1',
39 password: 'super_password'
40 }
41 await servers[0].users.create({ username: user.username, password: user.password })
42 userToken = await servers[0].login.getAccessToken(user)
43
44 await doubleFollow(servers[0], servers[1])
45 })
46
47 describe('With a followed instance', function () {
48
49 describe('With an unlogged user', function () {
50
51 it('Should get the local video', async function () {
52 await servers[0].videos.get({ id: video1UUID })
53 })
54
55 it('Should get the remote video', async function () {
56 await servers[0].videos.get({ id: video2UUID })
57 })
58
59 it('Should list local account videos', async function () {
60 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@' + servers[0].host })
61
62 expect(total).to.equal(1)
63 expect(data).to.have.lengthOf(1)
64 })
65
66 it('Should list remote account videos', async function () {
67 const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@' + servers[1].host })
68
69 expect(total).to.equal(1)
70 expect(data).to.have.lengthOf(1)
71 })
72
73 it('Should list local channel videos', async function () {
74 const handle = 'root_channel@' + servers[0].host
75 const { total, data } = await servers[0].videos.listByChannel({ handle })
76
77 expect(total).to.equal(1)
78 expect(data).to.have.lengthOf(1)
79 })
80
81 it('Should list remote channel videos', async function () {
82 const handle = 'root_channel@' + servers[1].host
83 const { total, data } = await servers[0].videos.listByChannel({ handle })
84
85 expect(total).to.equal(1)
86 expect(data).to.have.lengthOf(1)
87 })
88 })
89
90 describe('With a logged user', function () {
91 it('Should get the local video', async function () {
92 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
93 })
94
95 it('Should get the remote video', async function () {
96 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
97 })
98
99 it('Should list local account videos', async function () {
100 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[0].host })
101
102 expect(total).to.equal(1)
103 expect(data).to.have.lengthOf(1)
104 })
105
106 it('Should list remote account videos', async function () {
107 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[1].host })
108
109 expect(total).to.equal(1)
110 expect(data).to.have.lengthOf(1)
111 })
112
113 it('Should list local channel videos', async function () {
114 const handle = 'root_channel@' + servers[0].host
115 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
116
117 expect(total).to.equal(1)
118 expect(data).to.have.lengthOf(1)
119 })
120
121 it('Should list remote channel videos', async function () {
122 const handle = 'root_channel@' + servers[1].host
123 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
124
125 expect(total).to.equal(1)
126 expect(data).to.have.lengthOf(1)
127 })
128 })
129 })
130
131 describe('With a non followed instance', function () {
132
133 before(async function () {
134 this.timeout(30000)
135
136 await servers[0].follows.unfollow({ target: servers[1] })
137 })
138
139 describe('With an unlogged user', function () {
140
141 it('Should get the local video', async function () {
142 await servers[0].videos.get({ id: video1UUID })
143 })
144
145 it('Should not get the remote video', async function () {
146 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
147 const error = body as unknown as PeerTubeProblemDocument
148
149 const doc = 'https://docs.joinpeertube.org/api/rest-reference.html#section/Errors/does_not_respect_follow_constraints'
150 expect(error.type).to.equal(doc)
151 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
152
153 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
154 expect(error.error).to.equal(error.detail)
155
156 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
157
158 expect(error.originUrl).to.contains(servers[1].url)
159 })
160
161 it('Should list local account videos', async function () {
162 const { total, data } = await servers[0].videos.listByAccount({
163 token: null,
164 handle: 'root@' + servers[0].host
165 })
166
167 expect(total).to.equal(1)
168 expect(data).to.have.lengthOf(1)
169 })
170
171 it('Should not list remote account videos', async function () {
172 const { total, data } = await servers[0].videos.listByAccount({
173 token: null,
174 handle: 'root@' + servers[1].host
175 })
176
177 expect(total).to.equal(0)
178 expect(data).to.have.lengthOf(0)
179 })
180
181 it('Should list local channel videos', async function () {
182 const handle = 'root_channel@' + servers[0].host
183 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
184
185 expect(total).to.equal(1)
186 expect(data).to.have.lengthOf(1)
187 })
188
189 it('Should not list remote channel videos', async function () {
190 const handle = 'root_channel@' + servers[1].host
191 const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
192
193 expect(total).to.equal(0)
194 expect(data).to.have.lengthOf(0)
195 })
196 })
197
198 describe('With a logged user', function () {
199
200 it('Should get the local video', async function () {
201 await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
202 })
203
204 it('Should get the remote video', async function () {
205 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
206 })
207
208 it('Should list local account videos', async function () {
209 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[0].host })
210
211 expect(total).to.equal(1)
212 expect(data).to.have.lengthOf(1)
213 })
214
215 it('Should list remote account videos', async function () {
216 const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@' + servers[1].host })
217
218 expect(total).to.equal(1)
219 expect(data).to.have.lengthOf(1)
220 })
221
222 it('Should list local channel videos', async function () {
223 const handle = 'root_channel@' + servers[0].host
224 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
225
226 expect(total).to.equal(1)
227 expect(data).to.have.lengthOf(1)
228 })
229
230 it('Should list remote channel videos', async function () {
231 const handle = 'root_channel@' + servers[1].host
232 const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
233
234 expect(total).to.equal(1)
235 expect(data).to.have.lengthOf(1)
236 })
237 })
238 })
239
240 describe('When following a remote account', function () {
241
242 before(async function () {
243 this.timeout(60000)
244
245 await servers[0].follows.follow({ handles: [ 'root@' + servers[1].host ] })
246 await waitJobs(servers)
247 })
248
249 it('Should get the remote video with an unlogged user', async function () {
250 await servers[0].videos.get({ id: video2UUID })
251 })
252
253 it('Should get the remote video with a logged in user', async function () {
254 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
255 })
256 })
257
258 describe('When unfollowing a remote account', function () {
259
260 before(async function () {
261 this.timeout(60000)
262
263 await servers[0].follows.unfollow({ target: 'root@' + servers[1].host })
264 await waitJobs(servers)
265 })
266
267 it('Should not get the remote video with an unlogged user', async function () {
268 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
269
270 const error = body as unknown as PeerTubeProblemDocument
271 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
272 })
273
274 it('Should get the remote video with a logged in user', async function () {
275 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
276 })
277 })
278
279 describe('When following a remote channel', function () {
280
281 before(async function () {
282 this.timeout(60000)
283
284 await servers[0].follows.follow({ handles: [ 'root_channel@' + servers[1].host ] })
285 await waitJobs(servers)
286 })
287
288 it('Should get the remote video with an unlogged user', async function () {
289 await servers[0].videos.get({ id: video2UUID })
290 })
291
292 it('Should get the remote video with a logged in user', async function () {
293 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
294 })
295 })
296
297 describe('When unfollowing a remote channel', function () {
298
299 before(async function () {
300 this.timeout(60000)
301
302 await servers[0].follows.unfollow({ target: 'root_channel@' + servers[1].host })
303 await waitJobs(servers)
304 })
305
306 it('Should not get the remote video with an unlogged user', async function () {
307 const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
308
309 const error = body as unknown as PeerTubeProblemDocument
310 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
311 })
312
313 it('Should get the remote video with a logged in user', async function () {
314 await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
315 })
316 })
317
318 after(async function () {
319 await cleanupTests(servers)
320 })
321 })