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