spec/lib/billy/handlers/proxy_handler_spec.rb in puffing-billy-0.6.0 vs spec/lib/billy/handlers/proxy_handler_spec.rb in puffing-billy-0.6.1

- old
+ new

@@ -3,11 +3,11 @@ describe Billy::ProxyHandler do subject { Billy::ProxyHandler.new } let(:request) do { method: 'post', - url: 'http://example.test:8080/index?some=param', + url: 'http://usern:pw@example.test:8080/index?some=param', headers: { 'Accept-Encoding' => 'gzip', 'Cache-Control' => 'no-cache' }, body: 'Some body' } end @@ -48,10 +48,31 @@ 'http://example.test:8080/index?some=param', request[:headers], request[:body])).to be false end end + + context 'as a regex' do + before do + expect(Billy.config).to receive(:whitelist) { [%r{example\.test\/a}] } + end + + it 'handles requests for the host without a port' do + expect(subject.handles_request?(request[:method], + 'http://example.test/a', + request[:headers], + request[:body])).to be true + end + + it 'handles requests for the host with a port' do + expect(subject.handles_request?(request[:method], + 'http://example.test:8080/a', + request[:headers], + request[:body])).to be true + end + end + context 'without a port' do before do expect(Billy.config).to receive(:whitelist) { ['example.test'] } end @@ -182,8 +203,24 @@ subject.handle_request(request[:method], request[:url], request[:headers], request[:body]) end + end + end + + describe '#build_request_options' do + it 'creates authorization header when URL has basic auth' do + request_options = subject.send(:build_request_options, request[:url], + request[:headers], + request[:body]) + expect(request_options[:head]).to have_key 'authorization' + end + + it 'does not include authorization header without basic auth' do + request_options = subject.send(:build_request_options, request[:url].gsub('usern:pw@',''), + request[:headers], + request[:body]) + expect(request_options[:head]).not_to have_key 'authorization' end end end