]>
Commit | Line | Data |
---|---|---|
8729a870 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
ca3d5912 C |
5 | import { expectNotStartWith, expectStartWith, FIXTURE_URLS, MockProxy } from '@server/tests/shared' |
6 | import { areObjectStorageTestsDisabled } from '@shared/core-utils' | |
c55e3d72 | 7 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' |
62549e6c C |
8 | import { |
9 | cleanupTests, | |
10 | createMultipleServers, | |
11 | doubleFollow, | |
ca3d5912 | 12 | ObjectStorageCommand, |
62549e6c C |
13 | PeerTubeServer, |
14 | setAccessTokensToServers, | |
15 | setDefaultVideoChannel, | |
16 | waitJobs | |
bf54587a | 17 | } from '@shared/server-commands' |
8729a870 | 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) | |
62549e6c | 39 | await setDefaultVideoChannel(servers) |
8729a870 | 40 | await doubleFollow(servers[0], servers[1]) |
41 | }) | |
42 | ||
62549e6c | 43 | describe('Federation', function () { |
8729a870 | 44 | |
62549e6c C |
45 | it('Should succeed federation with the appropriate proxy config', async function () { |
46 | this.timeout(40000) | |
8729a870 | 47 | |
62549e6c C |
48 | await servers[0].kill() |
49 | await servers[0].run({}, { env: goodEnv }) | |
8729a870 | 50 | |
62549e6c C |
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 | }) | |
8729a870 | 84 | }) |
85 | ||
62549e6c C |
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 () { | |
b18a501a | 101 | this.timeout(120000) |
62549e6c C |
102 | |
103 | await servers[0].kill() | |
104 | await servers[0].run({}, { env: goodEnv }) | |
8729a870 | 105 | |
62549e6c | 106 | await quickImport() |
8729a870 | 107 | |
62549e6c | 108 | await waitJobs(servers) |
8729a870 | 109 | |
8729a870 | 110 | const { total, data } = await servers[0].videos.list() |
62549e6c C |
111 | expect(total).to.equal(3) |
112 | expect(data).to.have.lengthOf(3) | |
113 | }) | |
8729a870 | 114 | |
62549e6c | 115 | it('Should fail import with a wrong proxy config', async function () { |
b18a501a | 116 | this.timeout(120000) |
62549e6c C |
117 | |
118 | await servers[0].kill() | |
119 | await servers[0].run({}, { env: badEnv }) | |
120 | ||
121 | await quickImport(HttpStatusCode.BAD_REQUEST_400) | |
122 | }) | |
8729a870 | 123 | }) |
124 | ||
ca3d5912 C |
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 | ||
8729a870 | 163 | after(async function () { |
70430c27 | 164 | await proxy.terminate() |
8729a870 | 165 | |
166 | await cleanupTests(servers) | |
167 | }) | |
168 | }) |