spec/headers_spec.rb in api-auth-1.1.0 vs spec/headers_spec.rb in api-auth-1.2.0
- old
+ new
@@ -89,10 +89,22 @@
:method => :put)
headers = ApiAuth::Headers.new(request)
headers.canonical_string
request.headers['DATE'].should be_nil
end
+
+ it "doesn't mess up symbol based headers" do
+ headers = { 'Content-MD5' => "e59ff97941044f85df5297e1c302d260",
+ :content_type => "text/plain",
+ 'Date' => "Mon, 23 Jan 1984 03:29:56 GMT" }
+ @request = RestClient::Request.new(:url => "/resource.xml?foo=bar&bar=foo",
+ :headers => headers,
+ :method => :put)
+ @headers = ApiAuth::Headers.new(@request)
+ ApiAuth.sign!(@request, "some access id", "some secret key")
+ @request.processed_headers.should have_key('Content-Type')
+ end
end
describe "with Curb" do
before(:each) do
@@ -136,12 +148,14 @@
end
end
describe "with ActionController" do
+ let(:request_klass){ ActionDispatch::Request rescue ActionController::Request }
+
before(:each) do
- @request = ActionController::Request.new(
+ @request = request_klass.new(
'PATH_INFO' => '/resource.xml',
'QUERY_STRING' => 'foo=bar&bar=foo',
'REQUEST_METHOD' => 'PUT',
'CONTENT_MD5' => 'e59ff97941044f85df5297e1c302d260',
'CONTENT_TYPE' => 'text/plain',
@@ -157,22 +171,22 @@
@headers.sign_header("alpha")
@headers.authorization_header.should == "alpha"
end
it "should set the DATE header if one is not already present" do
- @request = ActionController::Request.new(
+ @request = request_klass.new(
'PATH_INFO' => '/resource.xml',
'QUERY_STRING' => 'foo=bar&bar=foo',
'REQUEST_METHOD' => 'PUT',
'CONTENT_MD5' => 'e59ff97941044f85df5297e1c302d260',
'CONTENT_TYPE' => 'text/plain')
ApiAuth.sign!(@request, "some access id", "some secret key")
@request.headers['DATE'].should_not be_nil
end
it "should not set the DATE header just by asking for the canonical_string" do
- request = ActionController::Request.new(
+ request = request_klass.new(
'PATH_INFO' => '/resource.xml',
'QUERY_STRING' => 'foo=bar&bar=foo',
'REQUEST_METHOD' => 'PUT',
'CONTENT_MD5' => 'e59ff97941044f85df5297e1c302d260',
'CONTENT_TYPE' => 'text/plain')
@@ -217,7 +231,54 @@
headers = ApiAuth::Headers.new(request)
headers.canonical_string
request.env['DATE'].should be_nil
end
end
+
+ describe "with HTTPI" do
+ before(:each) do
+ @request = HTTPI::Request.new("http://localhost/resource.xml?foo=bar&bar=foo")
+ @request.headers.merge!({
+ 'content-type' => 'text/plain',
+ 'content-md5' => 'e59ff97941044f85df5297e1c302d260',
+ 'date' => "Mon, 23 Jan 1984 03:29:56 GMT"
+ })
+ @headers = ApiAuth::Headers.new(@request)
+ end
+
+ it "should generate the proper canonical string" do
+ @headers.canonical_string.should == CANONICAL_STRING
+ end
+
+ it "should set the authorization header" do
+ @headers.sign_header("alpha")
+ @headers.authorization_header.should == "alpha"
+ end
+
+ it "should set the DATE header if one is not already present" do
+ @request = Net::HTTP::Put.new("/resource.xml?foo=bar&bar=foo",
+ 'content-type' => 'text/plain',
+ 'content-md5' => 'e59ff97941044f85df5297e1c302d260')
+ ApiAuth.sign!(@request, "some access id", "some secret key")
+ @request['DATE'].should_not be_nil
+ end
+
+ it "should not set the DATE header just by asking for the canonical_string" do
+ request = Net::HTTP::Put.new("/resource.xml?foo=bar&bar=foo",
+ 'content-type' => 'text/plain',
+ 'content-md5' => 'e59ff97941044f85df5297e1c302d260')
+ headers = ApiAuth::Headers.new(request)
+ headers.canonical_string
+ request['DATE'].should be_nil
+ end
+
+ context "md5_mismatch?" do
+ it "is false if no md5 header is present" do
+ request = Net::HTTP::Put.new("/resource.xml?foo=bar&bar=foo",
+ 'content-type' => 'text/plain')
+ headers = ApiAuth::Headers.new(request)
+ headers.md5_mismatch?.should be_false
+ end
+ end
+ end
end