Skip to content

Commit

Permalink
Added class method for signing requests
Browse files Browse the repository at this point in the history
  • Loading branch information
seangeo committed Jul 11, 2008
1 parent 73abe30 commit 2754420
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/auth-hmac.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
#
class AuthHMAC

# Signs a request using a given access key id and secret.
#
def AuthHMAC.sign!(request, access_key_id, secret)
self.new(access_key_id => secret).sign!(request, access_key_id)
end

# Create an AuthHMAC instance using a given credential store.
#
# A credential store must respond to the [] method and return
# the secret for the access key id passed to [].
#
def initialize(credential_store)
@credential_store = credential_store
end
Expand Down
12 changes: 12 additions & 0 deletions spec/auth-hmac_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

describe AuthHMAC do
describe ".sign!" do
it "should sign using the key passed in as a parameter" do
date = "Thu, 10 Jul 2008 03:29:56 GMT"
request = Net::HTTP::Put.new("/path/to/put?foo=bar&bar=foo",
'content-type' => 'text/plain',
'content-md5' => 'blahblah',
'date' => date)
AuthHMAC.sign!(request, "my-key-id", "secret")
request['Authorization'].should == "AuthHMAC my-key-id:71wAJM4IIu/3o6lcqx/tw7XnAJs="
end
end

describe "#sign!" do
before(:each) do
@store = mock('store')
@store.stub!(:[]).and_return("")
Expand Down

0 comments on commit 2754420

Please sign in to comment.