From 516525126bb66ae9fb4a0f1357202ba095f12d3a Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Fri, 2 Jul 2021 09:17:29 +0100 Subject: [PATCH] [UrlFetcher] do not override domain for clsi-perf requests --- services/clsi/app/js/UrlFetcher.js | 9 +++++--- services/clsi/config/settings.defaults.js | 5 +++++ services/clsi/test/unit/js/UrlFetcherTests.js | 21 ++++++++++++++++++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/services/clsi/app/js/UrlFetcher.js b/services/clsi/app/js/UrlFetcher.js index b3ed8c465d..adfb55da4c 100644 --- a/services/clsi/app/js/UrlFetcher.js +++ b/services/clsi/app/js/UrlFetcher.js @@ -42,9 +42,12 @@ module.exports = UrlFetcher = { return (_callback = function () {}) } - if (settings.filestoreDomainOveride != null) { - const p = URL.parse(url).path - url = `${settings.filestoreDomainOveride}${p}` + const u = URL.parse(url) + if ( + settings.filestoreDomainOveride && + u.host !== settings.apis.clsiPerf.host + ) { + url = `${settings.filestoreDomainOveride}${u.path}` } var timeoutHandler = setTimeout( function () { diff --git a/services/clsi/config/settings.defaults.js b/services/clsi/config/settings.defaults.js index ae6086f1d4..b53f871b6d 100644 --- a/services/clsi/config/settings.defaults.js +++ b/services/clsi/config/settings.defaults.js @@ -51,6 +51,11 @@ module.exports = { apis: { clsi: { url: `http://${process.env.CLSI_HOST || 'localhost'}:3013` + }, + clsiPerf: { + host: `${process.env.CLSI_PERF_HOST || 'localhost'}:${ + process.env.CLSI_PERF_PORT || '3043' + }` } }, diff --git a/services/clsi/test/unit/js/UrlFetcherTests.js b/services/clsi/test/unit/js/UrlFetcherTests.js index 238e5d8aa9..6a5bc1f3dd 100644 --- a/services/clsi/test/unit/js/UrlFetcherTests.js +++ b/services/clsi/test/unit/js/UrlFetcherTests.js @@ -24,7 +24,13 @@ describe('UrlFetcher', function () { defaults: (this.defaults = sinon.stub().returns((this.request = {}))) }, fs: (this.fs = {}), - 'settings-sharelatex': (this.settings = {}) + 'settings-sharelatex': (this.settings = { + apis: { + clsiPerf: { + host: 'localhost:3043' + } + } + }) } })) }) @@ -94,6 +100,19 @@ describe('UrlFetcher', function () { return this.fileStream.emit('finish') }) + it('should not use override clsiPerf domain when filestoreDomainOveride is set', function (done) { + this.settings.filestoreDomainOveride = '192.11.11.11' + const url = 'http://localhost:3043/file/here?query=string' + this.UrlFetcher.pipeUrlToFile(url, this.path, () => { + this.request.get.args[0][0].url.should.equal(url) + done() + }) + this.res = { statusCode: 200 } + this.urlStream.emit('response', this.res) + this.urlStream.emit('end') + this.fileStream.emit('finish') + }) + return it('should use override domain when filestoreDomainOveride is set', function (done) { this.settings.filestoreDomainOveride = '192.11.11.11' this.UrlFetcher.pipeUrlToFile(this.url, this.path, () => {