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