Skip to content
Browse files

specs for handling basic auth of RackResponse

  • Loading branch information...
1 parent 466267f commit 48ae511875b02ca80f633fd2c55f16b9f5b0d2c1 @jugyo jugyo committed Mar 30, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 spec/unit/rack_response_spec.rb
View
21 spec/unit/rack_response_spec.rb
@@ -4,6 +4,11 @@
before :each do
@rack_response = WebMock::RackResponse.new(MyRackApp)
@locked_rack_response = WebMock::RackResponse.new(MyLockedRackApp)
+ @rack_response_with_basic_auth = WebMock::RackResponse.new(
+ Rack::Auth::Basic.new(MyRackApp) do |username, password|
+ username == 'username' && password == 'password'
+ end
+ )
end
it "should hook up to a rack appliance" do
@@ -48,4 +53,20 @@
response = @rack_response.evaluate(request)
response.body.should include('Good to meet you, Jimmy!')
end
+
+ describe 'basic auth request' do
+ it 'should be failure when wrong credentials' do
+ request = WebMock::RequestSignature.new(:get, 'foo:bar@www.example.com')
+ response = @rack_response_with_basic_auth.evaluate(request)
+ response.status.first.should == 401
+ response.body.should_not include('This is my root!')
+ end
+
+ it 'should be success when valid credentials' do
+ request = WebMock::RequestSignature.new(:get, 'username:password@www.example.com')
+ response = @rack_response_with_basic_auth.evaluate(request)
+ response.status.first.should == 200
+ response.body.should include('This is my root!')
+ end
+ end
end

0 comments on commit 48ae511

Please sign in to comment.
Something went wrong with that request. Please try again.