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