Skip to content

Commit

Permalink
support proxy configuration via cli-option
Browse files Browse the repository at this point in the history
  • Loading branch information
chewiebug committed Aug 20, 2018
1 parent 236948e commit cf79848
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp
<td></td>
<td>Will verify plugins referenced in project's package.json against the plugins blacklist.</td>
</tr>
<tr>
<td>--proxy [proxyUri]</td>
<td></td>
<td>Configures a proxy to be used for --verify (e.g. "http://localhost:1234")</td>
</tr>
<tr>
<td>--tasks</td>
<td>-T</td>
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function handleArguments(env) {
pkgPath = path.join(env.cwd, pkgPath);
}
log.info('Verifying plugins in ' + pkgPath);
return getBlacklist(function(err, blacklist) {
return getBlacklist(opts.proxy, function(err, blacklist) {
if (err) {
return logBlacklistError(err);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/shared/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ module.exports = {
'Will verify plugins referenced in project\'s package.json against ' +
'the plugins blacklist.'),
},
proxy: {
type: 'string',
desc: ansi.gray(
'Configures a proxy to be used for --verify (e.g. "http://localhost:1234")'),
},
tasks: {
alias: 'T',
type: 'boolean',
Expand Down
25 changes: 13 additions & 12 deletions lib/shared/get-blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@ var concat = require('concat-stream');

var HttpsProxyAgent = require('https-proxy-agent');

// HTTP or HTTPS proxy to use
var proxyUri = process.env.http_proxy || process.env.https_proxy;

var url = 'https://gulpjs.com/plugins/blackList.json';

var options = {
method: 'GET',
host: 'gulpjs.com',
path: url,
agent: proxyUri !== undefined ? new HttpsProxyAgent(proxyUri) : undefined,
};

function collect(stream, cb) {
stream.on('error', cb);
stream.pipe(concat(onSuccess));
Expand All @@ -35,9 +25,20 @@ function parse(str, cb) {
}
}

function getOptions(proxyUri) {
var options = {
method: 'GET',
host: 'gulpjs.com',
path: url,
agent: proxyUri !== undefined ? new HttpsProxyAgent(proxyUri) : undefined,
};

return options;
}

// TODO: Test this impl
function getBlacklist(cb) {
https.get(options, onRequest)
function getBlacklist(proxyUri, cb) {
https.get(getOptions(proxyUri), onRequest)
.on('error', function(error) {
cb(error);
});
Expand Down
9 changes: 5 additions & 4 deletions test/flags-verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ var http = require('http');
var net = require('net');
var assert = require('assert');

var proxyPort = 8881;

describe('flag: --verify', function() {

it('dependencies with invalid dependency', function(done) {
Expand Down Expand Up @@ -72,7 +74,7 @@ describe('flag: --verify', function() {
});

it('proxy: dependencies with valid dependency', function(done) {
var proxyServer = createProxyServer(8881);
var proxyServer = createProxyServer(proxyPort);
proxyServer.on('listening', function (servers) {
testProxyImplementation(function (err, stdout, stderr) {
proxyServer.close();
Expand All @@ -98,7 +100,7 @@ describe('flag: --verify', function() {
stderr = eraseTime(stderr);
expect(stderr).toEqual(
'Error: failed to retrieve plugins black-list\n' +
'connect ECONNREFUSED 127.0.0.1:8881\n',
'connect ECONNREFUSED 127.0.0.1:' + proxyPort + '\n',
'testing stderr'
);
stdout = eraseTime(stdout);
Expand All @@ -112,9 +114,8 @@ describe('flag: --verify', function() {
});

function testProxyImplementation(cb) {
process.env.http_proxy = 'http://localhost:8881';
runner({ verbose: false })
.gulp('--verify valid-package.json', '--cwd ./test/fixtures/packages/')
.gulp('--verify valid-package.json', '--cwd ./test/fixtures/packages/', '--proxy http://localhost:' + proxyPort)
.run(cb);
}

Expand Down

0 comments on commit cf79848

Please sign in to comment.