aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-privacy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/video-privacy.ts')
-rw-r--r--server/tests/api/videos/video-privacy.ts157
1 files changed, 71 insertions, 86 deletions
diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts
index 950aeb7cf..b51b3bcdd 100644
--- a/server/tests/api/videos/video-privacy.ts
+++ b/server/tests/api/videos/video-privacy.ts
@@ -2,28 +2,13 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' 5import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { Video, VideoCreateResult } from '@shared/models' 6import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
7import {
8 cleanupTests,
9 flushAndRunServer,
10 getVideosList,
11 getVideosListWithToken,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo
15} from '../../../../shared/extra-utils/index'
16import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
17import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
18import { userLogin } from '../../../../shared/extra-utils/users/login'
19import { createUser } from '../../../../shared/extra-utils/users/users'
20import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
21import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
22 7
23const expect = chai.expect 8const expect = chai.expect
24 9
25describe('Test video privacy', function () { 10describe('Test video privacy', function () {
26 const servers: ServerInfo[] = [] 11 const servers: PeerTubeServer[] = []
27 let anotherUserToken: string 12 let anotherUserToken: string
28 13
29 let privateVideoId: number 14 let privateVideoId: number
@@ -49,8 +34,8 @@ describe('Test video privacy', function () {
49 this.timeout(50000) 34 this.timeout(50000)
50 35
51 // Run servers 36 // Run servers
52 servers.push(await flushAndRunServer(1, dontFederateUnlistedConfig)) 37 servers.push(await createSingleServer(1, dontFederateUnlistedConfig))
53 servers.push(await flushAndRunServer(2)) 38 servers.push(await createSingleServer(2))
54 39
55 // Get the access tokens 40 // Get the access tokens
56 await setAccessTokensToServers(servers) 41 await setAccessTokensToServers(servers)
@@ -66,55 +51,53 @@ describe('Test video privacy', function () {
66 51
67 for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { 52 for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
68 const attributes = { privacy } 53 const attributes = { privacy }
69 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 54 await servers[0].videos.upload({ attributes })
70 } 55 }
71 56
72 await waitJobs(servers) 57 await waitJobs(servers)
73 }) 58 })
74 59
75 it('Should not have these private and internal videos on server 2', async function () { 60 it('Should not have these private and internal videos on server 2', async function () {
76 const res = await getVideosList(servers[1].url) 61 const { total, data } = await servers[1].videos.list()
77 62
78 expect(res.body.total).to.equal(0) 63 expect(total).to.equal(0)
79 expect(res.body.data).to.have.lengthOf(0) 64 expect(data).to.have.lengthOf(0)
80 }) 65 })
81 66
82 it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () { 67 it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () {
83 const res = await getVideosList(servers[0].url) 68 const { total, data } = await servers[0].videos.list()
84 69
85 expect(res.body.total).to.equal(0) 70 expect(total).to.equal(0)
86 expect(res.body.data).to.have.lengthOf(0) 71 expect(data).to.have.lengthOf(0)
87 }) 72 })
88 73
89 it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { 74 it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () {
90 const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) 75 const { total, data } = await servers[0].videos.listWithToken()
91 76
92 expect(res.body.total).to.equal(1) 77 expect(total).to.equal(1)
93 expect(res.body.data).to.have.lengthOf(1) 78 expect(data).to.have.lengthOf(1)
94 79
95 expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) 80 expect(data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
96 }) 81 })
97 82
98 it('Should list my (private and internal) videos', async function () { 83 it('Should list my (private and internal) videos', async function () {
99 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10) 84 const { total, data } = await servers[0].videos.listMyVideos()
100 85
101 expect(res.body.total).to.equal(2) 86 expect(total).to.equal(2)
102 expect(res.body.data).to.have.lengthOf(2) 87 expect(data).to.have.lengthOf(2)
103 88
104 const videos: Video[] = res.body.data 89 const privateVideo = data.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
105
106 const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
107 privateVideoId = privateVideo.id 90 privateVideoId = privateVideo.id
108 privateVideoUUID = privateVideo.uuid 91 privateVideoUUID = privateVideo.uuid
109 92
110 const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL) 93 const internalVideo = data.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
111 internalVideoId = internalVideo.id 94 internalVideoId = internalVideo.id
112 internalVideoUUID = internalVideo.uuid 95 internalVideoUUID = internalVideo.uuid
113 }) 96 })
114 97
115 it('Should not be able to watch the private/internal video with non authenticated user', async function () { 98 it('Should not be able to watch the private/internal video with non authenticated user', async function () {
116 await getVideo(servers[0].url, privateVideoUUID, HttpStatusCode.UNAUTHORIZED_401) 99 await servers[0].videos.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
117 await getVideo(servers[0].url, internalVideoUUID, HttpStatusCode.UNAUTHORIZED_401) 100 await servers[0].videos.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
118 }) 101 })
119 102
120 it('Should not be able to watch the private video with another user', async function () { 103 it('Should not be able to watch the private video with another user', async function () {
@@ -124,18 +107,23 @@ describe('Test video privacy', function () {
124 username: 'hello', 107 username: 'hello',
125 password: 'super password' 108 password: 'super password'
126 } 109 }
127 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 110 await servers[0].users.create({ username: user.username, password: user.password })
111
112 anotherUserToken = await servers[0].login.getAccessToken(user)
128 113
129 anotherUserToken = await userLogin(servers[0], user) 114 await servers[0].videos.getWithToken({
130 await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, HttpStatusCode.FORBIDDEN_403) 115 token: anotherUserToken,
116 id: privateVideoUUID,
117 expectedStatus: HttpStatusCode.FORBIDDEN_403
118 })
131 }) 119 })
132 120
133 it('Should be able to watch the internal video with another user', async function () { 121 it('Should be able to watch the internal video with another user', async function () {
134 await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, HttpStatusCode.OK_200) 122 await servers[0].videos.getWithToken({ token: anotherUserToken, id: internalVideoUUID })
135 }) 123 })
136 124
137 it('Should be able to watch the private video with the correct user', async function () { 125 it('Should be able to watch the private video with the correct user', async function () {
138 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, HttpStatusCode.OK_200) 126 await servers[0].videos.getWithToken({ id: privateVideoUUID })
139 }) 127 })
140 }) 128 })
141 129
@@ -148,7 +136,7 @@ describe('Test video privacy', function () {
148 name: 'unlisted video', 136 name: 'unlisted video',
149 privacy: VideoPrivacy.UNLISTED 137 privacy: VideoPrivacy.UNLISTED
150 } 138 }
151 await uploadVideo(servers[1].url, servers[1].accessToken, attributes) 139 await servers[1].videos.upload({ attributes })
152 140
153 // Server 2 has transcoding enabled 141 // Server 2 has transcoding enabled
154 await waitJobs(servers) 142 await waitJobs(servers)
@@ -156,32 +144,32 @@ describe('Test video privacy', function () {
156 144
157 it('Should not have this unlisted video listed on server 1 and 2', async function () { 145 it('Should not have this unlisted video listed on server 1 and 2', async function () {
158 for (const server of servers) { 146 for (const server of servers) {
159 const res = await getVideosList(server.url) 147 const { total, data } = await server.videos.list()
160 148
161 expect(res.body.total).to.equal(0) 149 expect(total).to.equal(0)
162 expect(res.body.data).to.have.lengthOf(0) 150 expect(data).to.have.lengthOf(0)
163 } 151 }
164 }) 152 })
165 153
166 it('Should list my (unlisted) videos', async function () { 154 it('Should list my (unlisted) videos', async function () {
167 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) 155 const { total, data } = await servers[1].videos.listMyVideos()
168 156
169 expect(res.body.total).to.equal(1) 157 expect(total).to.equal(1)
170 expect(res.body.data).to.have.lengthOf(1) 158 expect(data).to.have.lengthOf(1)
171 159
172 unlistedVideo = res.body.data[0] 160 unlistedVideo = data[0]
173 }) 161 })
174 162
175 it('Should not be able to get this unlisted video using its id', async function () { 163 it('Should not be able to get this unlisted video using its id', async function () {
176 await getVideo(servers[1].url, unlistedVideo.id, 404) 164 await servers[1].videos.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
177 }) 165 })
178 166
179 it('Should be able to get this unlisted video using its uuid/shortUUID', async function () { 167 it('Should be able to get this unlisted video using its uuid/shortUUID', async function () {
180 for (const server of servers) { 168 for (const server of servers) {
181 for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) { 169 for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) {
182 const res = await getVideo(server.url, id) 170 const video = await server.videos.get({ id })
183 171
184 expect(res.body.name).to.equal('unlisted video') 172 expect(video.name).to.equal('unlisted video')
185 } 173 }
186 } 174 }
187 }) 175 })
@@ -193,28 +181,28 @@ describe('Test video privacy', function () {
193 name: 'unlisted video', 181 name: 'unlisted video',
194 privacy: VideoPrivacy.UNLISTED 182 privacy: VideoPrivacy.UNLISTED
195 } 183 }
196 await uploadVideo(servers[0].url, servers[0].accessToken, attributes) 184 await servers[0].videos.upload({ attributes })
197 185
198 await waitJobs(servers) 186 await waitJobs(servers)
199 }) 187 })
200 188
201 it('Should list my new unlisted video', async function () { 189 it('Should list my new unlisted video', async function () {
202 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3) 190 const { total, data } = await servers[0].videos.listMyVideos()
203 191
204 expect(res.body.total).to.equal(3) 192 expect(total).to.equal(3)
205 expect(res.body.data).to.have.lengthOf(3) 193 expect(data).to.have.lengthOf(3)
206 194
207 nonFederatedUnlistedVideoUUID = res.body.data[0].uuid 195 nonFederatedUnlistedVideoUUID = data[0].uuid
208 }) 196 })
209 197
210 it('Should be able to get non-federated unlisted video from origin', async function () { 198 it('Should be able to get non-federated unlisted video from origin', async function () {
211 const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID) 199 const video = await servers[0].videos.get({ id: nonFederatedUnlistedVideoUUID })
212 200
213 expect(res.body.name).to.equal('unlisted video') 201 expect(video.name).to.equal('unlisted video')
214 }) 202 })
215 203
216 it('Should not be able to get non-federated unlisted video from federated server', async function () { 204 it('Should not be able to get non-federated unlisted video from federated server', async function () {
217 await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, HttpStatusCode.NOT_FOUND_404) 205 await servers[1].videos.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
218 }) 206 })
219 }) 207 })
220 208
@@ -226,20 +214,20 @@ describe('Test video privacy', function () {
226 now = Date.now() 214 now = Date.now()
227 215
228 { 216 {
229 const attribute = { 217 const attributes = {
230 name: 'private video becomes public', 218 name: 'private video becomes public',
231 privacy: VideoPrivacy.PUBLIC 219 privacy: VideoPrivacy.PUBLIC
232 } 220 }
233 221
234 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) 222 await servers[0].videos.update({ id: privateVideoId, attributes })
235 } 223 }
236 224
237 { 225 {
238 const attribute = { 226 const attributes = {
239 name: 'internal video becomes public', 227 name: 'internal video becomes public',
240 privacy: VideoPrivacy.PUBLIC 228 privacy: VideoPrivacy.PUBLIC
241 } 229 }
242 await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, attribute) 230 await servers[0].videos.update({ id: internalVideoId, attributes })
243 } 231 }
244 232
245 await waitJobs(servers) 233 await waitJobs(servers)
@@ -247,13 +235,12 @@ describe('Test video privacy', function () {
247 235
248 it('Should have this new public video listed on server 1 and 2', async function () { 236 it('Should have this new public video listed on server 1 and 2', async function () {
249 for (const server of servers) { 237 for (const server of servers) {
250 const res = await getVideosList(server.url) 238 const { total, data } = await server.videos.list()
251 expect(res.body.total).to.equal(2) 239 expect(total).to.equal(2)
252 expect(res.body.data).to.have.lengthOf(2) 240 expect(data).to.have.lengthOf(2)
253 241
254 const videos: Video[] = res.body.data 242 const privateVideo = data.find(v => v.name === 'private video becomes public')
255 const privateVideo = videos.find(v => v.name === 'private video becomes public') 243 const internalVideo = data.find(v => v.name === 'internal video becomes public')
256 const internalVideo = videos.find(v => v.name === 'internal video becomes public')
257 244
258 expect(privateVideo).to.not.be.undefined 245 expect(privateVideo).to.not.be.undefined
259 expect(internalVideo).to.not.be.undefined 246 expect(internalVideo).to.not.be.undefined
@@ -270,27 +257,25 @@ describe('Test video privacy', function () {
270 it('Should set these videos as private and internal', async function () { 257 it('Should set these videos as private and internal', async function () {
271 this.timeout(10000) 258 this.timeout(10000)
272 259
273 await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) 260 await servers[0].videos.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } })
274 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) 261 await servers[0].videos.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } })
275 262
276 await waitJobs(servers) 263 await waitJobs(servers)
277 264
278 for (const server of servers) { 265 for (const server of servers) {
279 const res = await getVideosList(server.url) 266 const { total, data } = await server.videos.list()
280 267
281 expect(res.body.total).to.equal(0) 268 expect(total).to.equal(0)
282 expect(res.body.data).to.have.lengthOf(0) 269 expect(data).to.have.lengthOf(0)
283 } 270 }
284 271
285 { 272 {
286 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) 273 const { total, data } = await servers[0].videos.listMyVideos()
287 const videos = res.body.data 274 expect(total).to.equal(3)
288 275 expect(data).to.have.lengthOf(3)
289 expect(res.body.total).to.equal(3)
290 expect(videos).to.have.lengthOf(3)
291 276
292 const privateVideo = videos.find(v => v.name === 'private video becomes public') 277 const privateVideo = data.find(v => v.name === 'private video becomes public')
293 const internalVideo = videos.find(v => v.name === 'internal video becomes public') 278 const internalVideo = data.find(v => v.name === 'internal video becomes public')
294 279
295 expect(privateVideo).to.not.be.undefined 280 expect(privateVideo).to.not.be.undefined
296 expect(internalVideo).to.not.be.undefined 281 expect(internalVideo).to.not.be.undefined