1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
7 flushAndRunMultipleServers,
12 setAccessTokensToServers,
15 } from '../../utils/index'
16 import { doubleFollow } from '../../utils/server/follows'
17 import { userLogin } from '../../utils/users/login'
18 import { createUser } from '../../utils/users/users'
19 import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos'
21 const expect = chai.expect
23 describe('Test video privacy', function () {
24 let servers: ServerInfo[] = []
29 before(async function () {
33 servers = await flushAndRunMultipleServers(2)
35 // Get the access tokens
36 await setAccessTokensToServers(servers)
38 // Server 1 and server 2 follow each other
39 await doubleFollow(servers[0], servers[1])
42 it('Should upload a private video on server 1', async function () {
46 privacy: VideoPrivacy.PRIVATE
48 await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
53 it('Should not have this private video on server 2', async function () {
54 const res = await getVideosList(servers[1].url)
56 expect(res.body.total).to.equal(0)
57 expect(res.body.data).to.have.lengthOf(0)
60 it('Should list my (private) videos', async function () {
61 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1)
63 expect(res.body.total).to.equal(1)
64 expect(res.body.data).to.have.lengthOf(1)
66 privateVideoId = res.body.data[0].id
67 privateVideoUUID = res.body.data[0].uuid
70 it('Should not be able to watch this video with non authenticated user', async function () {
71 await getVideo(servers[0].url, privateVideoUUID, 401)
74 it('Should not be able to watch this private video with another user', async function () {
77 password: 'super password'
79 await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
81 const token = await userLogin(servers[0], user)
82 await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
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)
89 it('Should upload an unlisted video on server 2', async function () {
93 name: 'unlisted video',
94 privacy: VideoPrivacy.UNLISTED
96 await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
98 // Server 2 has transcoding enabled
102 it('Should not have this unlisted video listed on server 1 and 2', async function () {
103 for (const server of servers) {
104 const res = await getVideosList(server.url)
106 expect(res.body.total).to.equal(0)
107 expect(res.body.data).to.have.lengthOf(0)
111 it('Should list my (unlisted) videos', async function () {
112 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
114 expect(res.body.total).to.equal(1)
115 expect(res.body.data).to.have.lengthOf(1)
117 unlistedVideoUUID = res.body.data[0].uuid
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)
124 expect(res.body.name).to.equal('unlisted video')
128 it('Should update the private video to public on server 1', async function () {
132 name: 'super video public',
133 privacy: VideoPrivacy.PUBLIC
136 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
141 it('Should have this new public video listed on server 1 and 2', async function () {
142 for (const server of servers) {
143 const res = await getVideosList(server.url)
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')
151 after(async function () {
152 killallServers(servers)
154 // Keep the logs if the test failed