]>
Commit | Line | Data |
---|---|---|
8729a870 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
c55e3d72 C |
5 | import { FIXTURE_URLS, MockProxy } from '@server/tests/shared' |
6 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | |
62549e6c C |
7 | import { |
8 | cleanupTests, | |
9 | createMultipleServers, | |
10 | doubleFollow, | |
62549e6c C |
11 | PeerTubeServer, |
12 | setAccessTokensToServers, | |
13 | setDefaultVideoChannel, | |
14 | waitJobs | |
bf54587a | 15 | } from '@shared/server-commands' |
8729a870 | 16 | |
17 | const expect = chai.expect | |
18 | ||
19 | describe('Test proxy', function () { | |
20 | let servers: PeerTubeServer[] = [] | |
21 | let proxy: MockProxy | |
22 | ||
23 | const goodEnv = { HTTP_PROXY: '' } | |
24 | const badEnv = { HTTP_PROXY: 'http://localhost:9000' } | |
25 | ||
26 | before(async function () { | |
27 | this.timeout(120000) | |
28 | ||
29 | proxy = new MockProxy() | |
30 | ||
31 | const proxyPort = await proxy.initialize() | |
32 | servers = await createMultipleServers(2) | |
33 | ||
34 | goodEnv.HTTP_PROXY = 'http://localhost:' + proxyPort | |
35 | ||
36 | await setAccessTokensToServers(servers) | |
62549e6c | 37 | await setDefaultVideoChannel(servers) |
8729a870 | 38 | await doubleFollow(servers[0], servers[1]) |
39 | }) | |
40 | ||
62549e6c | 41 | describe('Federation', function () { |
8729a870 | 42 | |
62549e6c C |
43 | it('Should succeed federation with the appropriate proxy config', async function () { |
44 | this.timeout(40000) | |
8729a870 | 45 | |
62549e6c C |
46 | await servers[0].kill() |
47 | await servers[0].run({}, { env: goodEnv }) | |
8729a870 | 48 | |
62549e6c C |
49 | await servers[0].videos.quickUpload({ name: 'video 1' }) |
50 | ||
51 | await waitJobs(servers) | |
52 | ||
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) | |
57 | } | |
58 | }) | |
59 | ||
60 | it('Should fail federation with a wrong proxy config', async function () { | |
61 | this.timeout(40000) | |
62 | ||
63 | await servers[0].kill() | |
64 | await servers[0].run({}, { env: badEnv }) | |
65 | ||
66 | await servers[0].videos.quickUpload({ name: 'video 2' }) | |
67 | ||
68 | await waitJobs(servers) | |
69 | ||
70 | { | |
71 | const { total, data } = await servers[0].videos.list() | |
72 | expect(total).to.equal(2) | |
73 | expect(data).to.have.lengthOf(2) | |
74 | } | |
75 | ||
76 | { | |
77 | const { total, data } = await servers[1].videos.list() | |
78 | expect(total).to.equal(1) | |
79 | expect(data).to.have.lengthOf(1) | |
80 | } | |
81 | }) | |
8729a870 | 82 | }) |
83 | ||
62549e6c C |
84 | describe('Videos import', async function () { |
85 | ||
86 | function quickImport (expectedStatus: HttpStatusCode = HttpStatusCode.OK_200) { | |
87 | return servers[0].imports.importVideo({ | |
88 | attributes: { | |
89 | name: 'video import', | |
90 | channelId: servers[0].store.channel.id, | |
91 | privacy: VideoPrivacy.PUBLIC, | |
92 | targetUrl: FIXTURE_URLS.peertube_long | |
93 | }, | |
94 | expectedStatus | |
95 | }) | |
96 | } | |
97 | ||
98 | it('Should succeed import with the appropriate proxy config', async function () { | |
b18a501a | 99 | this.timeout(120000) |
62549e6c C |
100 | |
101 | await servers[0].kill() | |
102 | await servers[0].run({}, { env: goodEnv }) | |
8729a870 | 103 | |
62549e6c | 104 | await quickImport() |
8729a870 | 105 | |
62549e6c | 106 | await waitJobs(servers) |
8729a870 | 107 | |
8729a870 | 108 | const { total, data } = await servers[0].videos.list() |
62549e6c C |
109 | expect(total).to.equal(3) |
110 | expect(data).to.have.lengthOf(3) | |
111 | }) | |
8729a870 | 112 | |
62549e6c | 113 | it('Should fail import with a wrong proxy config', async function () { |
b18a501a | 114 | this.timeout(120000) |
62549e6c C |
115 | |
116 | await servers[0].kill() | |
117 | await servers[0].run({}, { env: badEnv }) | |
118 | ||
119 | await quickImport(HttpStatusCode.BAD_REQUEST_400) | |
120 | }) | |
8729a870 | 121 | }) |
122 | ||
123 | after(async function () { | |
70430c27 | 124 | await proxy.terminate() |
8729a870 | 125 | |
126 | await cleanupTests(servers) | |
127 | }) | |
128 | }) |