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