Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from pezra/promiscuous-basic-auth

Promiscuous basic auth
  • Loading branch information...
commit d2fea39fa93ed0ef2ce7f694db111c4dc70fcec4 2 parents c2c5d6e + 5ac9bac
Paul Sadauskas authored
2  History.txt
View
@@ -1,6 +1,8 @@
Version NEXT
============
* Fixed bug with using form data representations with authentication.
+ * Added PromiscuousBasicAuthenticator to support basic authentication
+ with servers that do not return challenge headers.
Version 1.0.0
============
1  Manifest
View
@@ -6,6 +6,7 @@ Rakefile
lib/resourceful.rb
lib/resourceful/abstract_form_data.rb
lib/resourceful/authentication_manager.rb
+lib/resourceful/promiscuous_basic_authenticator.rb
lib/resourceful/cache_manager.rb
lib/resourceful/exceptions.rb
lib/resourceful/header.rb
1  lib/resourceful.rb
View
@@ -15,6 +15,7 @@ module Resourceful
autoload :MultipartFormData, 'resourceful/multipart_form_data'
autoload :UrlencodedFormData, 'resourceful/urlencoded_form_data'
autoload :StubbedResourceProxy, 'resourceful/stubbed_resource_proxy'
+ autoload :PromiscuousBasicAuthenticator, 'resourceful/promiscuous_basic_authenticator'
extend Simple
end
3  lib/resourceful/authentication_manager.rb
View
@@ -27,7 +27,7 @@ def add_credentials(request)
end
- class BasicAuthenticator
+ class BasicAuthenticator
def initialize(realm, username, password)
@realm, @username, @password = realm, username, password
@@ -57,7 +57,6 @@ def add_credentials_to(request)
def credentials
HTTPAuth::Basic.pack_authorization(@username, @password)
end
-
end
class DigestAuthenticator
18 lib/resourceful/promiscuous_basic_authenticator.rb
View
@@ -0,0 +1,18 @@
+module Resourceful
+ # This class provides HTTP basic authentication without regard to
+ # the realm of receiving resource. This will send your username and
+ # password with any request made while it is in play.
+ class PromiscuousBasicAuthenticator < BasicAuthenticator
+ def initialize(username, password)
+ super(nil, username, password)
+ end
+
+ def valid_for?(challenge_response)
+ true
+ end
+
+ def can_handle?(request)
+ true
+ end
+ end
+end
30 spec/resourceful/promiscuous_basic_authenticator_spec.rb
View
@@ -0,0 +1,30 @@
+require File.expand_path("../spec_helper", File.dirname(__FILE__))
+
+describe Resourceful::PromiscuousBasicAuthenticator do
+ before do
+ @authenticator = Resourceful::PromiscuousBasicAuthenticator.new('jim', 'mypasswd')
+ end
+
+ it "should always claim to be valid for a challenge response" do
+ challenge_resp = mock("a challenge response")
+ @authenticator.valid_for?(challenge_resp).should eql(true)
+ end
+
+ it "should always claim to handle any request" do
+ a_req = mock("a request")
+ @authenticator.valid_for?(a_req).should eql(true)
+ end
+
+ it "be creatable with just a username and password" do
+ Resourceful::PromiscuousBasicAuthenticator.new('jim', 'mypasswd').should be_instance_of(Resourceful::PromiscuousBasicAuthenticator)
+ end
+
+ it "add credentials to request" do
+ header = mock('header')
+ header.should_receive(:[]=).with("Authorization", "Basic amltOm15cGFzc3dk")
+ a_req = mock("a request", :header => header)
+
+ @authenticator.add_credentials_to(a_req)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.