|
1 | 1 | const assert = require('assert'); |
2 | 2 | const sinon = require('sinon'); |
3 | 3 | const async = require('async'); |
| 4 | +const http = require('http'); |
4 | 5 | const { promisify } = require('util'); |
5 | 6 | const metadataUtils = require('../../../lib/metadata/metadataUtils'); |
6 | 7 | const storeObject = require('../../../lib/api/apiUtils/object/storeObject'); |
@@ -702,6 +703,58 @@ describe('routeBackbeat', () => { |
702 | 703 | assert.deepStrictEqual(mockResponse.body, null); |
703 | 704 | }); |
704 | 705 | }); |
| 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 | + }); |
705 | 758 | }); |
706 | 759 |
|
707 | 760 | describe('routeBackbeat authorization', () => { |
|
0 commit comments