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 {
|
2017-11-17 05:05:59 -06:00
|
|
|
flushAndRunMultipleServers,
|
2017-10-31 09:20:35 -05:00
|
|
|
flushTests,
|
|
|
|
getVideosList,
|
2017-11-17 05:05:59 -06:00
|
|
|
killallServers,
|
|
|
|
ServerInfo,
|
2017-10-31 09:20:35 -05:00
|
|
|
setAccessTokensToServers,
|
2017-11-17 05:05:59 -06:00
|
|
|
uploadVideo,
|
|
|
|
wait
|
2017-12-28 06:59:22 -06:00
|
|
|
} from '../../utils/index'
|
|
|
|
import { doubleFollow } from '../../utils/server/follows'
|
2017-12-28 07:29:57 -06:00
|
|
|
import { userLogin } from '../../utils/users/login'
|
2017-12-28 06:59:22 -06:00
|
|
|
import { createUser } from '../../utils/users/users'
|
|
|
|
import { getMyVideos, getVideo, getVideoWithToken, updateVideo } from '../../utils/videos/videos'
|
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[] = []
|
2018-04-04 03:21:36 -05:00
|
|
|
let privateVideoId: number
|
|
|
|
let privateVideoUUID: string
|
|
|
|
let unlistedVideoUUID: string
|
|
|
|
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
|
|
|
})
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should upload a private video on server 1', async function () {
|
2017-11-17 08:42:12 -06:00
|
|
|
this.timeout(10000)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
|
|
|
const attributes = {
|
|
|
|
privacy: VideoPrivacy.PRIVATE
|
|
|
|
}
|
|
|
|
await uploadVideo(servers[0].url, servers[0].accessToken, attributes)
|
|
|
|
|
2017-11-17 08:42:12 -06:00
|
|
|
await wait(5000)
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should not have this private video 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)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list my (private) videos', async function () {
|
|
|
|
const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 1)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
expect(res.body.data).to.have.lengthOf(1)
|
|
|
|
|
|
|
|
privateVideoId = res.body.data[0].id
|
|
|
|
privateVideoUUID = res.body.data[0].uuid
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to watch this video with non authenticated user', async function () {
|
|
|
|
await getVideo(servers[0].url, privateVideoUUID, 401)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to watch this private video with another user', async function () {
|
|
|
|
const user = {
|
|
|
|
username: 'hello',
|
|
|
|
password: 'super password'
|
|
|
|
}
|
|
|
|
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
|
|
|
|
|
2017-12-28 07:29:57 -06:00
|
|
|
const token = await userLogin(servers[0], user)
|
2017-10-31 09:20:35 -05:00
|
|
|
await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should be able to watch this video with the correct user', async function () {
|
|
|
|
await getVideoWithToken(servers[0].url, servers[0].accessToken, privateVideoUUID)
|
|
|
|
})
|
|
|
|
|
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
|
|
|
|
await wait(10000)
|
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')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should update the private video 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
|
|
|
|
|
|
|
const attribute = {
|
|
|
|
name: 'super video public',
|
|
|
|
privacy: VideoPrivacy.PUBLIC
|
|
|
|
}
|
|
|
|
|
2018-04-04 03:21:36 -05:00
|
|
|
now = Date.now()
|
2017-10-31 09:20:35 -05:00
|
|
|
await updateVideo(servers[0].url, servers[0].accessToken, privateVideoId, attribute)
|
|
|
|
|
2017-11-17 08:42:12 -06:00
|
|
|
await wait(5000)
|
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)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
expect(res.body.data).to.have.lengthOf(1)
|
|
|
|
expect(res.body.data[0].name).to.equal('super video public')
|
2018-04-04 03:21:36 -05:00
|
|
|
expect(new Date(res.body.data[0].publishedAt).getTime()).to.be.at.least(now)
|
2017-10-31 09:20:35 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
killallServers(servers)
|
|
|
|
|
|
|
|
// Keep the logs if the test failed
|
|
|
|
if (this['ok']) {
|
|
|
|
await flushTests()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|