2017-10-31 09:20:35 -05:00
|
|
|
/* tslint:disable:no-unused-expression */
|
|
|
|
|
|
|
|
import * as chai from 'chai'
|
2017-11-17 05:05:59 -06:00
|
|
|
import 'mocha'
|
2017-12-28 06:59:22 -06:00
|
|
|
import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
|
2017-10-31 09:20:35 -05:00
|
|
|
import {
|
2019-04-24 08:10:37 -05:00
|
|
|
cleanupTests,
|
2017-11-17 05:05:59 -06:00
|
|
|
flushAndRunMultipleServers,
|
2019-06-06 09:44:02 -05:00
|
|
|
getVideosList, getVideosListWithToken,
|
2017-11-17 05:05:59 -06:00
|
|
|
ServerInfo,
|
2017-10-31 09:20:35 -05:00
|
|
|
setAccessTokensToServers,
|
2018-06-13 03:06:50 -05:00
|
|
|
uploadVideo
|
2019-04-15 08:26:15 -05:00
|
|
|
} from '../../../../shared/extra-utils/index'
|
|
|
|
import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
|
|
|
|
import { userLogin } from '../../../../shared/extra-utils/users/login'
|
|
|
|
import { createUser } from '../../../../shared/extra-utils/users/users'
|
|
|
|
import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../../../shared/extra-utils/videos/videos'
|
|
|
|
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
2019-12-12 08:47:47 -06:00
|
|
|
import { Video } from '@shared/models'
|
2017-11-17 05:05:59 -06:00
|
|
|
|
|
|
|
const expect = chai.expect
|
2017-10-31 09:20:35 -05:00
|
|
|
|
|
|
|
describe('Test video privacy', function () {
|
|
|
|
let servers: ServerInfo[] = []
|
2019-12-12 08:47:47 -06:00
|
|
|
let anotherUserToken: string
|
|
|
|
|
2018-04-04 03:21:36 -05:00
|
|
|
let privateVideoId: number
|
|
|
|
let privateVideoUUID: string
|
2019-12-12 08:47:47 -06:00
|
|
|
|
|
|
|
let internalVideoId: number
|
|
|
|
let internalVideoUUID: string
|
|
|
|
|
2018-04-04 03:21:36 -05:00
|
|
|
let unlistedVideoUUID: string
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2018-04-04 03:21:36 -05:00
|
|
|
let now: number
|
2017-10-31 09:20:35 -05:00
|
|
|
|
|
|
|
before(async function () {
|
2017-11-17 08:42:12 -06:00
|
|
|
this.timeout(50000)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
|
|
|
// Run servers
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
|
|
|
|
// Get the access tokens
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
// Server 1 and server 2 follow each other
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should upload a private and internal videos on server 1', async function () {
|
2017-11-17 08:42:12 -06:00
|
|
|
this.timeout(10000)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
|
|
|
|
const attributes = { privacy }
|
|
|
|
await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
|
2017-10-31 09:20:35 -05:00
|
|
|
}
|
|
|
|
|
2018-06-13 03:06:50 -05:00
|
|
|
await waitJobs(servers)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should not have these private and internal videos on server 2', async function () {
|
2017-10-31 09:20:35 -05:00
|
|
|
const res = await getVideosList(servers[1].url)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(0)
|
|
|
|
expect(res.body.data).to.have.lengthOf(0)
|
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () {
|
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(0)
|
|
|
|
expect(res.body.data).to.have.lengthOf(0)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () {
|
|
|
|
const res = await getVideosListWithToken(servers[0].url, servers[0].accessToken)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
expect(res.body.data).to.have.lengthOf(1)
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
expect(res.body.data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list my (private and internal) videos', async function () {
|
|
|
|
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 10)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
expect(res.body.data).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
|
|
|
|
const privateVideo = videos.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
|
|
|
|
privateVideoId = privateVideo.id
|
|
|
|
privateVideoUUID = privateVideo.uuid
|
|
|
|
|
|
|
|
const internalVideo = videos.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
|
|
|
|
internalVideoId = internalVideo.id
|
|
|
|
internalVideoUUID = internalVideo.uuid
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should not be able to watch the private/internal video with non authenticated user', async function () {
|
2017-10-31 09:20:35 -05:00
|
|
|
await getVideo(servers[0].url, privateVideoUUID, 401)
|
2019-12-12 08:47:47 -06:00
|
|
|
await getVideo(servers[0].url, internalVideoUUID, 401)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should not be able to watch the private video with another user', async function () {
|
2018-05-28 10:28:53 -05:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2017-10-31 09:20:35 -05:00
|
|
|
const user = {
|
|
|
|
username: 'hello',
|
|
|
|
password: 'super password'
|
|
|
|
}
|
2019-04-15 03:49:46 -05:00
|
|
|
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
anotherUserToken = await userLogin(servers[0], user)
|
|
|
|
await getVideoWithToken(servers[0].url, anotherUserToken, privateVideoUUID, 403)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should be able to watch the internal video with another user', async function () {
|
|
|
|
await getVideoWithToken(servers[0].url, anotherUserToken, internalVideoUUID, 200)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to watch the private video with the correct user', async function () {
|
|
|
|
await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID, 200)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2017-11-17 08:20:42 -06:00
|
|
|
it('Should upload an unlisted video on server 2', async function () {
|
2017-11-17 08:42:12 -06:00
|
|
|
this.timeout(30000)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
|
|
|
const attributes = {
|
|
|
|
name: 'unlisted video',
|
|
|
|
privacy: VideoPrivacy.UNLISTED
|
|
|
|
}
|
|
|
|
await uploadVideo(servers[1].url, servers[1].accessToken, attributes)
|
|
|
|
|
2017-11-17 08:42:12 -06:00
|
|
|
// Server 2 has transcoding enabled
|
2018-06-13 03:06:50 -05:00
|
|
|
await waitJobs(servers)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should not have this unlisted video listed on server 1 and 2', async function () {
|
2017-10-31 09:20:35 -05:00
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideosList(server.url)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(0)
|
|
|
|
expect(res.body.data).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list my (unlisted) videos', async function () {
|
|
|
|
const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 1)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
expect(res.body.data).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
unlistedVideoUUID = res.body.data[0].uuid
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to get this unlisted video', async function () {
|
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideo(server.url, unlistedVideoUUID)
|
|
|
|
|
|
|
|
expect(res.body.name).to.equal('unlisted video')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should update the private and internal videos to public on server 1', async function () {
|
2017-11-17 08:42:12 -06:00
|
|
|
this.timeout(10000)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
now = Date.now()
|
|
|
|
|
|
|
|
{
|
|
|
|
const attribute = {
|
|
|
|
name: 'private video becomes public',
|
|
|
|
privacy: VideoPrivacy.PUBLIC
|
|
|
|
}
|
|
|
|
|
|
|
|
await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, privateVideoId, attribute)
|
2017-10-31 09:20:35 -05:00
|
|
|
}
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
{
|
|
|
|
const attribute = {
|
|
|
|
name: 'internal video becomes public',
|
|
|
|
privacy: VideoPrivacy.PUBLIC
|
|
|
|
}
|
|
|
|
await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, internalVideoId, attribute)
|
|
|
|
}
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2018-06-13 03:06:50 -05:00
|
|
|
await waitJobs(servers)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2017-11-17 08:20:42 -06:00
|
|
|
it('Should have this new public video listed on server 1 and 2', async function () {
|
2017-10-31 09:20:35 -05:00
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideosList(server.url)
|
2019-12-12 08:47:47 -06:00
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
expect(res.body.data).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const videos: Video[] = res.body.data
|
|
|
|
const privateVideo = videos.find(v => v.name === 'private video becomes public')
|
|
|
|
const internalVideo = videos.find(v => v.name === 'internal video becomes public')
|
|
|
|
|
|
|
|
expect(privateVideo).to.not.be.undefined
|
|
|
|
expect(internalVideo).to.not.be.undefined
|
|
|
|
|
|
|
|
expect(new Date(privateVideo.publishedAt).getTime()).to.be.at.least(now)
|
|
|
|
// We don't change the publish date of internal videos
|
|
|
|
expect(new Date(internalVideo.publishedAt).getTime()).to.be.below(now)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
expect(privateVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC)
|
|
|
|
expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC)
|
2017-10-31 09:20:35 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
it('Should set these videos as private and internal', async function () {
|
2019-06-06 09:44:02 -05:00
|
|
|
this.timeout(10000)
|
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
await updateVideo(servers[0].url, servers[0].accessToken, internalVideoId, { privacy: VideoPrivacy.PRIVATE })
|
|
|
|
await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, { privacy: VideoPrivacy.INTERNAL })
|
2019-06-06 09:44:02 -05:00
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const res = await getVideosList(server.url)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(0)
|
|
|
|
expect(res.body.data).to.have.lengthOf(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
|
2019-12-12 08:47:47 -06:00
|
|
|
const videos = res.body.data
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const privateVideo = videos.find(v => v.name === 'private video becomes public')
|
|
|
|
const internalVideo = videos.find(v => v.name === 'internal video becomes public')
|
|
|
|
|
|
|
|
expect(privateVideo).to.not.be.undefined
|
|
|
|
expect(internalVideo).to.not.be.undefined
|
2019-06-06 09:44:02 -05:00
|
|
|
|
2019-12-12 08:47:47 -06:00
|
|
|
expect(privateVideo.privacy.id).to.equal(VideoPrivacy.INTERNAL)
|
|
|
|
expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PRIVATE)
|
2019-06-06 09:44:02 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 08:10:37 -05:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
})
|