aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/helpers/requests.ts1
-rw-r--r--server/lib/object-storage/shared/client.ts17
-rw-r--r--server/tests/api/server/proxy.ts42
-rw-r--r--server/tests/shared/checks.ts5
4 files changed, 63 insertions, 2 deletions
diff --git a/server/helpers/requests.ts b/server/helpers/requests.ts
index 327610558..a9869e987 100644
--- a/server/helpers/requests.ts
+++ b/server/helpers/requests.ts
@@ -212,6 +212,7 @@ export {
212 doRequestAndSaveToFile, 212 doRequestAndSaveToFile,
213 isBinaryResponse, 213 isBinaryResponse,
214 downloadImage, 214 downloadImage,
215 getAgent,
215 findLatestRedirection, 216 findLatestRedirection,
216 peertubeGot 217 peertubeGot
217} 218}
diff --git a/server/lib/object-storage/shared/client.ts b/server/lib/object-storage/shared/client.ts
index c9a614593..d5cb074df 100644
--- a/server/lib/object-storage/shared/client.ts
+++ b/server/lib/object-storage/shared/client.ts
@@ -1,8 +1,22 @@
1import { S3Client } from '@aws-sdk/client-s3' 1import { S3Client } from '@aws-sdk/client-s3'
2import { NodeHttpHandler } from '@aws-sdk/node-http-handler'
2import { logger } from '@server/helpers/logger' 3import { logger } from '@server/helpers/logger'
4import { isProxyEnabled } from '@server/helpers/proxy'
5import { getAgent } from '@server/helpers/requests'
3import { CONFIG } from '@server/initializers/config' 6import { CONFIG } from '@server/initializers/config'
4import { lTags } from './logger' 7import { lTags } from './logger'
5 8
9function getProxyRequestHandler () {
10 if (!isProxyEnabled()) return null
11
12 const { agent } = getAgent()
13
14 return new NodeHttpHandler({
15 httpAgent: agent.http,
16 httpsAgent: agent.https
17 })
18}
19
6let endpointParsed: URL 20let endpointParsed: URL
7function getEndpointParsed () { 21function getEndpointParsed () {
8 if (endpointParsed) return endpointParsed 22 if (endpointParsed) return endpointParsed
@@ -26,7 +40,8 @@ function getClient () {
26 accessKeyId: OBJECT_STORAGE.CREDENTIALS.ACCESS_KEY_ID, 40 accessKeyId: OBJECT_STORAGE.CREDENTIALS.ACCESS_KEY_ID,
27 secretAccessKey: OBJECT_STORAGE.CREDENTIALS.SECRET_ACCESS_KEY 41 secretAccessKey: OBJECT_STORAGE.CREDENTIALS.SECRET_ACCESS_KEY
28 } 42 }
29 : undefined 43 : undefined,
44 requestHandler: getProxyRequestHandler()
30 }) 45 })
31 46
32 logger.info('Initialized S3 client %s with region %s.', getEndpoint(), OBJECT_STORAGE.REGION, lTags()) 47 logger.info('Initialized S3 client %s with region %s.', getEndpoint(), OBJECT_STORAGE.REGION, lTags())
diff --git a/server/tests/api/server/proxy.ts b/server/tests/api/server/proxy.ts
index 2a8ff56d2..e238edaf4 100644
--- a/server/tests/api/server/proxy.ts
+++ b/server/tests/api/server/proxy.ts
@@ -2,12 +2,14 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { FIXTURE_URLS, MockProxy } from '@server/tests/shared' 5import { expectNotStartWith, expectStartWith, FIXTURE_URLS, MockProxy } from '@server/tests/shared'
6import { areObjectStorageTestsDisabled } from '@shared/core-utils'
6import { HttpStatusCode, VideoPrivacy } from '@shared/models' 7import { HttpStatusCode, VideoPrivacy } from '@shared/models'
7import { 8import {
8 cleanupTests, 9 cleanupTests,
9 createMultipleServers, 10 createMultipleServers,
10 doubleFollow, 11 doubleFollow,
12 ObjectStorageCommand,
11 PeerTubeServer, 13 PeerTubeServer,
12 setAccessTokensToServers, 14 setAccessTokensToServers,
13 setDefaultVideoChannel, 15 setDefaultVideoChannel,
@@ -120,6 +122,44 @@ describe('Test proxy', function () {
120 }) 122 })
121 }) 123 })
122 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
123 after(async function () { 163 after(async function () {
124 await proxy.terminate() 164 await proxy.terminate()
125 165
diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts
index dcc16d7ea..33b917f31 100644
--- a/server/tests/shared/checks.ts
+++ b/server/tests/shared/checks.ts
@@ -19,6 +19,10 @@ function expectStartWith (str: string, start: string) {
19 expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.true 19 expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.true
20} 20}
21 21
22function expectNotStartWith (str: string, start: string) {
23 expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.false
24}
25
22async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { 26async function expectLogDoesNotContain (server: PeerTubeServer, str: string) {
23 const content = await server.servers.getLogContent() 27 const content = await server.servers.getLogContent()
24 28
@@ -92,6 +96,7 @@ export {
92 expectLogDoesNotContain, 96 expectLogDoesNotContain,
93 testFileExistsOrNot, 97 testFileExistsOrNot,
94 expectStartWith, 98 expectStartWith,
99 expectNotStartWith,
95 checkBadStartPagination, 100 checkBadStartPagination,
96 checkBadCountPagination, 101 checkBadCountPagination,
97 checkBadSortPagination 102 checkBadSortPagination