From afc22dc5c2165c94ac08b48553ad20be7826689c Mon Sep 17 00:00:00 2001 From: Ersun Warncke Date: Wed, 29 Aug 2018 12:00:20 -0400 Subject: [PATCH] Revert "Merge pull request #790 from sharelatex/ew-add-cookie-and-form-to-proxy" This reverts commit ebefc2f28c6e88bbfa632f2b22cb8b99b75e95ec, reversing changes made to 223beab491d2f8dcf4c7285267fda355cfce3f05. --- .../coffee/infrastructure/ProxyManager.coffee | 10 +-- .../infrastructure/ProxyManagerTests.coffee | 70 ++----------------- 2 files changed, 7 insertions(+), 73 deletions(-) diff --git a/services/web/app/coffee/infrastructure/ProxyManager.coffee b/services/web/app/coffee/infrastructure/ProxyManager.coffee index 3e7a037054..4d64b25bae 100644 --- a/services/web/app/coffee/infrastructure/ProxyManager.coffee +++ b/services/web/app/coffee/infrastructure/ProxyManager.coffee @@ -7,20 +7,14 @@ module.exports = ProxyManager = apply: (publicApiRouter) -> for proxyUrl, target of settings.proxyUrls do (target) -> - method = target.options?.method || 'get' - publicApiRouter[method] proxyUrl, ProxyManager.createProxy(target) + publicApiRouter.get proxyUrl, ProxyManager.createProxy(target) createProxy: (target) -> (req, res, next) -> targetUrl = makeTargetUrl(target, req) logger.log targetUrl: targetUrl, reqUrl: req.url, "proxying url" - options = - url: targetUrl - options.headers = { Cookie: req.headers.cookie } if req.headers?.cookie - Object.assign(options, target.options) if target?.options? - options.form = req.body if options.method in ['post', 'put'] - upstream = request(options) + upstream = request(targetUrl) upstream.on "error", (error) -> logger.error err: error, "error in ProxyManager" diff --git a/services/web/test/unit/coffee/infrastructure/ProxyManagerTests.coffee b/services/web/test/unit/coffee/infrastructure/ProxyManagerTests.coffee index 9a1d9ea17c..3f1c1e9f78 100644 --- a/services/web/test/unit/coffee/infrastructure/ProxyManagerTests.coffee +++ b/services/web/test/unit/coffee/infrastructure/ProxyManagerTests.coffee @@ -35,26 +35,11 @@ describe "ProxyManager", -> assertCalledWith(@router.get, '/foo/bar') assertCalledWith(@router.get, '/foo/:id') - it 'applies methods other than get', -> - @router = - post: sinon.stub() - put: sinon.stub() - @settings.proxyUrls = - '/foo/bar': {options: {method: 'post'}} - '/foo/:id': {options: {method: 'put'}} - @proxyManager.apply(@router) - sinon.assert.calledOnce(@router.post) - sinon.assert.calledOnce(@router.put) - assertCalledWith(@router.post, '/foo/bar') - assertCalledWith(@router.put, '/foo/:id') - describe 'createProxy', -> beforeEach -> @req.url = @proxyPath @req.route.path = @proxyPath @req.query = {} - @req.params = {} - @req.headers = {} @settings.proxyUrls = {} afterEach -> @@ -72,7 +57,7 @@ describe "ProxyManager", -> targetUrl = 'https://user:pass@foo.bar:123/pa/th.ext?query#hash' @settings.proxyUrls[@proxyPath] = targetUrl @proxyManager.createProxy(targetUrl)(@req) - assertCalledWith(@request, {url: targetUrl}) + assertCalledWith(@request, targetUrl) it 'overwrite query', -> targetUrl = 'foo.bar/baz?query' @@ -80,19 +65,19 @@ describe "ProxyManager", -> @settings.proxyUrls[@proxyPath] = targetUrl @proxyManager.createProxy(targetUrl)(@req) newTargetUrl = 'foo.bar/baz?requestQuery=important' - assertCalledWith(@request, {url: newTargetUrl}) + assertCalledWith(@request, newTargetUrl) it 'handles target objects', -> target = { baseUrl: 'api.v1', path: '/pa/th'} @settings.proxyUrls[@proxyPath] = target @proxyManager.createProxy(target)(@req, @res, @next) - assertCalledWith(@request, {url: 'api.v1/pa/th'}) + assertCalledWith(@request, 'api.v1/pa/th') it 'handles missing baseUrl', -> target = { path: '/pa/th'} @settings.proxyUrls[@proxyPath] = target @proxyManager.createProxy(target)(@req, @res, @next) - assertCalledWith(@request, {url: 'undefined/pa/th'}) + assertCalledWith(@request, 'undefined/pa/th') it 'handles dynamic path', -> target = baseUrl: 'api.v1', path: (params) -> "/resource/#{params.id}" @@ -101,49 +86,4 @@ describe "ProxyManager", -> @req.route.path = '/res/:id' @req.params = id: 123 @proxyManager.createProxy(target)(@req, @res, @next) - assertCalledWith(@request, {url: 'api.v1/resource/123'}) - - it 'set arbitrary options on request', -> - target = baseUrl: 'api.v1', path: '/foo', options: foo: 'bar' - @req.url = '/foo' - @req.route.path = '/foo' - @proxyManager.createProxy(target)(@req, @res, @next) - assertCalledWith(@request, - foo: 'bar' - url: 'api.v1/foo' - ) - - it 'passes cookies', -> - target = baseUrl: 'api.v1', path: '/foo' - @req.url = '/foo' - @req.route.path = '/foo' - @req.headers = cookie: 'cookie' - @proxyManager.createProxy(target)(@req, @res, @next) - assertCalledWith(@request, - headers: Cookie: 'cookie' - url: 'api.v1/foo' - ) - - it 'passes body for post', -> - target = baseUrl: 'api.v1', path: '/foo', options: method: 'post' - @req.url = '/foo' - @req.route.path = '/foo' - @req.body = foo: 'bar' - @proxyManager.createProxy(target)(@req, @res, @next) - assertCalledWith(@request, - form: foo: 'bar' - method: 'post' - url: 'api.v1/foo' - ) - - it 'passes body for put', -> - target = baseUrl: 'api.v1', path: '/foo', options: method: 'put' - @req.url = '/foo' - @req.route.path = '/foo' - @req.body = foo: 'bar' - @proxyManager.createProxy(target)(@req, @res, @next) - assertCalledWith(@request, - form: foo: 'bar' - method: 'put' - url: 'api.v1/foo' - ) \ No newline at end of file + assertCalledWith(@request, 'api.v1/resource/123')