2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
import 'mocha'
|
2021-06-28 10:30:59 -05:00
|
|
|
import * as chai from 'chai'
|
2021-07-13 04:05:15 -05:00
|
|
|
import { HttpStatusCode } from '@shared/core-utils'
|
2021-07-15 03:02:54 -05:00
|
|
|
import { cleanupTests, doubleFollow, flushAndRunServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
|
|
|
|
import { VideoCreateResult, VideoPrivacy } 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 () {
|
2020-06-03 02:42:07 -05:00
|
|
|
const 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
|
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
let unlistedVideo: VideoCreateResult
|
2020-06-03 02:42:07 -05:00
|
|
|
let nonFederatedUnlistedVideoUUID: 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
|
|
|
|
2020-06-03 02:42:07 -05:00
|
|
|
const dontFederateUnlistedConfig = {
|
|
|
|
federation: {
|
|
|
|
videos: {
|
|
|
|
federate_unlisted: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2020-06-03 02:42:07 -05:00
|
|
|
servers.push(await flushAndRunServer(1, dontFederateUnlistedConfig))
|
|
|
|
servers.push(await flushAndRunServer(2))
|
2017-10-31 09:20:35 -05:00
|
|
|
|
|
|
|
// 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
|
|
|
})
|
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
describe('Private and internal videos', function () {
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should upload a private and internal videos on server 1', async function () {
|
|
|
|
this.timeout(10000)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
for (const privacy of [ VideoPrivacy.PRIVATE, VideoPrivacy.INTERNAL ]) {
|
|
|
|
const attributes = { privacy }
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.upload({ attributes })
|
2021-06-28 10:30:59 -05:00
|
|
|
}
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should not have these private and internal videos on server 2', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await servers[1].videosCommand.list()
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(0)
|
|
|
|
expect(data).to.have.lengthOf(0)
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should not list the private and internal videos for an unauthenticated user on server 1', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await servers[0].videosCommand.list()
|
2021-06-28 10:30:59 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(0)
|
|
|
|
expect(data).to.have.lengthOf(0)
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should not list the private video and list the internal video for an authenticated user on server 1', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await servers[0].videosCommand.listWithToken()
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(data[0].privacy.id).to.equal(VideoPrivacy.INTERNAL)
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should list my (private and internal) videos', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await servers[0].videosCommand.listMyVideos()
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(2)
|
|
|
|
expect(data).to.have.lengthOf(2)
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
const privateVideo = data.find(v => v.privacy.id === VideoPrivacy.PRIVATE)
|
2021-06-28 10:30:59 -05:00
|
|
|
privateVideoId = privateVideo.id
|
|
|
|
privateVideoUUID = privateVideo.uuid
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
const internalVideo = data.find(v => v.privacy.id === VideoPrivacy.INTERNAL)
|
2021-06-28 10:30:59 -05:00
|
|
|
internalVideoId = internalVideo.id
|
|
|
|
internalVideoUUID = internalVideo.uuid
|
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should not be able to watch the private/internal video with non authenticated user', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
|
|
|
await servers[0].videosCommand.get({ id: internalVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should not be able to watch the private video with another user', async function () {
|
|
|
|
this.timeout(10000)
|
2018-05-28 10:28:53 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
const user = {
|
|
|
|
username: 'hello',
|
|
|
|
password: 'super password'
|
|
|
|
}
|
2021-07-13 07:23:01 -05:00
|
|
|
await servers[0].usersCommand.create({ username: user.username, password: user.password })
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-13 04:05:15 -05:00
|
|
|
anotherUserToken = await servers[0].loginCommand.getAccessToken(user)
|
2021-07-15 03:02:54 -05:00
|
|
|
|
|
|
|
await servers[0].videosCommand.getWithToken({
|
|
|
|
token: anotherUserToken,
|
|
|
|
id: privateVideoUUID,
|
|
|
|
expectedStatus: HttpStatusCode.FORBIDDEN_403
|
|
|
|
})
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should be able to watch the internal video with another user', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.getWithToken({ token: anotherUserToken, id: internalVideoUUID })
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should be able to watch the private video with the correct user', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.getWithToken({ id: privateVideoUUID })
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
})
|
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
describe('Unlisted videos', function () {
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should upload an unlisted video on server 2', async function () {
|
|
|
|
this.timeout(60000)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
const attributes = {
|
|
|
|
name: 'unlisted video',
|
|
|
|
privacy: VideoPrivacy.UNLISTED
|
|
|
|
}
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[1].videosCommand.upload({ attributes })
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
// Server 2 has transcoding enabled
|
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should not have this unlisted video listed on server 1 and 2', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await server.videosCommand.list()
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(0)
|
|
|
|
expect(data).to.have.lengthOf(0)
|
2021-06-28 10:30:59 -05:00
|
|
|
}
|
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should list my (unlisted) videos', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await servers[1].videosCommand.listMyVideos()
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
unlistedVideo = data[0]
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should not be able to get this unlisted video using its id', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[1].videosCommand.get({ id: unlistedVideo.id, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should be able to get this unlisted video using its uuid/shortUUID', async function () {
|
|
|
|
for (const server of servers) {
|
|
|
|
for (const id of [ unlistedVideo.uuid, unlistedVideo.shortUUID ]) {
|
2021-07-15 03:02:54 -05:00
|
|
|
const video = await server.videosCommand.get({ id })
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(video.name).to.equal('unlisted video')
|
2021-06-28 10:30:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should upload a non-federating unlisted video to server 1', async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
|
|
|
const attributes = {
|
|
|
|
name: 'unlisted video',
|
|
|
|
privacy: VideoPrivacy.UNLISTED
|
|
|
|
}
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.upload({ attributes })
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should list my new unlisted video', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await servers[0].videosCommand.listMyVideos()
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(3)
|
|
|
|
expect(data).to.have.lengthOf(3)
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
nonFederatedUnlistedVideoUUID = data[0].uuid
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should be able to get non-federated unlisted video from origin', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
const video = await servers[0].videosCommand.get({ id: nonFederatedUnlistedVideoUUID })
|
2020-06-03 02:42:07 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(video.name).to.equal('unlisted video')
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not be able to get non-federated unlisted video from federated server', async function () {
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[1].videosCommand.get({ id: nonFederatedUnlistedVideoUUID, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
|
2021-06-28 10:30:59 -05:00
|
|
|
})
|
2020-06-03 02:42:07 -05:00
|
|
|
})
|
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
describe('Privacy update', function () {
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should update the private and internal videos to public on server 1', async function () {
|
|
|
|
this.timeout(10000)
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
now = Date.now()
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
{
|
2021-07-15 03:02:54 -05:00
|
|
|
const attributes = {
|
2021-06-28 10:30:59 -05:00
|
|
|
name: 'private video becomes public',
|
|
|
|
privacy: VideoPrivacy.PUBLIC
|
|
|
|
}
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.update({ id: privateVideoId, attributes })
|
2019-12-12 08:47:47 -06:00
|
|
|
}
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
{
|
2021-07-15 03:02:54 -05:00
|
|
|
const attributes = {
|
2021-06-28 10:30:59 -05:00
|
|
|
name: 'internal video becomes public',
|
|
|
|
privacy: VideoPrivacy.PUBLIC
|
|
|
|
}
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.update({ id: internalVideoId, attributes })
|
2021-06-28 10:30:59 -05:00
|
|
|
}
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
await waitJobs(servers)
|
|
|
|
})
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should have this new public video listed on server 1 and 2', async function () {
|
|
|
|
for (const server of servers) {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await server.videosCommand.list()
|
|
|
|
expect(total).to.equal(2)
|
|
|
|
expect(data).to.have.lengthOf(2)
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
const privateVideo = data.find(v => v.name === 'private video becomes public')
|
|
|
|
const internalVideo = data.find(v => v.name === 'internal video becomes public')
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
expect(privateVideo).to.not.be.undefined
|
|
|
|
expect(internalVideo).to.not.be.undefined
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
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
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
expect(privateVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC)
|
|
|
|
expect(internalVideo.privacy.id).to.equal(VideoPrivacy.PUBLIC)
|
|
|
|
}
|
|
|
|
})
|
2019-06-06 09:44:02 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
it('Should set these videos as private and internal', async function () {
|
|
|
|
this.timeout(10000)
|
2019-06-06 09:44:02 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
await servers[0].videosCommand.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } })
|
|
|
|
await servers[0].videosCommand.update({ id: privateVideoId, attributes: { privacy: VideoPrivacy.INTERNAL } })
|
2019-06-06 09:44:02 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
await waitJobs(servers)
|
2019-06-06 09:44:02 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
for (const server of servers) {
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await server.videosCommand.list()
|
2021-06-28 10:30:59 -05:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
expect(total).to.equal(0)
|
|
|
|
expect(data).to.have.lengthOf(0)
|
2021-06-28 10:30:59 -05:00
|
|
|
}
|
2019-06-06 09:44:02 -05:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
{
|
2021-07-15 03:02:54 -05:00
|
|
|
const { total, data } = await servers[0].videosCommand.listMyVideos()
|
|
|
|
expect(total).to.equal(3)
|
|
|
|
expect(data).to.have.lengthOf(3)
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-07-15 03:02:54 -05:00
|
|
|
const privateVideo = data.find(v => v.name === 'private video becomes public')
|
|
|
|
const internalVideo = data.find(v => v.name === 'internal video becomes public')
|
2019-12-12 08:47:47 -06:00
|
|
|
|
2021-06-28 10:30:59 -05:00
|
|
|
expect(privateVideo).to.not.be.undefined
|
|
|
|
expect(internalVideo).to.not.be.undefined
|
2019-06-06 09:44:02 -05:00
|
|
|
|
2021-06-28 10:30:59 -05: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
|
|
|
})
|
|
|
|
})
|