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
|
|
|
|
2022-08-17 08:44:32 -05:00
|
|
|
import { expect } from 'chai'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { wait } from '@shared/core-utils'
|
2021-07-16 07:27:30 -05:00
|
|
|
import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
|
2021-12-17 04:58:15 -06:00
|
|
|
import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands'
|
2017-11-17 05:05:59 -06:00
|
|
|
|
2017-10-31 09:20:35 -05:00
|
|
|
describe('Test video privacy', function () {
|
2021-07-16 02:47:51 -05:00
|
|
|
const servers: PeerTubeServer[] = []
|
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
|
2021-07-16 02:47:51 -05:00
|
|
|
servers.push(await createSingleServer(1, dontFederateUnlistedConfig))
|
|
|
|
servers.push(await createSingleServer(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 () {
|
2022-09-28 01:24:18 -05:00
|
|
|
this.timeout(50000)
|
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-16 02:04:35 -05:00
|
|
|
await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await servers[1].videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
await servers[0].videos.get({ id: privateVideoUUID, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
|
|
|
|
await servers[0].videos.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 () {
|
|
|
|
const user = {
|
|
|
|
username: 'hello',
|
|
|
|
password: 'super password'
|
|
|
|
}
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].users.create({ username: user.username, password: user.password })
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
anotherUserToken = await servers[0].login.getAccessToken(user)
|
2021-07-15 03:02:54 -05:00
|
|
|
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].videos.getWithToken({
|
2021-07-15 03:02:54 -05:00
|
|
|
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-16 02:04:35 -05:00
|
|
|
await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
await servers[0].videos.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 () {
|
2022-10-24 07:54:21 -05:00
|
|
|
this.timeout(120000)
|
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-16 02:04:35 -05:00
|
|
|
await servers[1].videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await server.videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await servers[1].videos.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 () {
|
2022-06-22 07:03:50 -05:00
|
|
|
await servers[1].videos.get({ id: unlistedVideo.id, 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 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-16 02:04:35 -05:00
|
|
|
const video = await server.videos.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-16 02:04:35 -05:00
|
|
|
await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
const video = await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
await servers[1].videos.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 () {
|
2021-12-09 08:44:54 -06:00
|
|
|
this.timeout(100000)
|
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-16 02:04:35 -05:00
|
|
|
await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
await servers[0].videos.update({ id: internalVideoId, attributes })
|
2021-06-28 10:30:59 -05:00
|
|
|
}
|
2017-10-31 09:20:35 -05:00
|
|
|
|
2021-12-09 08:44:54 -06:00
|
|
|
await wait(10000)
|
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-16 02:04:35 -05:00
|
|
|
const { total, data } = await server.videos.list()
|
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.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 () {
|
2021-07-16 02:04:35 -05:00
|
|
|
await servers[0].videos.update({ id: internalVideoId, attributes: { privacy: VideoPrivacy.PRIVATE } })
|
|
|
|
await servers[0].videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await server.videos.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-16 02:04:35 -05:00
|
|
|
const { total, data } = await servers[0].videos.listMyVideos()
|
2021-07-15 03:02:54 -05:00
|
|
|
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
|
|
|
})
|
|
|
|
})
|