2019-07-16 01:40:01 -05:00
|
|
|
import ProxyStorage from '../../../../src/lib/up-storage';
|
2017-04-19 14:15:28 -05:00
|
|
|
|
2019-05-20 00:53:47 -05:00
|
|
|
require('../../../../src/lib/logger').setup([]);
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2019-07-16 01:40:01 -05:00
|
|
|
function setupProxy(host, uplinkConf, appConfig) {
|
|
|
|
uplinkConf.url = host;
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2019-07-16 01:40:01 -05:00
|
|
|
return new ProxyStorage(uplinkConf, appConfig);
|
2013-11-24 12:07:18 -05:00
|
|
|
}
|
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
describe('Use proxy', () => {
|
|
|
|
test('should work fine without proxy', () => {
|
2017-08-06 14:54:15 -05:00
|
|
|
let x = setupProxy('http://x/x', {}, {});
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('local config should take priority', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('http://x/x', { http_proxy: '123' }, { http_proxy: '456' });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('no_proxy is invalid', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: false }, {});
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: null }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: [] }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: '' }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('no_proxy - simple/include', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('http://localhost', { http_proxy: '123' }, { no_proxy: 'localhost' });
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('no_proxy - simple/not', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('http://localhost', { http_proxy: '123' }, { no_proxy: 'blah' });
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('no_proxy - various, single string', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('http://blahblah', { http_proxy: '123' }, { no_proxy: 'blah' });
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blah.blah', {}, { http_proxy: '123', no_proxy: 'blah' });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blahblah', {}, { http_proxy: '123', no_proxy: '.blah' });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blah.blah', { http_proxy: '123', no_proxy: '.blah' }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blah', { http_proxy: '123', no_proxy: '.blah' }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blahh', { http_proxy: '123', no_proxy: 'blah' }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('no_proxy - various, array', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('http://blahblah', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blah.blah', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blah.foo', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://foo.baz', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blahblah', { http_proxy: '123' }, { no_proxy: ['foo', 'bar', 'blah'] });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://blah.blah', { http_proxy: '123' }, { no_proxy: ['foo', 'bar', 'blah'] });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('no_proxy - hostport', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('http://localhost:80', { http_proxy: '123' }, { no_proxy: 'localhost' });
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('http://localhost:8080', { http_proxy: '123' }, { no_proxy: 'localhost' });
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
2013-11-24 12:07:18 -05:00
|
|
|
|
2017-11-01 11:47:20 -05:00
|
|
|
test('no_proxy - secure', () => {
|
2021-03-14 02:42:46 -05:00
|
|
|
let x = setupProxy('https://something', { http_proxy: '123' }, {});
|
2019-05-20 00:53:47 -05:00
|
|
|
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('https://something', { https_proxy: '123' }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2021-03-14 02:42:46 -05:00
|
|
|
x = setupProxy('https://something', { http_proxy: '456', https_proxy: '123' }, {});
|
2018-10-03 16:39:45 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2017-04-19 14:15:28 -05:00
|
|
|
});
|
|
|
|
});
|