1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { FIXTURE_URLS, MockProxy } from '@server/tests/shared'
6 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
15 } from '@shared/server-commands'
17 const expect = chai.expect
19 describe('Test proxy', function () {
20 let servers: PeerTubeServer[] = []
23 const goodEnv = { HTTP_PROXY: '' }
24 const badEnv = { HTTP_PROXY: 'http://localhost:9000' }
26 before(async function () {
29 proxy = new MockProxy()
31 const proxyPort = await proxy.initialize()
32 servers = await createMultipleServers(2)
34 goodEnv.HTTP_PROXY = 'http://localhost:' + proxyPort
36 await setAccessTokensToServers(servers)
37 await setDefaultVideoChannel(servers)
38 await doubleFollow(servers[0], servers[1])
41 describe('Federation', function () {
43 it('Should succeed federation with the appropriate proxy config', async function () {
46 await servers[0].kill()
47 await servers[0].run({}, { env: goodEnv })
49 await servers[0].videos.quickUpload({ name: 'video 1' })
51 await waitJobs(servers)
53 for (const server of servers) {
54 const { total, data } = await server.videos.list()
55 expect(total).to.equal(1)
56 expect(data).to.have.lengthOf(1)
60 it('Should fail federation with a wrong proxy config', async function () {
63 await servers[0].kill()
64 await servers[0].run({}, { env: badEnv })
66 await servers[0].videos.quickUpload({ name: 'video 2' })
68 await waitJobs(servers)
71 const { total, data } = await servers[0].videos.list()
72 expect(total).to.equal(2)
73 expect(data).to.have.lengthOf(2)
77 const { total, data } = await servers[1].videos.list()
78 expect(total).to.equal(1)
79 expect(data).to.have.lengthOf(1)
84 describe('Videos import', async function () {
86 function quickImport (expectedStatus: HttpStatusCode = HttpStatusCode.OK_200) {
87 return servers[0].imports.importVideo({
90 channelId: servers[0].store.channel.id,
91 privacy: VideoPrivacy.PUBLIC,
92 targetUrl: FIXTURE_URLS.peertube_long
98 it('Should succeed import with the appropriate proxy config', async function () {
101 await servers[0].kill()
102 await servers[0].run({}, { env: goodEnv })
106 await waitJobs(servers)
108 const { total, data } = await servers[0].videos.list()
109 expect(total).to.equal(3)
110 expect(data).to.have.lengthOf(3)
113 it('Should fail import with a wrong proxy config', async function () {
116 await servers[0].kill()
117 await servers[0].run({}, { env: badEnv })
119 await quickImport(HttpStatusCode.BAD_REQUEST_400)
123 after(async function () {
124 await proxy.terminate()
126 await cleanupTests(servers)