]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
11474c3c | 2 | |
11474c3c | 3 | import * as chai from 'chai' |
975e6e0e | 4 | import 'mocha' |
c5d31dba | 5 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' |
11474c3c | 6 | import { |
7c3b7976 | 7 | cleanupTests, |
3092e9bb | 8 | flushAndRunServer, |
a1587156 C |
9 | getVideosList, |
10 | getVideosListWithToken, | |
975e6e0e | 11 | ServerInfo, |
11474c3c | 12 | setAccessTokensToServers, |
3cd0734f | 13 | uploadVideo |
94565d52 C |
14 | } from '../../../../shared/extra-utils/index' |
15 | import { doubleFollow } from '../../../../shared/extra-utils/server/follows' | |
16 | import { userLogin } from '../../../../shared/extra-utils/users/login' | |
17 | import { createUser } from '../../../../shared/extra-utils/users/users' | |
18 | import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos' | |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | |
22a73cb8 | 20 | import { Video } from '@shared/models' |
975e6e0e C |
21 | |
22 | const expect = chai.expect | |
11474c3c C |
23 | |
24 | describe('Test video privacy', function () { | |
3092e9bb | 25 | const servers: ServerInfo[] = [] |
22a73cb8 C |
26 | let anotherUserToken: string |
27 | ||
c49db162 C |
28 | let privateVideoId: number |
29 | let privateVideoUUID: string | |
22a73cb8 C |
30 | |
31 | let internalVideoId: number | |
32 | let internalVideoUUID: string | |
33 | ||
c49db162 | 34 | let unlistedVideoUUID: string |
3092e9bb | 35 | let nonFederatedUnlistedVideoUUID: string |
22a73cb8 | 36 | |
c49db162 | 37 | let now: number |
11474c3c | 38 | |
3092e9bb LB |
39 | const dontFederateUnlistedConfig = { |
40 | federation: { | |
41 | videos: { | |
42 | federate_unlisted: false | |
43 | } | |
44 | } | |
45 | } | |
46 | ||
11474c3c | 47 | before(async function () { |
572f8d3d | 48 | this.timeout(50000) |
11474c3c C |
49 | |
50 | // Run servers | |
3092e9bb LB |
51 | servers.push(await flushAndRunServer(1, dontFederateUnlistedConfig)) |
52 | servers.push(await flushAndRunServer(2)) | |
11474c3c C |
53 | |
54 | // Get the access tokens | |
55 | await setAccessTokensToServers(servers) | |
56 | ||
975e6e0e C |
57 | // Server 1 and server 2 follow each other |
58 | await doubleFollow(servers[0], servers[1]) | |
11474c3c C |
59 | }) |
60 | ||
22a73cb8 | 61 | it('Should upload a private and internal videos on server 1', async function () { |
572f8d3d | 62 | this.timeout(10000) |
11474c3c | 63 | |
22a73cb8 C |
64 | for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) { |
65 | const attributes = { privacy } | |
66 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | |
11474c3c | 67 | } |
11474c3c | 68 | |
3cd0734f | 69 | await waitJobs(servers) |
11474c3c C |
70 | }) |
71 | ||
22a73cb8 | 72 | it('Should not have these private and internal videos on server 2', async function () { |
11474c3c C |
73 | const res = await getVideosList(servers[1].url) |
74 | ||
75 | expect(res.body.total).to.equal(0) | |
76 | expect(res.body.data).to.have.lengthOf(0) | |
77 | }) | |
78 | ||
22a73cb8 C |
79 | it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () { |
80 | const res = await getVideosList(servers[0].url) | |
81 | ||
82 | expect(res.body.total).to.equal(0) | |
83 | expect(res.body.data).to.have.lengthOf(0) | |
84 | }) | |
85 | ||
86 | it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () { | |
87 | const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken) | |
11474c3c C |
88 | |
89 | expect(res.body.total).to.equal(1) | |
90 | expect(res.body.data).to.have.lengthOf(1) | |
91 | ||
22a73cb8 C |
92 | expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL) |
93 | }) | |
94 | ||
95 | it('Should list my (private and internal) videos', async function () { | |
96 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10) | |
97 | ||
98 | expect(res.body.total).to.equal(2) | |
99 | expect(res.body.data).to.have.lengthOf(2) | |
100 | ||
101 | const videos: Video[] = res.body.data | |
102 | ||
103 | const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE) | |
104 | privateVideoId = privateVideo.id | |
105 | privateVideoUUID = privateVideo.uuid | |
106 | ||
107 | const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL) | |
108 | internalVideoId = internalVideo.id | |
109 | internalVideoUUID = internalVideo.uuid | |
11474c3c C |
110 | }) |
111 | ||
22a73cb8 | 112 | it('Should not be able to watch the private/internal video with non authenticated user', async function () { |
11474c3c | 113 | await getVideo(servers[0].url, privateVideoUUID, 401) |
22a73cb8 | 114 | await getVideo(servers[0].url, internalVideoUUID, 401) |
11474c3c C |
115 | }) |
116 | ||
22a73cb8 | 117 | it('Should not be able to watch the private video with another user', async function () { |
77a87fec C |
118 | this.timeout(10000) |
119 | ||
11474c3c C |
120 | const user = { |
121 | username: 'hello', | |
122 | password: 'super password' | |
123 | } | |
a1587156 | 124 | await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) |
11474c3c | 125 | |
22a73cb8 C |
126 | anotherUserToken = await userLogin(servers[0], user) |
127 | await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, 403) | |
11474c3c C |
128 | }) |
129 | ||
22a73cb8 C |
130 | it('Should be able to watch the internal video with another user', async function () { |
131 | await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, 200) | |
132 | }) | |
133 | ||
134 | it('Should be able to watch the private video with the correct user', async function () { | |
135 | await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, 200) | |
11474c3c C |
136 | }) |
137 | ||
9a27cdc2 | 138 | it('Should upload an unlisted video on server 2', async function () { |
572f8d3d | 139 | this.timeout(30000) |
11474c3c C |
140 | |
141 | const attributes = { | |
142 | name: 'unlisted video', | |
143 | privacy: VideoPrivacy.UNLISTED | |
144 | } | |
145 | await uploadVideo(servers[1].url, servers[1].accessToken, attributes) | |
146 | ||
572f8d3d | 147 | // Server 2 has transcoding enabled |
3cd0734f | 148 | await waitJobs(servers) |
11474c3c C |
149 | }) |
150 | ||
975e6e0e | 151 | it('Should not have this unlisted video listed on server 1 and 2', async function () { |
11474c3c C |
152 | for (const server of servers) { |
153 | const res = await getVideosList(server.url) | |
154 | ||
155 | expect(res.body.total).to.equal(0) | |
156 | expect(res.body.data).to.have.lengthOf(0) | |
157 | } | |
158 | }) | |
159 | ||
160 | it('Should list my (unlisted) videos', async function () { | |
161 | const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1) | |
162 | ||
163 | expect(res.body.total).to.equal(1) | |
164 | expect(res.body.data).to.have.lengthOf(1) | |
165 | ||
166 | unlistedVideoUUID = res.body.data[0].uuid | |
167 | }) | |
168 | ||
169 | it('Should be able to get this unlisted video', async function () { | |
170 | for (const server of servers) { | |
171 | const res = await getVideo(server.url, unlistedVideoUUID) | |
172 | ||
173 | expect(res.body.name).to.equal('unlisted video') | |
174 | } | |
175 | }) | |
176 | ||
3092e9bb LB |
177 | it('Should upload a non-federating unlisted video to server 1', async function () { |
178 | this.timeout(30000) | |
179 | ||
180 | const attributes = { | |
181 | name: 'unlisted video', | |
182 | privacy: VideoPrivacy.UNLISTED | |
183 | } | |
184 | await uploadVideo(servers[0].url, servers[0].accessToken, attributes) | |
185 | ||
186 | await waitJobs(servers) | |
187 | }) | |
188 | ||
189 | it('Should list my new unlisted video', async function () { | |
190 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 3) | |
191 | ||
192 | expect(res.body.total).to.equal(3) | |
193 | expect(res.body.data).to.have.lengthOf(3) | |
194 | ||
195 | nonFederatedUnlistedVideoUUID = res.body.data[0].uuid | |
196 | }) | |
197 | ||
198 | it('Should be able to get non-federated unlisted video from origin', async function () { | |
199 | const res = await getVideo(servers[0].url, nonFederatedUnlistedVideoUUID) | |
200 | ||
201 | expect(res.body.name).to.equal('unlisted video') | |
202 | }) | |
203 | ||
204 | it('Should not be able to get non-federated unlisted video from federated server', async function () { | |
205 | await getVideo(servers[1].url, nonFederatedUnlistedVideoUUID, 404) | |
206 | }) | |
207 | ||
22a73cb8 | 208 | it('Should update the private and internal videos to public on server 1', async function () { |
572f8d3d | 209 | this.timeout(10000) |
11474c3c | 210 | |
22a73cb8 C |
211 | now = Date.now() |
212 | ||
213 | { | |
214 | const attribute = { | |
215 | name: 'private video becomes public', | |
216 | privacy: VideoPrivacy.PUBLIC | |
217 | } | |
218 | ||
a1587156 | 219 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute) |
11474c3c C |
220 | } |
221 | ||
22a73cb8 C |
222 | { |
223 | const attribute = { | |
224 | name: 'internal video becomes public', | |
225 | privacy: VideoPrivacy.PUBLIC | |
226 | } | |
a1587156 | 227 | await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, attribute) |
22a73cb8 | 228 | } |
11474c3c | 229 | |
3cd0734f | 230 | await waitJobs(servers) |
11474c3c C |
231 | }) |
232 | ||
9a27cdc2 | 233 | it('Should have this new public video listed on server 1 and 2', async function () { |
11474c3c C |
234 | for (const server of servers) { |
235 | const res = await getVideosList(server.url) | |
22a73cb8 C |
236 | expect(res.body.total).to.equal(2) |
237 | expect(res.body.data).to.have.lengthOf(2) | |
238 | ||
239 | const videos: Video[] = res.body.data | |
240 | const privateVideo = videos.find(v => v.name === 'private video becomes public') | |
241 | const internalVideo = videos.find(v => v.name === 'internal video becomes public') | |
242 | ||
243 | expect(privateVideo).to.not.be.undefined | |
244 | expect(internalVideo).to.not.be.undefined | |
245 | ||
246 | expect(new Date(privateVideo.publishedAt).getTime()).to.be.at.least(now) | |
247 | // We don't change the publish date of internal videos | |
248 | expect(new Date(internalVideo.publishedAt).getTime()).to.be.below(now) | |
11474c3c | 249 | |
22a73cb8 C |
250 | expect(privateVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC) |
251 | expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC) | |
11474c3c C |
252 | } |
253 | }) | |
254 | ||
22a73cb8 | 255 | it('Should set these videos as private and internal', async function () { |
46a6db24 C |
256 | this.timeout(10000) |
257 | ||
22a73cb8 C |
258 | await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE }) |
259 | await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL }) | |
46a6db24 C |
260 | |
261 | await waitJobs(servers) | |
262 | ||
263 | for (const server of servers) { | |
264 | const res = await getVideosList(server.url) | |
265 | ||
266 | expect(res.body.total).to.equal(0) | |
267 | expect(res.body.data).to.have.lengthOf(0) | |
268 | } | |
269 | ||
270 | { | |
271 | const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5) | |
22a73cb8 C |
272 | const videos = res.body.data |
273 | ||
3092e9bb LB |
274 | expect(res.body.total).to.equal(3) |
275 | expect(videos).to.have.lengthOf(3) | |
22a73cb8 C |
276 | |
277 | const privateVideo = videos.find(v => v.name === 'private video becomes public') | |
278 | const internalVideo = videos.find(v => v.name === 'internal video becomes public') | |
279 | ||
280 | expect(privateVideo).to.not.be.undefined | |
281 | expect(internalVideo).to.not.be.undefined | |
46a6db24 | 282 | |
22a73cb8 C |
283 | expect(privateVideo.privacy.id).to.equal(VideoPrivacy.INTERNAL) |
284 | expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PRIVATE) | |
46a6db24 C |
285 | } |
286 | }) | |
287 | ||
7c3b7976 C |
288 | after(async function () { |
289 | await cleanupTests(servers) | |
11474c3c C |
290 | }) |
291 | }) |