diff --git a/History.txt b/History.txt index c845241..7b59579 100644 --- a/History.txt +++ b/History.txt @@ -20,6 +20,7 @@ CHANGED: Due to a reorganization, if you're currently requiring "webrat/rspec-ra * Bug fixes + * Remove newlines from HTTP Basic authentication credentials (Michael Klett) * Require nokogiri form rspec-rails.rb (David Chelimsky) * Fix logger issue when running inside Cucumber (Damian Janowski) * Fix various issues related to submitting values with HTML entities (Kieran P) diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index ee180d7..619f3c6 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -105,7 +105,7 @@ For example: end def basic_auth(user, pass) - encoded_login = ["#{user}:#{pass}"].pack("m*") + encoded_login = ["#{user}:#{pass}"].pack("m*").gsub(/\n/, '') header('HTTP_AUTHORIZATION', "Basic #{encoded_login}") end diff --git a/spec/public/basic_auth_spec.rb b/spec/public/basic_auth_spec.rb index 1d6b590..655f417 100644 --- a/spec/public/basic_auth_spec.rb +++ b/spec/public/basic_auth_spec.rb @@ -6,7 +6,7 @@ describe "Basic Auth HTTP headers" do end it "should be present in visit" do - webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"}) + webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ="}) visit("/") end @@ -18,7 +18,18 @@ describe "Basic Auth HTTP headers" do HTML - webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ=\n"}) + webrat_session.should_receive(:post).with("/form1", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQ="}) click_button end + + context "with long username and password combination" do + before do + basic_auth('user', 'secret1234567890123456789012345678901234567890123456789012345678901234567890') + end + + it "should be present, without new lines, in visit" do + webrat_session.should_receive(:get).with("/", {}, {'HTTP_AUTHORIZATION' => "Basic dXNlcjpzZWNyZXQxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkw"}) + visit("/") + end + end end