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