]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/proxy.ts
Merge remote-tracking branch 'weblate/develop' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / proxy.ts
index 2a8ff56d261d500f6a0e2f3f5272bc2c75e6aaa2..4bf89410eb831f9280bfcb8a0c06428df73ae44a 100644 (file)
@@ -1,27 +1,26 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
-import * as chai from 'chai'
-import { FIXTURE_URLS, MockProxy } from '@server/tests/shared'
+import { expect } from 'chai'
+import { expectNotStartWith, expectStartWith, FIXTURE_URLS, MockProxy } from '@server/tests/shared'
+import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
 import {
   cleanupTests,
   createMultipleServers,
   doubleFollow,
+  ObjectStorageCommand,
   PeerTubeServer,
   setAccessTokensToServers,
   setDefaultVideoChannel,
   waitJobs
 } from '@shared/server-commands'
 
-const expect = chai.expect
-
 describe('Test proxy', function () {
   let servers: PeerTubeServer[] = []
   let proxy: MockProxy
 
   const goodEnv = { HTTP_PROXY: '' }
-  const badEnv = { HTTP_PROXY: 'http://localhost:9000' }
+  const badEnv = { HTTP_PROXY: 'http://127.0.0.1:9000' }
 
   before(async function () {
     this.timeout(120000)
@@ -31,7 +30,7 @@ describe('Test proxy', function () {
     const proxyPort = await proxy.initialize()
     servers = await createMultipleServers(2)
 
-    goodEnv.HTTP_PROXY = 'http://localhost:' + proxyPort
+    goodEnv.HTTP_PROXY = 'http://127.0.0.1:' + proxyPort
 
     await setAccessTokensToServers(servers)
     await setDefaultVideoChannel(servers)
@@ -96,7 +95,7 @@ describe('Test proxy', function () {
     }
 
     it('Should succeed import with the appropriate proxy config', async function () {
-      this.timeout(120000)
+      this.timeout(240000)
 
       await servers[0].kill()
       await servers[0].run({}, { env: goodEnv })
@@ -120,6 +119,44 @@ describe('Test proxy', function () {
     })
   })
 
+  describe('Object storage', function () {
+    if (areMockObjectStorageTestsDisabled()) return
+
+    before(async function () {
+      this.timeout(30000)
+
+      await ObjectStorageCommand.prepareDefaultMockBuckets()
+    })
+
+    it('Should succeed to upload to object storage with the appropriate proxy config', async function () {
+      this.timeout(120000)
+
+      await servers[0].kill()
+      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: goodEnv })
+
+      const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
+      await waitJobs(servers)
+
+      const video = await servers[0].videos.get({ id: uuid })
+
+      expectStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+    })
+
+    it('Should fail to upload to object storage with a wrong proxy config', async function () {
+      this.timeout(120000)
+
+      await servers[0].kill()
+      await servers[0].run(ObjectStorageCommand.getDefaultMockConfig(), { env: badEnv })
+
+      const { uuid } = await servers[0].videos.quickUpload({ name: 'video' })
+      await waitJobs(servers, { skipDelayed: true })
+
+      const video = await servers[0].videos.get({ id: uuid })
+
+      expectNotStartWith(video.files[0].fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
+    })
+  })
+
   after(async function () {
     await proxy.terminate()