]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/video-privacy.ts
Design confirm dialog
[github/Chocobozzz/PeerTube.git] / server / tests / api / video-privacy.ts
CommitLineData
11474c3c
C
1/* tslint:disable:no-unused-expression */
2
11474c3c 3import * as chai from 'chai'
975e6e0e
C
4import 'mocha'
5import { VideoPrivacy } from '../../../shared/models/videos/video-privacy.enum'
11474c3c 6import {
975e6e0e 7 flushAndRunMultipleServers,
11474c3c 8 flushTests,
11474c3c 9 getVideosList,
975e6e0e
C
10 killallServers,
11 ServerInfo,
11474c3c 12 setAccessTokensToServers,
975e6e0e
C
13 uploadVideo,
14 wait
11474c3c 15} from '../utils'
975e6e0e 16import { doubleFollow } from '../utils/follows'
11474c3c 17import { getUserAccessToken } from '../utils/login'
975e6e0e
C
18import { createUser } from '../utils/users'
19import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../utils/videos'
20
21const expect = chai.expect
11474c3c
C
22
23describe('Test video privacy', function () {
24 let servers: ServerInfo[] = []
25 let privateVideoId
26 let privateVideoUUID
27 let unlistedVideoUUID
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
572f8d3d 50 await wait(5000)
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 () {
75 const user = {
76 username: 'hello',
77 password: 'super password'
78 }
79 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
80
81 const token = await getUserAccessToken(servers[0], user)
82 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
83 })
84
85 it('Should be able to watch this video with the correct user', async function () {
86 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
87 })
88
9a27cdc2 89 it('Should upload an unlisted video on server 2', async function () {
572f8d3d 90 this.timeout(30000)
11474c3c
C
91
92 const attributes = {
93 name: 'unlisted video',
94 privacy: VideoPrivacy.UNLISTED
95 }
96 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
97
572f8d3d
C
98 // Server 2 has transcoding enabled
99 await wait(10000)
11474c3c
C
100 })
101
975e6e0e 102 it('Should not have this unlisted video listed on server 1 and 2', async function () {
11474c3c
C
103 for (const server of servers) {
104 const res = await getVideosList(server.url)
105
106 expect(res.body.total).to.equal(0)
107 expect(res.body.data).to.have.lengthOf(0)
108 }
109 })
110
111 it('Should list my (unlisted) videos', async function () {
112 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
113
114 expect(res.body.total).to.equal(1)
115 expect(res.body.data).to.have.lengthOf(1)
116
117 unlistedVideoUUID = res.body.data[0].uuid
118 })
119
120 it('Should be able to get this unlisted video', async function () {
121 for (const server of servers) {
122 const res = await getVideo(server.url, unlistedVideoUUID)
123
124 expect(res.body.name).to.equal('unlisted video')
125 }
126 })
127
975e6e0e 128 it('Should update the private video to public on server 1', async function () {
572f8d3d 129 this.timeout(10000)
11474c3c
C
130
131 const attribute = {
132 name: 'super video public',
133 privacy: VideoPrivacy.PUBLIC
134 }
135
136 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
137
572f8d3d 138 await wait(5000)
11474c3c
C
139 })
140
9a27cdc2 141 it('Should have this new public 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(1)
146 expect(res.body.data).to.have.lengthOf(1)
147 expect(res.body.data[0].name).to.equal('super video public')
148 }
149 })
150
151 after(async function () {
152 killallServers(servers)
153
154 // Keep the logs if the test failed
155 if (this['ok']) {
156 await flushTests()
157 }
158 })
159})