]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { expect } from 'chai' | |
4 | import { expectNotStartWith, expectStartWith, FIXTURE_URLS, MockProxy } from '@server/tests/shared' | |
5 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' | |
6 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | |
7 | import { | |
8 | cleanupTests, | |
9 | createMultipleServers, | |
10 | doubleFollow, | |
11 | ObjectStorageCommand, | |
12 | PeerTubeServer, | |
13 | setAccessTokensToServers, | |
14 | setDefaultVideoChannel, | |
15 | waitJobs | |
16 | } from '@shared/server-commands' | |
17 | ||
18 | describe('Test proxy', function () { | |
19 | let servers: PeerTubeServer[] = [] | |
20 | let proxy: MockProxy | |
21 | ||
22 | const goodEnv = { HTTP_PROXY: '' } | |
23 | const badEnv = { HTTP_PROXY: 'http://127.0.0.1:9000' } | |
24 | ||
25 | before(async function () { | |
26 | this.timeout(120000) | |
27 | ||
28 | proxy = new MockProxy() | |
29 | ||
30 | const proxyPort = await proxy.initialize() | |
31 | servers = await createMultipleServers(2) | |
32 | ||
33 | goodEnv.HTTP_PROXY = 'http://127.0.0.1:' + proxyPort | |
34 | ||
35 | await setAccessTokensToServers(servers) | |
36 | await setDefaultVideoChannel(servers) | |
37 | await doubleFollow(servers[0], servers[1]) | |
38 | }) | |
39 | ||
40 | describe('Federation', function () { | |
41 | ||
42 | it('Should succeed federation with the appropriate proxy config', async function () { | |
43 | this.timeout(40000) | |
44 | ||
45 | await servers[0].kill() | |
46 | await servers[0].run({}, { env: goodEnv }) | |
47 | ||
48 | await servers[0].videos.quickUpload({ name: 'video 1' }) | |
49 | ||
50 | await waitJobs(servers) | |
51 | ||
52 | for (const server of servers) { | |
53 | const { total, data } = await server.videos.list() | |
54 | expect(total).to.equal(1) | |
55 | expect(data).to.have.lengthOf(1) | |
56 | } | |
57 | }) | |
58 | ||
59 | it('Should fail federation with a wrong proxy config', async function () { | |
60 | this.timeout(40000) | |
61 | ||
62 | await servers[0].kill() | |
63 | await servers[0].run({}, { env: badEnv }) | |
64 | ||
65 | await servers[0].videos.quickUpload({ name: 'video 2' }) | |
66 | ||
67 | await waitJobs(servers) | |
68 | ||
69 | { | |
70 | const { total, data } = await servers[0].videos.list() | |
71 | expect(total).to.equal(2) | |
72 | expect(data).to.have.lengthOf(2) | |
73 | } | |
74 | ||
75 | { | |
76 | const { total, data } = await servers[1].videos.list() | |
77 | expect(total).to.equal(1) | |
78 | expect(data).to.have.lengthOf(1) | |
79 | } | |
80 | }) | |
81 | }) | |
82 | ||
83 | describe('Videos import', async function () { | |
84 | ||
85 | function quickImport (expectedStatus: HttpStatusCode = HttpStatusCode.OK_200) { | |
86 | return servers[0].imports.importVideo({ | |
87 | attributes: { | |
88 | name: 'video import', | |
89 | channelId: servers[0].store.channel.id, | |
90 | privacy: VideoPrivacy.PUBLIC, | |
91 | targetUrl: FIXTURE_URLS.peertube_long | |
92 | }, | |
93 | expectedStatus | |
94 | }) | |
95 | } | |
96 | ||
97 | it('Should succeed import with the appropriate proxy config', async function () { | |
98 | this.timeout(120000) | |
99 | ||
100 | await servers[0].kill() | |
101 | await servers[0].run({}, { env: goodEnv }) | |
102 | ||
103 | await quickImport() | |
104 | ||
105 | await waitJobs(servers) | |
106 | ||
107 | const { total, data } = await servers[0].videos.list() | |
108 | expect(total).to.equal(3) | |
109 | expect(data).to.have.lengthOf(3) | |
110 | }) | |
111 | ||
112 | it('Should fail import with a wrong proxy config', async function () { | |
113 | this.timeout(120000) | |
114 | ||
115 | await servers[0].kill() | |
116 | await servers[0].run({}, { env: badEnv }) | |
117 | ||
118 | await quickImport(HttpStatusCode.BAD_REQUEST_400) | |
119 | }) | |
120 | }) | |
121 | ||
122 | describe('Object storage', function () { | |
123 | if (areMockObjectStorageTestsDisabled()) return | |
124 | ||
125 | before(async function () { | |
126 | this.timeout(30000) | |
127 | ||
128 | await ObjectStorageCommand.prepareDefaultMockBuckets() | |
129 | }) | |
130 | ||
131 | it('Should succeed to upload to object storage with the appropriate proxy config', async function () { | |
132 | this.timeout(120000) | |
133 | ||
134 | await servers[0].kill() | |
135 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: goodEnv }) | |
136 | ||
137 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video' }) | |
138 | await waitJobs(servers) | |
139 | ||
140 | const video = await servers[0].videos.get({ id: uuid }) | |
141 | ||
142 | expectStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) | |
143 | }) | |
144 | ||
145 | it('Should fail to upload to object storage with a wrong proxy config', async function () { | |
146 | this.timeout(120000) | |
147 | ||
148 | await servers[0].kill() | |
149 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: badEnv }) | |
150 | ||
151 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video' }) | |
152 | await waitJobs(servers, { skipDelayed: true }) | |
153 | ||
154 | const video = await servers[0].videos.get({ id: uuid }) | |
155 | ||
156 | expectNotStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) | |
157 | }) | |
158 | }) | |
159 | ||
160 | after(async function () { | |
161 | await proxy.terminate() | |
162 | ||
163 | await cleanupTests(servers) | |
164 | }) | |
165 | }) |