]>
Commit | Line | Data |
---|---|---|
8729a870 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
86347717 | 3 | import { expect } from 'chai' |
ca3d5912 | 4 | import { expectNotStartWith, expectStartWith, FIXTURE_URLS, MockProxy } from '@server/tests/shared' |
9ab330b9 | 5 | import { areMockObjectStorageTestsDisabled } from '@shared/core-utils' |
c55e3d72 | 6 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' |
62549e6c C |
7 | import { |
8 | cleanupTests, | |
9 | createMultipleServers, | |
10 | doubleFollow, | |
ca3d5912 | 11 | ObjectStorageCommand, |
62549e6c C |
12 | PeerTubeServer, |
13 | setAccessTokensToServers, | |
14 | setDefaultVideoChannel, | |
15 | waitJobs | |
bf54587a | 16 | } from '@shared/server-commands' |
8729a870 | 17 | |
8729a870 | 18 | describe('Test proxy', function () { |
19 | let servers: PeerTubeServer[] = [] | |
20 | let proxy: MockProxy | |
21 | ||
22 | const goodEnv = { HTTP_PROXY: '' } | |
2732eeff | 23 | const badEnv = { HTTP_PROXY: 'http://127.0.0.1:9000' } |
8729a870 | 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 | ||
2732eeff | 33 | goodEnv.HTTP_PROXY = 'http://127.0.0.1:' + proxyPort |
8729a870 | 34 | |
35 | await setAccessTokensToServers(servers) | |
62549e6c | 36 | await setDefaultVideoChannel(servers) |
8729a870 | 37 | await doubleFollow(servers[0], servers[1]) |
38 | }) | |
39 | ||
62549e6c | 40 | describe('Federation', function () { |
8729a870 | 41 | |
62549e6c C |
42 | it('Should succeed federation with the appropriate proxy config', async function () { |
43 | this.timeout(40000) | |
8729a870 | 44 | |
62549e6c C |
45 | await servers[0].kill() |
46 | await servers[0].run({}, { env: goodEnv }) | |
8729a870 | 47 | |
62549e6c C |
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 | }) | |
8729a870 | 81 | }) |
82 | ||
62549e6c C |
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 () { | |
afb371d9 | 98 | this.timeout(240000) |
62549e6c C |
99 | |
100 | await servers[0].kill() | |
101 | await servers[0].run({}, { env: goodEnv }) | |
8729a870 | 102 | |
62549e6c | 103 | await quickImport() |
8729a870 | 104 | |
62549e6c | 105 | await waitJobs(servers) |
8729a870 | 106 | |
8729a870 | 107 | const { total, data } = await servers[0].videos.list() |
62549e6c C |
108 | expect(total).to.equal(3) |
109 | expect(data).to.have.lengthOf(3) | |
110 | }) | |
8729a870 | 111 | |
62549e6c | 112 | it('Should fail import with a wrong proxy config', async function () { |
b18a501a | 113 | this.timeout(120000) |
62549e6c C |
114 | |
115 | await servers[0].kill() | |
116 | await servers[0].run({}, { env: badEnv }) | |
117 | ||
118 | await quickImport(HttpStatusCode.BAD_REQUEST_400) | |
119 | }) | |
8729a870 | 120 | }) |
121 | ||
ca3d5912 | 122 | describe('Object storage', function () { |
9ab330b9 | 123 | if (areMockObjectStorageTestsDisabled()) return |
ca3d5912 C |
124 | |
125 | before(async function () { | |
126 | this.timeout(30000) | |
127 | ||
9ab330b9 | 128 | await ObjectStorageCommand.prepareDefaultMockBuckets() |
ca3d5912 C |
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() | |
9ab330b9 | 135 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: goodEnv }) |
ca3d5912 C |
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 | ||
9ab330b9 | 142 | expectStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) |
ca3d5912 C |
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() | |
9ab330b9 | 149 | await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: badEnv }) |
ca3d5912 C |
150 | |
151 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video' }) | |
e82cb087 | 152 | await waitJobs(servers, { skipDelayed: true }) |
ca3d5912 C |
153 | |
154 | const video = await servers[0].videos.get({ id: uuid }) | |
155 | ||
9ab330b9 | 156 | expectNotStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl()) |
ca3d5912 C |
157 | }) |
158 | }) | |
159 | ||
8729a870 | 160 | after(async function () { |
70430c27 | 161 | await proxy.terminate() |
8729a870 | 162 | |
163 | await cleanupTests(servers) | |
164 | }) | |
165 | }) |