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