2020-01-31 15:56:52 +00:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-11-16 14:02:48 +00:00
|
|
|
|
|
|
|
import 'mocha'
|
2021-07-07 07:16:40 +00:00
|
|
|
import * as chai from 'chai'
|
|
|
|
import { HttpStatusCode } from '@shared/core-utils'
|
2021-07-15 08:02:54 +00:00
|
|
|
import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers } from '@shared/extra-utils'
|
2021-07-07 07:16:40 +00:00
|
|
|
import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
|
2018-11-16 14:02:48 +00:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
describe('Test follow constraints', function () {
|
|
|
|
let servers: ServerInfo[] = []
|
|
|
|
let video1UUID: string
|
|
|
|
let video2UUID: string
|
2021-07-15 08:02:54 +00:00
|
|
|
let userToken: string
|
2018-11-16 14:02:48 +00:00
|
|
|
|
|
|
|
before(async function () {
|
2021-05-10 11:56:26 +00:00
|
|
|
this.timeout(90000)
|
2018-11-16 14:02:48 +00:00
|
|
|
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
|
|
|
|
// Get the access tokens
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
{
|
2021-07-15 08:02:54 +00:00
|
|
|
const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'video server 1' } })
|
|
|
|
video1UUID = uuid
|
2018-11-16 14:02:48 +00:00
|
|
|
}
|
|
|
|
{
|
2021-07-15 08:02:54 +00:00
|
|
|
const { uuid } = await servers[1].videosCommand.upload({ attributes: { name: 'video server 2' } })
|
|
|
|
video2UUID = uuid
|
2018-11-16 14:02:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const user = {
|
|
|
|
username: 'user1',
|
|
|
|
password: 'super_password'
|
|
|
|
}
|
2021-07-13 12:23:01 +00:00
|
|
|
await servers[0].usersCommand.create({ username: user.username, password: user.password })
|
2021-07-15 08:02:54 +00:00
|
|
|
userToken = await servers[0].loginCommand.getAccessToken(user)
|
2018-11-16 14:02:48 +00:00
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('With a followed instance', function () {
|
|
|
|
|
|
|
|
describe('With an unlogged user', function () {
|
|
|
|
|
|
|
|
it('Should get the local video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
await servers[0].videosCommand.get({ id: video1UUID })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get the remote video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
await servers[0].videosCommand.get({ id: video2UUID })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[0].port })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list remote account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({ accountName: 'root@localhost:' + servers[1].port })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[0].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list remote channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[1].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('With a logged user', function () {
|
|
|
|
it('Should get the local video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get the remote video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list remote account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[0].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list remote channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[1].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('With a non followed instance', function () {
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2021-07-07 07:16:40 +00:00
|
|
|
await servers[0].followsCommand.unfollow({ target: servers[1] })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('With an unlogged user', function () {
|
|
|
|
|
|
|
|
it('Should get the local video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
await servers[0].videosCommand.get({ id: video1UUID })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not get the remote video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const body = await servers[0].videosCommand.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
|
|
|
const error = body as unknown as PeerTubeProblemDocument
|
2021-06-02 16:15:41 +00:00
|
|
|
|
|
|
|
const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
|
|
|
|
expect(error.type).to.equal(doc)
|
|
|
|
expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
|
|
|
|
|
|
|
|
expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
|
|
|
|
expect(error.error).to.equal(error.detail)
|
|
|
|
|
|
|
|
expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
|
|
|
|
|
|
|
|
expect(error.originUrl).to.contains(servers[1].url)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({
|
|
|
|
token: undefined,
|
|
|
|
accountName: 'root@localhost:' + servers[0].port
|
|
|
|
})
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not list remote account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({
|
|
|
|
token: undefined,
|
|
|
|
accountName: 'root@localhost:' + servers[1].port
|
|
|
|
})
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(0)
|
|
|
|
expect(data).to.have.lengthOf(0)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[0].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should not list remote channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[1].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ token: undefined, videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(0)
|
|
|
|
expect(data).to.have.lengthOf(0)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('With a logged user', function () {
|
|
|
|
it('Should get the local video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
await servers[0].videosCommand.getWithToken({ token: userToken, id: video1UUID })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get the remote video', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
await servers[0].videosCommand.getWithToken({ token: userToken, id: video2UUID })
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[0].port })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list remote account videos', async function () {
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByAccount({ token: userToken, accountName: 'root@localhost:' + servers[1].port })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list local channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[0].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should list remote channel videos', async function () {
|
2019-04-25 15:14:49 +00:00
|
|
|
const videoChannelName = 'root_channel@localhost:' + servers[1].port
|
2021-07-15 08:02:54 +00:00
|
|
|
const { total, data } = await servers[0].videosCommand.listByChannel({ token: userToken, videoChannelName })
|
2018-11-16 14:02:48 +00:00
|
|
|
|
2021-07-15 08:02:54 +00:00
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-04-24 13:10:37 +00:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-11-16 14:02:48 +00:00
|
|
|
})
|
|
|
|
})
|