1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
14 } from '@shared/extra-utils'
15 import { MockProxy } from '@shared/extra-utils/mock-servers/mock-proxy'
16 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
18 const expect = chai.expect
20 describe('Test proxy', function () {
21 let servers: PeerTubeServer[] = []
24 const goodEnv = { HTTP_PROXY: '' }
25 const badEnv = { HTTP_PROXY: 'http://localhost:9000' }
27 before(async function () {
30 proxy = new MockProxy()
32 const proxyPort = await proxy.initialize()
33 servers = await createMultipleServers(2)
35 goodEnv.HTTP_PROXY = 'http://localhost:' + proxyPort
37 await setAccessTokensToServers(servers)
38 await setDefaultVideoChannel(servers)
39 await doubleFollow(servers[0], servers[1])
42 describe('Federation', function () {
44 it('Should succeed federation with the appropriate proxy config', async function () {
47 await servers[0].kill()
48 await servers[0].run({}, { env: goodEnv })
50 await servers[0].videos.quickUpload({ name: 'video 1' })
52 await waitJobs(servers)
54 for (const server of servers) {
55 const { total, data } = await server.videos.list()
56 expect(total).to.equal(1)
57 expect(data).to.have.lengthOf(1)
61 it('Should fail federation with a wrong proxy config', async function () {
64 await servers[0].kill()
65 await servers[0].run({}, { env: badEnv })
67 await servers[0].videos.quickUpload({ name: 'video 2' })
69 await waitJobs(servers)
72 const { total, data } = await servers[0].videos.list()
73 expect(total).to.equal(2)
74 expect(data).to.have.lengthOf(2)
78 const { total, data } = await servers[1].videos.list()
79 expect(total).to.equal(1)
80 expect(data).to.have.lengthOf(1)
85 describe('Videos import', async function () {
87 function quickImport (expectedStatus: HttpStatusCode = HttpStatusCode.OK_200) {
88 return servers[0].imports.importVideo({
91 channelId: servers[0].store.channel.id,
92 privacy: VideoPrivacy.PUBLIC,
93 targetUrl: FIXTURE_URLS.peertube_long
99 it('Should succeed import with the appropriate proxy config', async function () {
102 await servers[0].kill()
103 await servers[0].run({}, { env: goodEnv })
107 await waitJobs(servers)
109 const { total, data } = await servers[0].videos.list()
110 expect(total).to.equal(3)
111 expect(data).to.have.lengthOf(3)
114 it('Should fail import with a wrong proxy config', async function () {
117 await servers[0].kill()
118 await servers[0].run({}, { env: badEnv })
120 await quickImport(HttpStatusCode.BAD_REQUEST_400)
124 after(async function () {
125 await proxy.terminate()
127 await cleanupTests(servers)