diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/server/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/server/proxy.ts | 72 |
2 files changed, 73 insertions, 0 deletions
diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index 56e6eb5da..b16a22ee7 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts | |||
@@ -15,3 +15,4 @@ import './stats' | |||
15 | import './tracker' | 15 | import './tracker' |
16 | import './no-client' | 16 | import './no-client' |
17 | import './plugins' | 17 | import './plugins' |
18 | import './proxy' | ||
diff --git a/server/tests/api/server/proxy.ts b/server/tests/api/server/proxy.ts new file mode 100644 index 000000000..d5042ef27 --- /dev/null +++ b/server/tests/api/server/proxy.ts | |||
@@ -0,0 +1,72 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | ||
5 | import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' | ||
6 | import { MockProxy } from '@shared/extra-utils/mock-servers/mock-proxy' | ||
7 | |||
8 | const expect = chai.expect | ||
9 | |||
10 | describe('Test proxy', function () { | ||
11 | let servers: PeerTubeServer[] = [] | ||
12 | let proxy: MockProxy | ||
13 | |||
14 | const goodEnv = { HTTP_PROXY: '' } | ||
15 | const badEnv = { HTTP_PROXY: 'http://localhost:9000' } | ||
16 | |||
17 | before(async function () { | ||
18 | this.timeout(120000) | ||
19 | |||
20 | proxy = new MockProxy() | ||
21 | |||
22 | const proxyPort = await proxy.initialize() | ||
23 | servers = await createMultipleServers(2) | ||
24 | |||
25 | goodEnv.HTTP_PROXY = 'http://localhost:' + proxyPort | ||
26 | |||
27 | await setAccessTokensToServers(servers) | ||
28 | await doubleFollow(servers[0], servers[1]) | ||
29 | }) | ||
30 | |||
31 | it('Should succeed federation with the appropriate proxy config', async function () { | ||
32 | await servers[0].kill() | ||
33 | await servers[0].run({}, { env: goodEnv }) | ||
34 | |||
35 | await servers[0].videos.quickUpload({ name: 'video 1' }) | ||
36 | |||
37 | await waitJobs(servers) | ||
38 | |||
39 | for (const server of servers) { | ||
40 | const { total, data } = await server.videos.list() | ||
41 | expect(total).to.equal(1) | ||
42 | expect(data).to.have.lengthOf(1) | ||
43 | } | ||
44 | }) | ||
45 | |||
46 | it('Should fail federation with a wrong proxy config', async function () { | ||
47 | await servers[0].kill() | ||
48 | await servers[0].run({}, { env: badEnv }) | ||
49 | |||
50 | await servers[0].videos.quickUpload({ name: 'video 2' }) | ||
51 | |||
52 | await waitJobs(servers) | ||
53 | |||
54 | { | ||
55 | const { total, data } = await servers[0].videos.list() | ||
56 | expect(total).to.equal(2) | ||
57 | expect(data).to.have.lengthOf(2) | ||
58 | } | ||
59 | |||
60 | { | ||
61 | const { total, data } = await servers[1].videos.list() | ||
62 | expect(total).to.equal(1) | ||
63 | expect(data).to.have.lengthOf(1) | ||
64 | } | ||
65 | }) | ||
66 | |||
67 | after(async function () { | ||
68 | proxy.terminate() | ||
69 | |||
70 | await cleanupTests(servers) | ||
71 | }) | ||
72 | }) | ||