aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-25 11:04:18 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-25 11:07:56 +0100
commit18490b07650d77d7fe376970b749af5a8c672fd6 (patch)
tree89741e63e34c2659487c9afa8309755064cb0c39 /server/tests
parent5beb89f223539f1e415a976ff104f772526b4d20 (diff)
downloadPeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.tar.gz
PeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.tar.zst
PeerTube-18490b07650d77d7fe376970b749af5a8c672fd6.zip
Fix migration and test
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/users.ts32
-rw-r--r--server/tests/feeds/feeds.ts53
2 files changed, 66 insertions, 19 deletions
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 2a220be83..da7dc9704 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -14,6 +14,7 @@ import {
14 flushAndRunServer, 14 flushAndRunServer,
15 getMyUserInformation, 15 getMyUserInformation,
16 getMyUserVideoRating, 16 getMyUserVideoRating,
17 getUserScopedTokens,
17 getUsersList, 18 getUsersList,
18 immutableAssign, 19 immutableAssign,
19 killallServers, 20 killallServers,
@@ -23,6 +24,7 @@ import {
23 makeUploadRequest, 24 makeUploadRequest,
24 registerUser, 25 registerUser,
25 removeUser, 26 removeUser,
27 renewUserScopedTokens,
26 reRunServer, 28 reRunServer,
27 ServerInfo, 29 ServerInfo,
28 setAccessTokensToServers, 30 setAccessTokensToServers,
@@ -38,7 +40,7 @@ import {
38 checkBadStartPagination 40 checkBadStartPagination
39} from '../../../../shared/extra-utils/requests/check-api-params' 41} from '../../../../shared/extra-utils/requests/check-api-params'
40import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 42import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
41import { getMagnetURI, getMyVideoImports, getGoodVideoUrl, importVideo } from '../../../../shared/extra-utils/videos/video-imports' 43import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
42import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 44import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
43import { VideoPrivacy } from '../../../../shared/models/videos' 45import { VideoPrivacy } from '../../../../shared/models/videos'
44 46
@@ -609,6 +611,34 @@ describe('Test users API validators', function () {
609 }) 611 })
610 }) 612 })
611 613
614 describe('When managing my scoped tokens', function () {
615
616 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
617 await getUserScopedTokens(server.url, null, 401)
618 })
619
620 it('Should fail to get my scoped tokens with a bad token', async function () {
621 await getUserScopedTokens(server.url, 'bad', 401)
622
623 })
624
625 it('Should succeed to get my scoped tokens', async function () {
626 await getUserScopedTokens(server.url, server.accessToken)
627 })
628
629 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
630 await renewUserScopedTokens(server.url, null, 401)
631 })
632
633 it('Should fail to renew my scoped tokens with a bad token', async function () {
634 await renewUserScopedTokens(server.url, 'bad', 401)
635 })
636
637 it('Should succeed to renew my scoped tokens', async function () {
638 await renewUserScopedTokens(server.url, server.accessToken)
639 })
640 })
641
612 describe('When getting a user', function () { 642 describe('When getting a user', function () {
613 643
614 it('Should fail with an non authenticated user', async function () { 644 it('Should fail with an non authenticated user', async function () {
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 175ea9102..92a468192 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -8,28 +8,29 @@ import {
8 addAccountToServerBlocklist, 8 addAccountToServerBlocklist,
9 removeAccountFromServerBlocklist 9 removeAccountFromServerBlocklist
10} from '@shared/extra-utils/users/blocklist' 10} from '@shared/extra-utils/users/blocklist'
11import { addUserSubscription, listUserSubscriptionVideos } from '@shared/extra-utils/users/user-subscriptions'
11import { VideoPrivacy } from '@shared/models' 12import { VideoPrivacy } from '@shared/models'
13import { ScopedToken } from '@shared/models/users/user-scoped-token'
12import { 14import {
13 cleanupTests, 15 cleanupTests,
14 createUser, 16 createUser,
15 doubleFollow, 17 doubleFollow,
16 flushAndRunMultipleServers, 18 flushAndRunMultipleServers,
19 flushAndRunServer,
17 getJSONfeed, 20 getJSONfeed,
18 getMyUserInformation, 21 getMyUserInformation,
22 getUserScopedTokens,
19 getXMLfeed, 23 getXMLfeed,
24 renewUserScopedTokens,
20 ServerInfo, 25 ServerInfo,
21 setAccessTokensToServers, 26 setAccessTokensToServers,
22 uploadVideo, 27 uploadVideo,
23 uploadVideoAndGetId, 28 uploadVideoAndGetId,
24 userLogin, 29 userLogin
25 flushAndRunServer,
26 getUserScopedTokens
27} from '../../../shared/extra-utils' 30} from '../../../shared/extra-utils'
28import { waitJobs } from '../../../shared/extra-utils/server/jobs' 31import { waitJobs } from '../../../shared/extra-utils/server/jobs'
29import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' 32import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
30import { User } from '../../../shared/models/users' 33import { User } from '../../../shared/models/users'
31import { ScopedToken } from '@shared/models/users/user-scoped-token'
32import { listUserSubscriptionVideos, addUserSubscription } from '@shared/extra-utils/users/user-subscriptions'
33 34
34chai.use(require('chai-xml')) 35chai.use(require('chai-xml'))
35chai.use(require('chai-json-schema')) 36chai.use(require('chai-json-schema'))
@@ -298,14 +299,10 @@ describe('Test syndication feeds', () => {
298 }) 299 })
299 300
300 describe('Video feed from my subscriptions', function () { 301 describe('Video feed from my subscriptions', function () {
301 /** 302 let feeduserAccountId: number
302 * use the 'version' query parameter to bust cache between tests 303 let feeduserFeedToken: string
303 */
304 304
305 it('Should list no videos for a user with no videos and no subscriptions', async function () { 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' } 306 const attr = { username: 'feeduser', password: 'password' }
310 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) 307 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
311 const feeduserAccessToken = await userLogin(servers[0], attr) 308 const feeduserAccessToken = await userLogin(servers[0], attr)
@@ -332,15 +329,21 @@ describe('Test syndication feeds', () => {
332 } 329 }
333 }) 330 })
334 331
332 it('Should fail with an invalid token', async function () {
333 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: feeduserAccountId, token: 'toto' }, 403)
334 })
335
336 it('Should fail with a token of another user', async function () {
337 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: feeduserAccountId, token: userFeedToken }, 403)
338 })
339
335 it('Should list no videos for a user with videos but no subscriptions', async function () { 340 it('Should list no videos for a user with videos but no subscriptions', async function () {
336 { 341 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken)
337 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 342 expect(res.body.total).to.equal(0)
338 expect(res.body.total).to.equal(0)
339 343
340 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken }) 344 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken })
341 const jsonObj = JSON.parse(json.text) 345 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 346 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
343 }
344 }) 347 })
345 348
346 it('Should list self videos for a user with a subscription to themselves', async function () { 349 it('Should list self videos for a user with a subscription to themselves', async function () {
@@ -376,6 +379,20 @@ describe('Test syndication feeds', () => {
376 } 379 }
377 }) 380 })
378 381
382 it('Should renew the token, and so have an invalid old token', async function () {
383 await renewUserScopedTokens(servers[0].url, userAccessToken)
384
385 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken, version: 3 }, 403)
386 })
387
388 it('Should succeed with the new token', async function () {
389 const res2 = await getUserScopedTokens(servers[0].url, userAccessToken)
390 const token: ScopedToken = res2.body
391 userFeedToken = token.feedToken
392
393 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken, version: 4 })
394 })
395
379 }) 396 })
380 397
381 after(async function () { 398 after(async function () {