1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/test/unit/no_proxy.js

91 lines
3.5 KiB
JavaScript
Raw Normal View History

2017-04-19 21:15:28 +02:00
'use strict';
2013-11-24 18:07:18 +01:00
2017-04-19 21:15:28 +02:00
let assert = require('assert');
let Storage = require('../../lib/up-storage');
require('../../lib/logger').setup([]);
2013-11-24 18:07:18 +01:00
function setup(host, config, mainconfig) {
2017-04-19 21:15:28 +02:00
config.url = host;
return new Storage(config, mainconfig);
2013-11-24 18:07:18 +01:00
}
2013-12-19 16:11:54 +01:00
describe('Use proxy', function() {
it('should work fine without proxy', function() {
2017-04-19 21:15:28 +02:00
let x = setup('http://x/x', {}, {});
assert.equal(x.proxy, null);
});
2013-11-24 18:07:18 +01:00
it('local config should take priority', function() {
2017-04-19 21:15:28 +02:00
let x = setup('http://x/x', {http_proxy: '123'}, {http_proxy: '456'});
assert.equal(x.proxy, '123');
});
2013-11-24 18:07:18 +01:00
it('no_proxy is invalid', function() {
let x = setup('http://x/x', {http_proxy: '123', no_proxy: false}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://x/x', {http_proxy: '123', no_proxy: null}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://x/x', {http_proxy: '123', no_proxy: []}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://x/x', {http_proxy: '123', no_proxy: ''}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
});
2013-11-24 18:07:18 +01:00
it('no_proxy - simple/include', function() {
2017-04-19 21:15:28 +02:00
let x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'});
assert.equal(x.proxy, undefined);
});
2013-11-24 18:07:18 +01:00
it('no_proxy - simple/not', function() {
2017-04-19 21:15:28 +02:00
let x = setup('http://localhost', {http_proxy: '123'}, {no_proxy: 'blah'});
assert.equal(x.proxy, '123');
});
2013-11-24 18:07:18 +01:00
it('no_proxy - various, single string', function() {
let x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
x = setup('http://blahblah', {}, {http_proxy: '123', no_proxy: '.blah'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {http_proxy: '123', no_proxy: '.blah'}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
x = setup('http://blah', {http_proxy: '123', no_proxy: '.blah'}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
x = setup('http://blahh', {http_proxy: '123', no_proxy: 'blah'}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
});
2013-11-24 18:07:18 +01:00
it('no_proxy - various, array', function() {
let x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
x = setup('http://blah.foo', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
x = setup('http://foo.baz', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://blahblah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('http://blah.blah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
});
2013-11-24 18:07:18 +01:00
it('no_proxy - hostport', function() {
let x = setup('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
x = setup('http://localhost:8080', {http_proxy: '123'}, {no_proxy: 'localhost'});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
});
2013-11-24 18:07:18 +01:00
it('no_proxy - secure', function() {
let x = setup('https://something', {http_proxy: '123'}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, null);
x = setup('https://something', {https_proxy: '123'}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
x = setup('https://something', {http_proxy: '456', https_proxy: '123'}, {});
2017-04-19 21:15:28 +02:00
assert.equal(x.proxy, '123');
});
});