2020-03-03 17:59:19 -05:00
|
|
|
import { ProxyStorage } from '../src/up-storage';
|
|
|
|
|
|
|
|
require('@verdaccio/logger').setup([]);
|
|
|
|
|
|
|
|
function setupProxy(host, uplinkConf, appConfig) {
|
|
|
|
uplinkConf.url = host;
|
|
|
|
|
|
|
|
return new ProxyStorage(uplinkConf, appConfig);
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('Use proxy', () => {
|
|
|
|
test('should work fine without proxy', () => {
|
|
|
|
const x = setupProxy('http://x/x', {}, {});
|
|
|
|
|
|
|
|
expect(x.proxy).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('local config should take priority', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
const x = setupProxy('http://x/x', { http_proxy: '123' }, { http_proxy: '456' });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('no_proxy is invalid', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
let x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: false }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: null }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: [] }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://x/x', { http_proxy: '123', no_proxy: '' }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('no_proxy - simple/include', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
let x = setupProxy('http://localhost', { http_proxy: '123' }, { no_proxy: 'localhost' });
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
expect(x.proxy).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('no_proxy - simple/not', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
let x = setupProxy('http://localhost', { http_proxy: '123' }, { no_proxy: 'blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
expect(x.proxy).toEqual('123');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('no_proxy - various, single string', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
let x = setupProxy('http://blahblah', { http_proxy: '123' }, { no_proxy: 'blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blah.blah', {}, { http_proxy: '123', no_proxy: 'blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blahblah', {}, { http_proxy: '123', no_proxy: '.blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blah.blah', { http_proxy: '123', no_proxy: '.blah' }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blah', { http_proxy: '123', no_proxy: '.blah' }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blahh', { http_proxy: '123', no_proxy: 'blah' }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('no_proxy - various, array', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
let x = setupProxy('http://blahblah', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blah.blah', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blah.foo', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://foo.baz', { http_proxy: '123' }, { no_proxy: 'foo,bar,blah' });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blahblah', { http_proxy: '123' }, { no_proxy: ['foo', 'bar', 'blah'] });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://blah.blah', { http_proxy: '123' }, { no_proxy: ['foo', 'bar', 'blah'] });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('no_proxy - hostport', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
let x = setupProxy('http://localhost:80', { http_proxy: '123' }, { no_proxy: 'localhost' });
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
expect(x.proxy).toEqual(undefined);
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('http://localhost:8080', { http_proxy: '123' }, { no_proxy: 'localhost' });
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('no_proxy - secure', () => {
|
2020-08-13 16:27:00 -05:00
|
|
|
let x = setupProxy('https://something', { http_proxy: '123' }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
|
|
|
|
expect(x.proxy).toEqual(undefined);
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('https://something', { https_proxy: '123' }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
2020-08-13 16:27:00 -05:00
|
|
|
x = setupProxy('https://something', { http_proxy: '456', https_proxy: '123' }, {});
|
2020-03-03 17:59:19 -05:00
|
|
|
expect(x.proxy).toEqual('123');
|
|
|
|
});
|
|
|
|
});
|