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