Skip to content

Commit e2ace24

Browse files
author
Kerkesni
committed
Merge remote-tracking branch 'origin/bugfix/CLDSRV-755' into w/9.1/bugfix/CLDSRV-755
2 parents a2678a9 + a432e79 commit e2ace24

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

lib/routes/routeBackbeat.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ function routeIndexingAPIs(request, response, userInfo, log, callback) {
14501450
}
14511451

14521452
function routeBackbeatAPIProxy(request, response, requestContexts, log) {
1453-
const path = request.url.replace('/_/backbeat/api', '/_/');
1453+
const path = request.url.replace('/_/backbeat/api/', '/_/');
14541454
const { host, port } = config.backbeat;
14551455
const target = `http://${host}:${port}${path}`;
14561456

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenko/cloudserver",
3-
"version": "9.1.3",
3+
"version": "9.1.4",
44
"description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol",
55
"main": "index.js",
66
"engines": {

tests/unit/routes/routeBackbeat.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const assert = require('assert');
22
const sinon = require('sinon');
33
const async = require('async');
4+
const http = require('http');
45
const { promisify } = require('util');
56
const metadataUtils = require('../../../lib/metadata/metadataUtils');
67
const storeObject = require('../../../lib/api/apiUtils/object/storeObject');
@@ -702,6 +703,58 @@ describe('routeBackbeat', () => {
702703
assert.deepStrictEqual(mockResponse.body, null);
703704
});
704705
});
706+
707+
describe('routeBackbeatAPIProxy', () => {
708+
let mockBackbeat;
709+
710+
const request = new DummyRequest({
711+
method: 'POST',
712+
url: '/_/backbeat/api/ingestion/pause',
713+
socket: {
714+
remoteAddress: '127.0.0.1',
715+
},
716+
}, Buffer.from(''));
717+
718+
beforeEach(() => {
719+
mockBackbeat = http.createServer((req, res) => {
720+
res.writeHead(200);
721+
res.end();
722+
});
723+
mockBackbeat.listen(config.backbeat.port);
724+
});
725+
726+
afterEach(() => {
727+
mockBackbeat.close();
728+
sinon.restore();
729+
});
730+
731+
it('should correctly proxy the request to the backbeat API', async () => {
732+
sinon.stub(auth.server, 'doAuth').yields(null, new AuthInfo({
733+
canonicalID: 'abcdef/lifecycle',
734+
accountDisplayName: 'Lifecycle Service Account',
735+
}), undefined, undefined, undefined);
736+
737+
endPromise = new Promise(resolve => { resolveEnd = resolve; });
738+
const response = {
739+
on: sinon.stub(),
740+
once: sinon.stub(),
741+
emit: sinon.stub(),
742+
setHeader: sinon.stub(),
743+
end: sinon.stub().callsFake(() => {
744+
resolveEnd();
745+
})
746+
};
747+
748+
routeBackbeat('127.0.0.1', request, response, log);
749+
750+
void await endPromise;
751+
752+
const proxyReq = response.emit.getCall(0).args[1].req;
753+
assert.strictEqual(proxyReq.method, 'POST');
754+
assert.strictEqual(proxyReq.path, '/_/ingestion/pause');
755+
assert.strictEqual(proxyReq.getHeader('host'), `localhost:${config.backbeat.port}`);
756+
});
757+
});
705758
});
706759

707760
describe('routeBackbeat authorization', () => {

0 commit comments

Comments
 (0)