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,
16 import { doubleFollow } from '../utils/follows'
17 import { getUserAccessToken } from '../utils/login'
18 import { createUser } from '../utils/users'
19 import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../utils/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 getUserAccessToken(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 a 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)
101 it('Should not have this unlisted video listed on server 1 and 2', async function () {
102 for (const server of servers) {
103 const res = await getVideosList(server.url)
105 expect(res.body.total).to.equal(0)
106 expect(res.body.data).to.have.lengthOf(0)
110 it('Should list my (unlisted) videos', async function () {
111 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
113 expect(res.body.total).to.equal(1)
114 expect(res.body.data).to.have.lengthOf(1)
116 unlistedVideoUUID = res.body.data[0].uuid
119 it('Should be able to get this unlisted video', async function () {
120 for (const server of servers) {
121 const res = await getVideo(server.url, unlistedVideoUUID)
123 expect(res.body.name).to.equal('unlisted video')
127 it('Should update the private video to public on server 1', async function () {
131 name: 'super video public',
132 privacy: VideoPrivacy.PUBLIC
135 await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
140 it('Should not have this new unlisted video listed on server 1 and 2', async function () {
141 for (const server of servers) {
142 const res = await getVideosList(server.url)
144 expect(res.body.total).to.equal(1)
145 expect(res.body.data).to.have.lengthOf(1)
146 expect(res.body.data[0].name).to.equal('super video public')
150 after(async function () {
151 killallServers(servers)
153 // Keep the logs if the test failed