PeerTube/server/tests/api/server/follow-constraints.ts

239 lines
8.2 KiB
TypeScript
Raw Normal View History

2020-01-31 16:56:52 +01:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
2021-07-07 09:16:40 +02:00
import * as chai from 'chai'
import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
2021-07-16 14:27:30 +02:00
import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
const expect = chai.expect
describe('Test follow constraints', function () {
2021-07-16 09:47:51 +02:00
let servers: PeerTubeServer[] = []
let video1UUID: string
let video2UUID: string
2021-07-15 10:02:54 +02:00
let userToken: string
before(async function () {
2021-12-28 15:07:46 +01:00
this.timeout(240000)
2021-07-16 09:47:51 +02:00
servers = await createMultipleServers(2)
// Get the access tokens
await setAccessTokensToServers(servers)
{
2021-07-16 09:04:35 +02:00
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video server 1' } })
2021-07-15 10:02:54 +02:00
video1UUID = uuid
}
{
2021-07-16 09:04:35 +02:00
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video server 2' } })
2021-07-15 10:02:54 +02:00
video2UUID = uuid
}
const user = {
username: 'user1',
password: 'super_password'
}
2021-07-16 09:04:35 +02:00
await servers[0].users.create({ username: user.username, password: user.password })
userToken = await servers[0].login.getAccessToken(user)
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-16 09:04:35 +02:00
await servers[0].videos.get({ id: video1UUID })
})
it('Should get the remote video', async function () {
2021-07-16 09:04:35 +02:00
await servers[0].videos.get({ id: video2UUID })
})
it('Should list local account videos', async function () {
2021-07-16 10:42:24 +02:00
const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[0].port })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
2021-07-16 10:42:24 +02:00
const { total, data } = await servers[0].videos.listByAccount({ handle: 'root@localhost:' + servers[1].port })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[0].port
const { total, data } = await servers[0].videos.listByChannel({ handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[1].port
const { total, data } = await servers[0].videos.listByChannel({ handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
})
describe('With a logged user', function () {
it('Should get the local video', async function () {
2021-07-16 09:04:35 +02:00
await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
})
it('Should get the remote video', async function () {
2021-07-16 09:04:35 +02:00
await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
})
it('Should list local account videos', async function () {
2021-07-16 10:42:24 +02:00
const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
2021-07-16 10:42:24 +02:00
const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[0].port
const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[1].port
const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
})
})
describe('With a non followed instance', function () {
before(async function () {
this.timeout(30000)
2021-07-16 09:04:35 +02:00
await servers[0].follows.unfollow({ target: servers[1] })
})
describe('With an unlogged user', function () {
it('Should get the local video', async function () {
2021-07-16 09:04:35 +02:00
await servers[0].videos.get({ id: video1UUID })
})
it('Should not get the remote video', async function () {
2021-07-16 09:04:35 +02:00
const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
2021-07-15 10:02:54 +02:00
const error = body as unknown as PeerTubeProblemDocument
2021-06-02 18:15:41 +02: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)
})
it('Should list local account videos', async function () {
2021-07-16 09:04:35 +02:00
const { total, data } = await servers[0].videos.listByAccount({
2021-07-16 14:27:30 +02:00
token: null,
2021-07-16 10:42:24 +02:00
handle: 'root@localhost:' + servers[0].port
2021-07-15 10:02:54 +02:00
})
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should not list remote account videos', async function () {
2021-07-16 09:04:35 +02:00
const { total, data } = await servers[0].videos.listByAccount({
2021-07-16 14:27:30 +02:00
token: null,
2021-07-16 10:42:24 +02:00
handle: 'root@localhost:' + servers[1].port
2021-07-15 10:02:54 +02:00
})
2021-07-15 10:02:54 +02:00
expect(total).to.equal(0)
expect(data).to.have.lengthOf(0)
})
it('Should list local channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[0].port
2021-07-16 14:27:30 +02:00
const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should not list remote channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[1].port
2021-07-16 14:27:30 +02:00
const { total, data } = await servers[0].videos.listByChannel({ token: null, handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(0)
expect(data).to.have.lengthOf(0)
})
})
describe('With a logged user', function () {
it('Should get the local video', async function () {
2021-07-16 09:04:35 +02:00
await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
})
it('Should get the remote video', async function () {
2021-07-16 09:04:35 +02:00
await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
})
it('Should list local account videos', async function () {
2021-07-16 10:42:24 +02:00
const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[0].port })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list remote account videos', async function () {
2021-07-16 10:42:24 +02:00
const { total, data } = await servers[0].videos.listByAccount({ token: userToken, handle: 'root@localhost:' + servers[1].port })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list local channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[0].port
const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
it('Should list remote channel videos', async function () {
2021-07-16 10:42:24 +02:00
const handle = 'root_channel@localhost:' + servers[1].port
const { total, data } = await servers[0].videos.listByChannel({ token: userToken, handle })
2021-07-15 10:02:54 +02:00
expect(total).to.equal(1)
expect(data).to.have.lengthOf(1)
})
})
})
2019-04-24 15:10:37 +02:00
after(async function () {
await cleanupTests(servers)
})
})