Skip to content

Commit

Permalink
Merge pull request #5 from arihantjn53/ACE_1059_remove_any_protocol
Browse files Browse the repository at this point in the history
Remove any protocol part from --proxy-host
  • Loading branch information
francisf authored Aug 20, 2020
2 parents 9666cee + f02fb06 commit cb729b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports.PORTS = {
MAX: 65535,
MIN: 1
};
module.exports.PROTOCOL_REGEX = /(^\w+:|^)\/\//;

module.exports.LOGS = Object.freeze({
NETWORK: 'NetworkStats.log',
Expand Down
4 changes: 3 additions & 1 deletion src/commandLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ var CommandLineManager = {
index = argv.indexOf('--proxy-host');
if (index !== -1) {
if (CommandLineManager.validArgValue(argv[index + 1])) {
var host = argv[index + 1];
host = host.replace(constants.PROTOCOL_REGEX, '');
RdGlobalConfig.proxy = RdGlobalConfig.proxy || {};
RdGlobalConfig.proxy.host = argv[index + 1];
RdGlobalConfig.proxy.host = host;
argv.splice(index, 2);
} else {
invalidArgs.add('--proxy-host');
Expand Down
14 changes: 14 additions & 0 deletions test/commandLine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ describe('CommandLineManager', function () {
expect(RdGlobalConfig.proxy.port).to.eql(9687);
});

it('remove any protocol part from proxy-host', function () {
sinon.stub(console, 'log');
argv = argv.concat(['--proxy-host', 'http://host']);
CommandLineManager.processArgs(argv);
expect(RdGlobalConfig.proxy.host).to.eql('host');
});

it('remove any prefix slashes from proxy-host', function () {
argv = argv.concat(['--proxy-host', '//host']);
CommandLineManager.processArgs(argv);
console.log.restore();
expect(RdGlobalConfig.proxy.host).to.eql('host');
});

it('proxy-port is set to the default value when its not in the expected range', function () {
sinon.stub(console, 'log');
argv = argv.concat(['--proxy-host', 'host', '--proxy-port', '99999']);
Expand Down

0 comments on commit cb729b6

Please sign in to comment.