2021-08-25 15:08:37 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
|
|
|
|
2022-08-17 15:44:32 +02:00
|
|
|
import { expect } from 'chai'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { HttpStatusCode, HttpStatusCodeType, VideoPrivacy } from '@peertube/peertube-models'
|
|
|
|
import { areMockObjectStorageTestsDisabled } from '@peertube/peertube-node-utils'
|
2021-10-21 16:28:39 +02:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
2022-05-09 11:49:25 +02:00
|
|
|
ObjectStorageCommand,
|
2021-10-21 16:28:39 +02:00
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
setDefaultVideoChannel,
|
|
|
|
waitJobs
|
2023-07-31 14:34:36 +02:00
|
|
|
} from '@peertube/peertube-server-commands'
|
|
|
|
import { FIXTURE_URLS } from '@tests/shared/tests.js'
|
|
|
|
import { expectStartWith, expectNotStartWith } from '@tests/shared/checks.js'
|
|
|
|
import { MockProxy } from '@tests/shared/mock-servers/mock-proxy.js'
|
2021-08-25 15:08:37 +02:00
|
|
|
|
|
|
|
describe('Test proxy', function () {
|
|
|
|
let servers: PeerTubeServer[] = []
|
|
|
|
let proxy: MockProxy
|
|
|
|
|
|
|
|
const goodEnv = { HTTP_PROXY: '' }
|
2022-12-09 11:14:47 +01:00
|
|
|
const badEnv = { HTTP_PROXY: 'http://127.0.0.1:9000' }
|
2021-08-25 15:08:37 +02:00
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
proxy = new MockProxy()
|
|
|
|
|
|
|
|
const proxyPort = await proxy.initialize()
|
|
|
|
servers = await createMultipleServers(2)
|
|
|
|
|
2022-12-09 11:14:47 +01:00
|
|
|
goodEnv.HTTP_PROXY = 'http://127.0.0.1:' + proxyPort
|
2021-08-25 15:08:37 +02:00
|
|
|
|
|
|
|
await setAccessTokensToServers(servers)
|
2021-10-21 16:28:39 +02:00
|
|
|
await setDefaultVideoChannel(servers)
|
2021-08-25 15:08:37 +02:00
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
})
|
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
describe('Federation', function () {
|
2021-08-25 15:08:37 +02:00
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
it('Should succeed federation with the appropriate proxy config', async function () {
|
|
|
|
this.timeout(40000)
|
2021-08-25 15:08:37 +02:00
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
await servers[0].kill()
|
|
|
|
await servers[0].run({}, { env: goodEnv })
|
2021-08-25 15:08:37 +02:00
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
await servers[0].videos.quickUpload({ name: 'video 1' })
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const { total, data } = await server.videos.list()
|
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail federation with a wrong proxy config', async function () {
|
|
|
|
this.timeout(40000)
|
|
|
|
|
|
|
|
await servers[0].kill()
|
|
|
|
await servers[0].run({}, { env: badEnv })
|
|
|
|
|
|
|
|
await servers[0].videos.quickUpload({ name: 'video 2' })
|
|
|
|
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
{
|
|
|
|
const { total, data } = await servers[0].videos.list()
|
|
|
|
expect(total).to.equal(2)
|
|
|
|
expect(data).to.have.lengthOf(2)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
const { total, data } = await servers[1].videos.list()
|
|
|
|
expect(total).to.equal(1)
|
|
|
|
expect(data).to.have.lengthOf(1)
|
|
|
|
}
|
|
|
|
})
|
2021-08-25 15:08:37 +02:00
|
|
|
})
|
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
describe('Videos import', async function () {
|
|
|
|
|
2023-07-31 14:34:36 +02:00
|
|
|
function quickImport (expectedStatus: HttpStatusCodeType = HttpStatusCode.OK_200) {
|
2024-02-12 10:49:45 +01:00
|
|
|
return servers[0].videoImports.importVideo({
|
2021-10-21 16:28:39 +02:00
|
|
|
attributes: {
|
|
|
|
name: 'video import',
|
|
|
|
channelId: servers[0].store.channel.id,
|
|
|
|
privacy: VideoPrivacy.PUBLIC,
|
|
|
|
targetUrl: FIXTURE_URLS.peertube_long
|
|
|
|
},
|
|
|
|
expectedStatus
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
it('Should succeed import with the appropriate proxy config', async function () {
|
2023-01-27 09:04:02 +01:00
|
|
|
this.timeout(240000)
|
2021-10-21 16:28:39 +02:00
|
|
|
|
|
|
|
await servers[0].kill()
|
|
|
|
await servers[0].run({}, { env: goodEnv })
|
2021-08-25 15:08:37 +02:00
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
await quickImport()
|
2021-08-25 15:08:37 +02:00
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
await waitJobs(servers)
|
2021-08-25 15:08:37 +02:00
|
|
|
|
|
|
|
const { total, data } = await servers[0].videos.list()
|
2021-10-21 16:28:39 +02:00
|
|
|
expect(total).to.equal(3)
|
|
|
|
expect(data).to.have.lengthOf(3)
|
|
|
|
})
|
2021-08-25 15:08:37 +02:00
|
|
|
|
2021-10-21 16:28:39 +02:00
|
|
|
it('Should fail import with a wrong proxy config', async function () {
|
2022-01-03 11:01:39 +01:00
|
|
|
this.timeout(120000)
|
2021-10-21 16:28:39 +02:00
|
|
|
|
|
|
|
await servers[0].kill()
|
|
|
|
await servers[0].run({}, { env: badEnv })
|
|
|
|
|
|
|
|
await quickImport(HttpStatusCode.BAD_REQUEST_400)
|
|
|
|
})
|
2021-08-25 15:08:37 +02:00
|
|
|
})
|
|
|
|
|
2022-05-09 11:49:25 +02:00
|
|
|
describe('Object storage', function () {
|
2022-10-19 10:43:53 +02:00
|
|
|
if (areMockObjectStorageTestsDisabled()) return
|
2022-05-09 11:49:25 +02:00
|
|
|
|
2023-05-23 10:49:45 +02:00
|
|
|
const objectStorage = new ObjectStorageCommand()
|
|
|
|
|
2022-05-09 11:49:25 +02:00
|
|
|
before(async function () {
|
|
|
|
this.timeout(30000)
|
|
|
|
|
2023-05-23 10:49:45 +02:00
|
|
|
await objectStorage.prepareDefaultMockBuckets()
|
2022-05-09 11:49:25 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed to upload to object storage with the appropriate proxy config', async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
await servers[0].kill()
|
2023-05-23 10:49:45 +02:00
|
|
|
await servers[0].run(objectStorage.getDefaultMockConfig(), { env: goodEnv })
|
2022-05-09 11:49:25 +02:00
|
|
|
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
|
|
|
|
await waitJobs(servers)
|
|
|
|
|
|
|
|
const video = await servers[0].videos.get({ id: uuid })
|
|
|
|
|
2023-05-23 10:49:45 +02:00
|
|
|
expectStartWith(video.files[0].fileUrl, objectStorage.getMockWebVideosBaseUrl())
|
2022-05-09 11:49:25 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should fail to upload to object storage with a wrong proxy config', async function () {
|
|
|
|
this.timeout(120000)
|
|
|
|
|
|
|
|
await servers[0].kill()
|
2023-05-23 10:49:45 +02:00
|
|
|
await servers[0].run(objectStorage.getDefaultMockConfig(), { env: badEnv })
|
2022-05-09 11:49:25 +02:00
|
|
|
|
|
|
|
const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
|
2022-10-25 15:01:51 +02:00
|
|
|
await waitJobs(servers, { skipDelayed: true })
|
2022-05-09 11:49:25 +02:00
|
|
|
|
|
|
|
const video = await servers[0].videos.get({ id: uuid })
|
|
|
|
|
2023-05-23 10:49:45 +02:00
|
|
|
expectNotStartWith(video.files[0].fileUrl, objectStorage.getMockWebVideosBaseUrl())
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await objectStorage.cleanupMock()
|
2022-05-09 11:49:25 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-08-25 15:08:37 +02:00
|
|
|
after(async function () {
|
2021-09-06 08:13:11 +02:00
|
|
|
await proxy.terminate()
|
2021-08-25 15:08:37 +02:00
|
|
|
|
|
|
|
await cleanupTests(servers)
|
|
|
|
})
|
|
|
|
})
|