2017-12-22 21:32:52 +01:00
|
|
|
import assert from 'assert';
|
|
|
|
import Storage from '../../src/lib/up-storage';
|
2017-04-19 21:15:28 +02:00
|
|
|
|
2017-06-21 19:02:52 +02:00
|
|
|
require('../../src/lib/logger').setup([]);
|
2013-11-24 18:07:18 +01:00
|
|
|
|
2017-08-06 21:54:15 +02:00
|
|
|
function setupProxy(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
|
|
|
}
|
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
describe('Use proxy', () => {
|
|
|
|
test('should work fine without proxy', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://x/x', {}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
|
|
|
});
|
2013-11-24 18:07:18 +01:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('local config should take priority', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://x/x', {http_proxy: '123'}, {http_proxy: '456'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
|
|
|
});
|
2013-11-24 18:07:18 +01:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('no_proxy is invalid', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: false}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: null}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://x/x', {http_proxy: '123', no_proxy: []}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('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
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('no_proxy - simple/include', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://localhost', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, undefined);
|
|
|
|
});
|
2013-11-24 18:07:18 +01:00
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('no_proxy - simple/not', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://localhost', {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
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('no_proxy - various, single string', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'blah'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://blah.blah', {}, {http_proxy: '123', no_proxy: 'blah'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://blahblah', {}, {http_proxy: '123', no_proxy: '.blah'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://blah.blah', {http_proxy: '123', no_proxy: '.blah'}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://blah', {http_proxy: '123', no_proxy: '.blah'}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('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
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('no_proxy - various, array', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://blah.blah', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://blah.foo', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://foo.baz', {http_proxy: '123'}, {no_proxy: 'foo,bar,blah'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('http://blahblah', {http_proxy: '123'}, {no_proxy: ['foo', 'bar', 'blah']});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('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
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('no_proxy - hostport', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('http://localhost:80', {http_proxy: '123'}, {no_proxy: 'localhost'});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('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
|
|
|
|
2017-11-01 17:47:20 +01:00
|
|
|
test('no_proxy - secure', () => {
|
2017-08-06 21:54:15 +02:00
|
|
|
let x = setupProxy('https://something', {http_proxy: '123'}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, null);
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('https://something', {https_proxy: '123'}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
2017-08-06 21:54:15 +02:00
|
|
|
x = setupProxy('https://something', {http_proxy: '456', https_proxy: '123'}, {});
|
2017-04-19 21:15:28 +02:00
|
|
|
assert.equal(x.proxy, '123');
|
|
|
|
});
|
|
|
|
});
|