aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-04-15 10:49:46 +0200
committerChocobozzz <me@florianbigard.com>2019-04-15 14:39:52 +0200
commit1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a (patch)
tree91a10310cdf924779527525d39f8eb7e09e4ba49 /server/tests/api/videos
parent31b48aad478506d4214586f02792816efa968e4b (diff)
downloadPeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.gz
PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.zst
PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.zip
Add user adminFlags
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/multiple-servers.ts2
-rw-r--r--server/tests/api/videos/video-blacklist.ts115
-rw-r--r--server/tests/api/videos/video-change-ownership.ts32
-rw-r--r--server/tests/api/videos/video-channels.ts2
-rw-r--r--server/tests/api/videos/video-nsfw.ts2
-rw-r--r--server/tests/api/videos/video-playlists.ts7
-rw-r--r--server/tests/api/videos/video-privacy.ts2
-rw-r--r--server/tests/api/videos/videos-filter.ts16
-rw-r--r--server/tests/api/videos/videos-history.ts2
9 files changed, 149 insertions, 31 deletions
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index f91678140..46486b777 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -164,7 +164,7 @@ describe('Test multiple servers', function () {
164 username: 'user1', 164 username: 'user1',
165 password: 'super_password' 165 password: 'super_password'
166 } 166 }
167 await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) 167 await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
168 const userAccessToken = await userLogin(servers[1], user) 168 const userAccessToken = await userLogin(servers[1], user)
169 169
170 const videoAttributes = { 170 const videoAttributes = {
diff --git a/server/tests/api/videos/video-blacklist.ts b/server/tests/api/videos/video-blacklist.ts
index 10b412a80..1feae19e9 100644
--- a/server/tests/api/videos/video-blacklist.ts
+++ b/server/tests/api/videos/video-blacklist.ts
@@ -5,29 +5,31 @@ import { orderBy } from 'lodash'
5import 'mocha' 5import 'mocha'
6import { 6import {
7 addVideoToBlacklist, 7 addVideoToBlacklist,
8 createUser,
8 flushAndRunMultipleServers, 9 flushAndRunMultipleServers,
9 getBlacklistedVideosList, 10 getBlacklistedVideosList,
10 getBlacklistedVideosListWithTypeFilter,
11 getMyVideos, 11 getMyVideos,
12 getSortedBlacklistedVideosList,
13 getVideosList, 12 getVideosList,
14 killallServers, 13 killallServers,
15 removeVideoFromBlacklist, 14 removeVideoFromBlacklist,
15 reRunServer,
16 searchVideo, 16 searchVideo,
17 ServerInfo, 17 ServerInfo,
18 setAccessTokensToServers, 18 setAccessTokensToServers,
19 updateVideo, 19 updateVideo,
20 updateVideoBlacklist, 20 updateVideoBlacklist,
21 uploadVideo, 21 uploadVideo,
22 viewVideo 22 userLogin
23} from '../../../../shared/utils/index' 23} from '../../../../shared/utils/index'
24import { doubleFollow } from '../../../../shared/utils/server/follows' 24import { doubleFollow } from '../../../../shared/utils/server/follows'
25import { waitJobs } from '../../../../shared/utils/server/jobs' 25import { waitJobs } from '../../../../shared/utils/server/jobs'
26import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos' 26import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
27import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
28import { UserRole } from '../../../../shared/models/users'
27 29
28const expect = chai.expect 30const expect = chai.expect
29 31
30describe('Test video blacklist management', function () { 32describe('Test video blacklist', function () {
31 let servers: ServerInfo[] = [] 33 let servers: ServerInfo[] = []
32 let videoId: number 34 let videoId: number
33 35
@@ -104,7 +106,7 @@ describe('Test video blacklist management', function () {
104 106
105 describe('When listing manually blacklisted videos', function () { 107 describe('When listing manually blacklisted videos', function () {
106 it('Should display all the blacklisted videos', async function () { 108 it('Should display all the blacklisted videos', async function () {
107 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken) 109 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken })
108 110
109 expect(res.body.total).to.equal(2) 111 expect(res.body.total).to.equal(2)
110 112
@@ -119,7 +121,11 @@ describe('Test video blacklist management', function () {
119 }) 121 })
120 122
121 it('Should display all the blacklisted videos when applying manual type filter', async function () { 123 it('Should display all the blacklisted videos when applying manual type filter', async function () {
122 const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL) 124 const res = await getBlacklistedVideosList({
125 url: servers[ 0 ].url,
126 token: servers[ 0 ].accessToken,
127 type: VideoBlacklistType.MANUAL
128 })
123 129
124 expect(res.body.total).to.equal(2) 130 expect(res.body.total).to.equal(2)
125 131
@@ -129,7 +135,11 @@ describe('Test video blacklist management', function () {
129 }) 135 })
130 136
131 it('Should display nothing when applying automatic type filter', async function () { 137 it('Should display nothing when applying automatic type filter', async function () {
132 const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.AUTO_BEFORE_PUBLISHED) // tslint:disable:max-line-length 138 const res = await getBlacklistedVideosList({
139 url: servers[ 0 ].url,
140 token: servers[ 0 ].accessToken,
141 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
142 })
133 143
134 expect(res.body.total).to.equal(0) 144 expect(res.body.total).to.equal(0)
135 145
@@ -139,7 +149,7 @@ describe('Test video blacklist management', function () {
139 }) 149 })
140 150
141 it('Should get the correct sort when sorting by descending id', async function () { 151 it('Should get the correct sort when sorting by descending id', async function () {
142 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id') 152 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-id' })
143 expect(res.body.total).to.equal(2) 153 expect(res.body.total).to.equal(2)
144 154
145 const blacklistedVideos = res.body.data 155 const blacklistedVideos = res.body.data
@@ -152,7 +162,7 @@ describe('Test video blacklist management', function () {
152 }) 162 })
153 163
154 it('Should get the correct sort when sorting by descending video name', async function () { 164 it('Should get the correct sort when sorting by descending video name', async function () {
155 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 165 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
156 expect(res.body.total).to.equal(2) 166 expect(res.body.total).to.equal(2)
157 167
158 const blacklistedVideos = res.body.data 168 const blacklistedVideos = res.body.data
@@ -165,7 +175,7 @@ describe('Test video blacklist management', function () {
165 }) 175 })
166 176
167 it('Should get the correct sort when sorting by ascending creation date', async function () { 177 it('Should get the correct sort when sorting by ascending creation date', async function () {
168 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') 178 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' })
169 expect(res.body.total).to.equal(2) 179 expect(res.body.total).to.equal(2)
170 180
171 const blacklistedVideos = res.body.data 181 const blacklistedVideos = res.body.data
@@ -182,7 +192,7 @@ describe('Test video blacklist management', function () {
182 it('Should change the reason', async function () { 192 it('Should change the reason', async function () {
183 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') 193 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
184 194
185 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 195 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
186 const video = res.body.data.find(b => b.video.id === videoId) 196 const video = res.body.data.find(b => b.video.id === videoId)
187 197
188 expect(video.reason).to.equal('my super reason updated') 198 expect(video.reason).to.equal('my super reason updated')
@@ -218,7 +228,7 @@ describe('Test video blacklist management', function () {
218 228
219 it('Should remove a video from the blacklist on server 1', async function () { 229 it('Should remove a video from the blacklist on server 1', async function () {
220 // Get one video in the blacklist 230 // Get one video in the blacklist
221 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 231 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
222 videoToRemove = res.body.data[0] 232 videoToRemove = res.body.data[0]
223 blacklist = res.body.data.slice(1) 233 blacklist = res.body.data.slice(1)
224 234
@@ -239,7 +249,7 @@ describe('Test video blacklist management', function () {
239 }) 249 })
240 250
241 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 251 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
242 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name') 252 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
243 expect(res.body.total).to.equal(1) 253 expect(res.body.total).to.equal(1)
244 254
245 const videos = res.body.data 255 const videos = res.body.data
@@ -313,7 +323,7 @@ describe('Test video blacklist management', function () {
313 }) 323 })
314 324
315 it('Should have the correct video blacklist unfederate attribute', async function () { 325 it('Should have the correct video blacklist unfederate attribute', async function () {
316 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt') 326 const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' })
317 327
318 const blacklistedVideos: VideoBlacklist[] = res.body.data 328 const blacklistedVideos: VideoBlacklist[] = res.body.data
319 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) 329 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
@@ -338,6 +348,83 @@ describe('Test video blacklist management', function () {
338 348
339 }) 349 })
340 350
351 describe('When auto blacklist videos', function () {
352 let userWithoutFlag: string
353 let userWithFlag: string
354
355 before(async function () {
356 this.timeout(20000)
357
358 killallServers([ servers[0] ])
359
360 const config = {
361 'auto_blacklist': {
362 videos: {
363 'of_users': {
364 enabled: true
365 }
366 }
367 }
368 }
369 await reRunServer(servers[0], config)
370
371 {
372 const user = { username: 'user_without_flag', password: 'password' }
373 await createUser({
374 url: servers[ 0 ].url,
375 accessToken: servers[ 0 ].accessToken,
376 username: user.username,
377 adminFlags: UserAdminFlag.NONE,
378 password: user.password,
379 role: UserRole.USER
380 })
381
382 userWithoutFlag = await userLogin(servers[0], user)
383 }
384
385 {
386 const user = { username: 'user_with_flag', password: 'password' }
387 await createUser({
388 url: servers[ 0 ].url,
389 accessToken: servers[ 0 ].accessToken,
390 username: user.username,
391 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST,
392 password: user.password,
393 role: UserRole.USER
394 })
395
396 userWithFlag = await userLogin(servers[0], user)
397 }
398
399 await waitJobs(servers)
400 })
401
402 it('Should auto blacklist a video', async function () {
403 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
404
405 const res = await getBlacklistedVideosList({
406 url: servers[ 0 ].url,
407 token: servers[ 0 ].accessToken,
408 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
409 })
410
411 expect(res.body.total).to.equal(1)
412 expect(res.body.data[0].video.name).to.equal('blacklisted')
413 })
414
415 it('Should not auto blacklist a video', async function () {
416 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
417
418 const res = await getBlacklistedVideosList({
419 url: servers[ 0 ].url,
420 token: servers[ 0 ].accessToken,
421 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
422 })
423
424 expect(res.body.total).to.equal(1)
425 })
426 })
427
341 after(async function () { 428 after(async function () {
342 killallServers(servers) 429 killallServers(servers)
343 }) 430 })
diff --git a/server/tests/api/videos/video-change-ownership.ts b/server/tests/api/videos/video-change-ownership.ts
index 25675a966..a23e30dc0 100644
--- a/server/tests/api/videos/video-change-ownership.ts
+++ b/server/tests/api/videos/video-change-ownership.ts
@@ -46,8 +46,20 @@ describe('Test video change ownership - nominal', function () {
46 await setAccessTokensToServers(servers) 46 await setAccessTokensToServers(servers)
47 47
48 const videoQuota = 42000000 48 const videoQuota = 42000000
49 await createUser(servers[0].url, servers[0].accessToken, firstUser.username, firstUser.password, videoQuota) 49 await createUser({
50 await createUser(servers[0].url, servers[0].accessToken, secondUser.username, secondUser.password, videoQuota) 50 url: servers[ 0 ].url,
51 accessToken: servers[ 0 ].accessToken,
52 username: firstUser.username,
53 password: firstUser.password,
54 videoQuota: videoQuota
55 })
56 await createUser({
57 url: servers[ 0 ].url,
58 accessToken: servers[ 0 ].accessToken,
59 username: secondUser.username,
60 password: secondUser.password,
61 videoQuota: videoQuota
62 })
51 63
52 firstUserAccessToken = await userLogin(servers[0], firstUser) 64 firstUserAccessToken = await userLogin(servers[0], firstUser)
53 secondUserAccessToken = await userLogin(servers[0], secondUser) 65 secondUserAccessToken = await userLogin(servers[0], secondUser)
@@ -219,8 +231,20 @@ describe('Test video change ownership - quota too small', function () {
219 231
220 const videoQuota = 42000000 232 const videoQuota = 42000000
221 const limitedVideoQuota = 10 233 const limitedVideoQuota = 10
222 await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota) 234 await createUser({
223 await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, limitedVideoQuota) 235 url: server.url,
236 accessToken: server.accessToken,
237 username: firstUser.username,
238 password: firstUser.password,
239 videoQuota: videoQuota
240 })
241 await createUser({
242 url: server.url,
243 accessToken: server.accessToken,
244 username: secondUser.username,
245 password: secondUser.password,
246 videoQuota: limitedVideoQuota
247 })
224 248
225 firstUserAccessToken = await userLogin(server, firstUser) 249 firstUserAccessToken = await userLogin(server, firstUser)
226 secondUserAccessToken = await userLogin(server, secondUser) 250 secondUserAccessToken = await userLogin(server, secondUser)
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 63514d69c..bd672cf41 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -270,7 +270,7 @@ describe('Test video channels', function () {
270 } 270 }
271 271
272 { 272 {
273 await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, 'toto', 'password') 273 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' })
274 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' }) 274 const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' })
275 275
276 const res = await getMyUserInformation(servers[ 0 ].url, accessToken) 276 const res = await getMyUserInformation(servers[ 0 ].url, accessToken)
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index df1ee2eb9..cb972d921 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -144,7 +144,7 @@ describe('Test video NSFW policy', function () {
144 it('Should create a user having the default nsfw policy', async function () { 144 it('Should create a user having the default nsfw policy', async function () {
145 const username = 'user1' 145 const username = 'user1'
146 const password = 'my super password' 146 const password = 'my super password'
147 await createUser(server.url, server.accessToken, username, password) 147 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
148 148
149 userAccessToken = await userLogin(server, { username, password }) 149 userAccessToken = await userLogin(server, { username, password })
150 150
diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts
index fc2662808..d9cb71992 100644
--- a/server/tests/api/videos/video-playlists.ts
+++ b/server/tests/api/videos/video-playlists.ts
@@ -815,7 +815,12 @@ describe('Test video playlists', function () {
815 this.timeout(30000) 815 this.timeout(30000)
816 816
817 const user = { username: 'user_1', password: 'password' } 817 const user = { username: 'user_1', password: 'password' }
818 const res = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 818 const res = await createUser({
819 url: servers[ 0 ].url,
820 accessToken: servers[ 0 ].accessToken,
821 username: user.username,
822 password: user.password
823 })
819 824
820 const userId = res.body.user.id 825 const userId = res.body.user.id
821 const userAccessToken = await userLogin(servers[0], user) 826 const userAccessToken = await userLogin(servers[0], user)
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index 0b4e66369..e1b5fb193 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -78,7 +78,7 @@ describe('Test video privacy', function () {
78 username: 'hello', 78 username: 'hello',
79 password: 'super password' 79 password: 'super password'
80 } 80 }
81 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password) 81 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
82 82
83 const token = await userLogin(servers[0], user) 83 const token = await userLogin(servers[0], user)
84 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403) 84 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 59e37ad86..920ca0023 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -64,13 +64,15 @@ describe('Test videos filter validator', function () {
64 for (const server of servers) { 64 for (const server of servers) {
65 const moderator = { username: 'moderator', password: 'my super password' } 65 const moderator = { username: 'moderator', password: 'my super password' }
66 await createUser( 66 await createUser(
67 server.url, 67 {
68 server.accessToken, 68 url: server.url,
69 moderator.username, 69 accessToken: server.accessToken,
70 moderator.password, 70 username: moderator.username,
71 undefined, 71 password: moderator.password,
72 undefined, 72 videoQuota: undefined,
73 UserRole.MODERATOR 73 videoQuotaDaily: undefined,
74 role: UserRole.MODERATOR
75 }
74 ) 76 )
75 server['moderatorAccessToken'] = await userLogin(server, moderator) 77 server['moderatorAccessToken'] = await userLogin(server, moderator)
76 78
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts
index f7d3a6aeb..ab40bb64c 100644
--- a/server/tests/api/videos/videos-history.ts
+++ b/server/tests/api/videos/videos-history.ts
@@ -58,7 +58,7 @@ describe('Test videos history', function () {
58 username: 'user_1', 58 username: 'user_1',
59 password: 'super password' 59 password: 'super password'
60 } 60 }
61 await createUser(server.url, server.accessToken, user.username, user.password) 61 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
62 userAccessToken = await userLogin(server, user) 62 userAccessToken = await userLogin(server, user)
63 }) 63 })
64 64