1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
8 flushAndRunMultipleServers,
12 setAccessTokensToServers,
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'
21 const expect = chai.expect
23 describe('Test video privacy', function () {
24 let servers: ServerInfo[] = []
25 let privateVideoId: number
26 let privateVideoUUID: string
27 let unlistedVideoUUID: string
30 before(async function () {
34 servers = await flushAndRunMultipleServers(2)
36 // Get the access tokens
37 await setAccessTokensToServers(servers)
39 // Server 1 and server 2 follow each other
40 await doubleFollow(servers[0], servers[1])
43 it('Should upload a private video on server 1', async function () {
47 privacy: VideoPrivacy.PRIVATE
49 await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
51 await waitJobs(servers)
54 it('Should not have this private video on server 2', async function () {
55 const res = await getVideosList(servers[1].url)
57 expect(res.body.total).to.equal(0)
58 expect(res.body.data).to.have.lengthOf(0)
61 it('Should list my (private) videos', async function () {
62 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1)
64 expect(res.body.total).to.equal(1)
65 expect(res.body.data).to.have.lengthOf(1)
67 privateVideoId = res.body.data[0].id
68 privateVideoUUID = res.body.data[0].uuid
71 it('Should not be able to watch this video with non authenticated user', async function () {
72 await getVideo(servers[0].url, privateVideoUUID, 401)
75 it('Should not be able to watch this private video with another user', async function () {
80 password: 'super password'
82 await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
84 const token = await userLogin(servers[0], user)
85 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
88 it('Should be able to watch this video with the correct user', async function () {
89 await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
92 it('Should upload an unlisted video on server 2', async function () {
96 name: 'unlisted video',
97 privacy: VideoPrivacy.UNLISTED
99 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
101 // Server 2 has transcoding enabled
102 await waitJobs(servers)
105 it('Should not have this unlisted video listed on server 1 and 2', async function () {
106 for (const server of servers) {
107 const res = await getVideosList(server.url)
109 expect(res.body.total).to.equal(0)
110 expect(res.body.data).to.have.lengthOf(0)
114 it('Should list my (unlisted) videos', async function () {
115 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
117 expect(res.body.total).to.equal(1)
118 expect(res.body.data).to.have.lengthOf(1)
120 unlistedVideoUUID = res.body.data[0].uuid
123 it('Should be able to get this unlisted video', async function () {
124 for (const server of servers) {
125 const res = await getVideo(server.url, unlistedVideoUUID)
127 expect(res.body.name).to.equal('unlisted video')
131 it('Should update the private video to public on server 1', async function () {
135 name: 'super video public',
136 privacy: VideoPrivacy.PUBLIC
140 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
142 await waitJobs(servers)
145 it('Should have this new public video listed on server 1 and 2', async function () {
146 for (const server of servers) {
147 const res = await getVideosList(server.url)
149 expect(res.body.total).to.equal(1)
150 expect(res.body.data).to.have.lengthOf(1)
151 expect(res.body.data[0].name).to.equal('super video public')
152 expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
156 after(async function () {
157 await cleanupTests(servers)