Permalink
Browse files

Add basic auth support

  • Loading branch information...
1 parent 1737b4c commit d583f8eb935353c7627be7d35bae59ca0647e31b Denis Goeury committed Mar 27, 2012
Showing with 18 additions and 0 deletions.
  1. +1 −0 lib/rsolr/connection.rb
  2. +17 −0 spec/api/connection_spec.rb
View
@@ -67,6 +67,7 @@ def setup_raw_request request_context
raw_request = http_method.new request_context[:uri].request_uri
# end
raw_request.initialize_http_header headers
+ raw_request.basic_auth(request_context[:uri].user, request_context[:uri].password) if request_context[:uri].user && request_context[:uri].password
raw_request
end
@@ -1,4 +1,6 @@
require 'spec_helper'
+require 'base64'
+
describe "RSolr::Connection" do
context "setup_raw_request" do
@@ -56,4 +58,19 @@
end
end
+ describe "basic auth support" do
+ let(:http) { mock(Net::HTTP).as_null_object }
+
+ before do
+ Net::HTTP.stub(:new) { http }
+ end
+
+ it "sets the authorization header" do
+ http.should_receive(:request) do |request|
+ request.fetch('authorization').should == "Basic #{Base64.encode64("joe:pass")}".strip
+ mock(Net::HTTPResponse).as_null_object
+ end
+ RSolr::Connection.new.execute nil, :uri => URI.parse("http://joe:pass@localhost:8983/solr"), :method => :get
+ end
+ end
end

0 comments on commit d583f8e

Please sign in to comment.