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