aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-08-13 15:07:23 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commitafff310e50f2fa8419bb4242470cbde46ab54463 (patch)
tree34efda2daf8f7cdfd89ef6616a79e2222082f93a /server/tests
parentf619de0e435f7ac3abad2ec772397486358b56e7 (diff)
downloadPeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.gz
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.tar.zst
PeerTube-afff310e50f2fa8419bb4242470cbde46ab54463.zip
allow private syndication feeds via a user feedToken
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/feeds/feeds.ts91
1 files changed, 90 insertions, 1 deletions
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 0ff690f34..2cd9b2d0a 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -22,11 +22,14 @@ import {
22 uploadVideo, 22 uploadVideo,
23 uploadVideoAndGetId, 23 uploadVideoAndGetId,
24 userLogin, 24 userLogin,
25 flushAndRunServer 25 flushAndRunServer,
26 getUserScopedTokens
26} from '../../../shared/extra-utils' 27} from '../../../shared/extra-utils'
27import { waitJobs } from '../../../shared/extra-utils/server/jobs' 28import { waitJobs } from '../../../shared/extra-utils/server/jobs'
28import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' 29import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
29import { User } from '../../../shared/models/users' 30import { User } from '../../../shared/models/users'
31import { ScopedToken } from '@shared/models/users/user-scoped-token'
32import { listUserSubscriptionVideos, addUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
30 33
31chai.use(require('chai-xml')) 34chai.use(require('chai-xml'))
32chai.use(require('chai-json-schema')) 35chai.use(require('chai-json-schema'))
@@ -41,6 +44,7 @@ describe('Test syndication feeds', () => {
41 let rootChannelId: number 44 let rootChannelId: number
42 let userAccountId: number 45 let userAccountId: number
43 let userChannelId: number 46 let userChannelId: number
47 let userFeedToken: string
44 48
45 before(async function () { 49 before(async function () {
46 this.timeout(120000) 50 this.timeout(120000)
@@ -74,6 +78,10 @@ describe('Test syndication feeds', () => {
74 const user: User = res.body 78 const user: User = res.body
75 userAccountId = user.account.id 79 userAccountId = user.account.id
76 userChannelId = user.videoChannels[0].id 80 userChannelId = user.videoChannels[0].id
81
82 const res2 = await getUserScopedTokens(servers[0].url, userAccessToken)
83 const token: ScopedToken = res2.body
84 userFeedToken = token.feedToken
77 } 85 }
78 86
79 { 87 {
@@ -289,6 +297,87 @@ describe('Test syndication feeds', () => {
289 }) 297 })
290 }) 298 })
291 299
300 describe('Video feed from my subscriptions', function () {
301 /**
302 * use the 'version' query parameter to bust cache between tests
303 */
304
305 it('Should list no videos for a user with no videos and no subscriptions', async function () {
306 let feeduserAccountId: number
307 let feeduserFeedToken: string
308
309 const attr = { username: 'feeduser', password: 'password' }
310 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
311 const feeduserAccessToken = await userLogin(servers[0], attr)
312
313 {
314 const res = await getMyUserInformation(servers[0].url, feeduserAccessToken)
315 const user: User = res.body
316 feeduserAccountId = user.account.id
317 }
318
319 {
320 const res = await getUserScopedTokens(servers[0].url, feeduserAccessToken)
321 const token: ScopedToken = res.body
322 feeduserFeedToken = token.feedToken
323 }
324
325 {
326 const res = await listUserSubscriptionVideos(servers[0].url, feeduserAccessToken)
327 expect(res.body.total).to.equal(0)
328
329 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: feeduserAccountId, token: feeduserFeedToken })
330 const jsonObj = JSON.parse(json.text)
331 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
332 }
333 })
334
335 it('Should list no videos for a user with videos but no subscriptions', async function () {
336 {
337 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
338 expect(res.body.total).to.equal(0)
339
340 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId, token: userFeedToken })
341 const jsonObj = JSON.parse(json.text)
342 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
343 }
344 })
345
346 it('Should list self videos for a user with a subscription to themselves', async function () {
347 this.timeout(30000)
348
349 await addUserSubscription(servers[0].url, userAccessToken, 'john_channel@localhost:' + servers[0].port)
350 await waitJobs(servers)
351
352 {
353 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
354 expect(res.body.total).to.equal(1)
355 expect(res.body.data[0].name).to.equal('user video')
356
357 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId, token: userFeedToken, version: 1 })
358 const jsonObj = JSON.parse(json.text)
359 expect(jsonObj.items.length).to.be.equal(1) // subscribed to self, it should not list the instance's videos but list john's
360 }
361 })
362
363 it('Should list videos of a user\'s subscription', async function () {
364 this.timeout(30000)
365
366 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port)
367 await waitJobs(servers)
368
369 {
370 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
371 expect(res.body.total).to.equal(2, "there should be 2 videos part of the subscription")
372
373 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId, token: userFeedToken, version: 2 })
374 const jsonObj = JSON.parse(json.text)
375 expect(jsonObj.items.length).to.be.equal(2) // subscribed to root, it should not list the instance's videos but list root/john's
376 }
377 })
378
379 })
380
292 after(async function () { 381 after(async function () {
293 await cleanupTests([ ...servers, serverHLSOnly ]) 382 await cleanupTests([ ...servers, serverHLSOnly ])
294 }) 383 })