Skip to content

Commit

Permalink
changed the offset parameter to the secure module instead of the chec…
Browse files Browse the repository at this point in the history
…k method
  • Loading branch information
alansikora committed Sep 30, 2013
1 parent 458b9f9 commit eaddda7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/mailgun/secure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def initialize(mailgun)

# check request auth
def check_request_auth(timestamp, token, signature, offset=-5)
offset = Time.now.to_i + offset * 60
return false if timestamp < offset
if offset != 0
offset = Time.now.to_i + offset * 60
return false if timestamp < offset
end

return signature == OpenSSL::HMAC.hexdigest(
OpenSSL::Digest::Digest.new('sha256'),
Expand Down
8 changes: 8 additions & 0 deletions spec/secure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
result.should be_false
end

it "check_request_auth should return true for an authentication generated any time when the check offset is 0" do
timestamp, token, signature = generate_request_auth("some-api-key", -6)

result = @mailgun.secure.check_request_auth(timestamp, token, signature, 0)

result.should be_true
end

it "check_request_auth should return false for a different api key, token or signature" do
timestamp, token, signature = generate_request_auth("some-different-api-key")

Expand Down

0 comments on commit eaddda7

Please sign in to comment.