]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-privacy.ts
Merge branch 'release/v1.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-privacy.ts
CommitLineData
11474c3c
C
1/* tslint:disable:no-unused-expression */
2
11474c3c 3import * as chai from 'chai'
975e6e0e 4import 'mocha'
c5d31dba 5import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
11474c3c 6import {
7c3b7976 7 cleanupTests,
975e6e0e 8 flushAndRunMultipleServers,
46a6db24 9 getVideosList, getVideosListWithToken,
975e6e0e 10 ServerInfo,
11474c3c 11 setAccessTokensToServers,
3cd0734f 12 uploadVideo
94565d52
C
13} from '../../../../shared/extra-utils/index'
14import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
15import { userLogin } from '../../../../shared/extra-utils/users/login'
16import { createUser } from '../../../../shared/extra-utils/users/users'
17import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
18import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
975e6e0e
C
19
20const expect = chai.expect
11474c3c
C
21
22describe('Test video privacy', function () {
23 let servers: ServerInfo[] = []
c49db162
C
24 let privateVideoId: number
25 let privateVideoUUID: string
26 let unlistedVideoUUID: string
27 let now: number
11474c3c
C
28
29 before(async function () {
572f8d3d 30 this.timeout(50000)
11474c3c
C
31
32 // Run servers
33 servers = await flushAndRunMultipleServers(2)
34
35 // Get the access tokens
36 await setAccessTokensToServers(servers)
37
975e6e0e
C
38 // Server 1 and server 2 follow each other
39 await doubleFollow(servers[0], servers[1])
11474c3c
C
40 })
41
975e6e0e 42 it('Should upload a private video on server 1', async function () {
572f8d3d 43 this.timeout(10000)
11474c3c
C
44
45 const attributes = {
46 privacy: VideoPrivacy.PRIVATE
47 }
48 await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
49
3cd0734f 50 await waitJobs(servers)
11474c3c
C
51 })
52
975e6e0e 53 it('Should not have this private video on server 2', async function () {
11474c3c
C
54 const res = await getVideosList(servers[1].url)
55
56 expect(res.body.total).to.equal(0)
57 expect(res.body.data).to.have.lengthOf(0)
58 })
59
60 it('Should list my (private) videos', async function () {
61 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1)
62
63 expect(res.body.total).to.equal(1)
64 expect(res.body.data).to.have.lengthOf(1)
65
66 privateVideoId = res.body.data[0].id
67 privateVideoUUID = res.body.data[0].uuid
68 })
69
70 it('Should not be able to watch this video with non authenticated user', async function () {
71 await getVideo(servers[0].url, privateVideoUUID, 401)
72 })
73
74 it('Should not be able to watch this private video with another user', async function () {
77a87fec
C
75 this.timeout(10000)
76
11474c3c
C
77 const user = {
78 username: 'hello',
79 password: 'super password'
80 }
1eddc9a7 81 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
11474c3c 82
eec63bbc 83 const token = await userLogin(servers[0], user)
11474c3c
C
84 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
85 })
86
87 it('Should be able to watch this video with the correct user', async function () {
88 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
89 })
90
9a27cdc2 91 it('Should upload an unlisted video on server 2', async function () {
572f8d3d 92 this.timeout(30000)
11474c3c
C
93
94 const attributes = {
95 name: 'unlisted video',
96 privacy: VideoPrivacy.UNLISTED
97 }
98 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
99
572f8d3d 100 // Server 2 has transcoding enabled
3cd0734f 101 await waitJobs(servers)
11474c3c
C
102 })
103
975e6e0e 104 it('Should not have this unlisted video listed on server 1 and 2', async function () {
11474c3c
C
105 for (const server of servers) {
106 const res = await getVideosList(server.url)
107
108 expect(res.body.total).to.equal(0)
109 expect(res.body.data).to.have.lengthOf(0)
110 }
111 })
112
113 it('Should list my (unlisted) videos', async function () {
114 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
115
116 expect(res.body.total).to.equal(1)
117 expect(res.body.data).to.have.lengthOf(1)
118
119 unlistedVideoUUID = res.body.data[0].uuid
120 })
121
122 it('Should be able to get this unlisted video', async function () {
123 for (const server of servers) {
124 const res = await getVideo(server.url, unlistedVideoUUID)
125
126 expect(res.body.name).to.equal('unlisted video')
127 }
128 })
129
975e6e0e 130 it('Should update the private video to public on server 1', async function () {
572f8d3d 131 this.timeout(10000)
11474c3c
C
132
133 const attribute = {
134 name: 'super video public',
135 privacy: VideoPrivacy.PUBLIC
136 }
137
c49db162 138 now = Date.now()
11474c3c
C
139 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
140
3cd0734f 141 await waitJobs(servers)
11474c3c
C
142 })
143
9a27cdc2 144 it('Should have this new public video listed on server 1 and 2', async function () {
11474c3c
C
145 for (const server of servers) {
146 const res = await getVideosList(server.url)
147
148 expect(res.body.total).to.equal(1)
149 expect(res.body.data).to.have.lengthOf(1)
150 expect(res.body.data[0].name).to.equal('super video public')
c49db162 151 expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
11474c3c
C
152 }
153 })
154
46a6db24
C
155 it('Should set this new video as private', async function () {
156 this.timeout(10000)
157
158 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.PRIVATE })
159
160 await waitJobs(servers)
161
162 for (const server of servers) {
163 const res = await getVideosList(server.url)
164
165 expect(res.body.total).to.equal(0)
166 expect(res.body.data).to.have.lengthOf(0)
167 }
168
169 {
170 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
171
172 expect(res.body.total).to.equal(1)
173 expect(res.body.data).to.have.lengthOf(1)
174 expect(res.body.data[0].name).to.equal('super video public')
175 }
176 })
177
7c3b7976
C
178 after(async function () {
179 await cleanupTests(servers)
11474c3c
C
180 })
181})