Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/secure_api/api_token/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def within_time_tolerance(clear_token)
clear_token[/#{prefix}([0-9]+)#{suffix}/]
token_time = $1 || 0
elapsed_time = timestamp.to_i - token_time.to_i
elapsed_time < time_tolerance_seconds
elapsed_time.abs < time_tolerance_seconds
end
end
end
14 changes: 14 additions & 0 deletions test/api_token_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ def test_a_token_with_the_correct_info_and_time_stamp_gt_10_mins_old_is_invalid
end
end

def test_a_token_with_a_future_timestamp_beyond_tolerance_is_invalid
twenty_minutes_ago = Time.now.utc.to_i - (60 * 20)
ApiToken.stub(:timestamp, twenty_minutes_ago) do
refute ApiToken.valid?(@token)
Comment thread
ds-mariole marked this conversation as resolved.
end
end

def test_a_token_with_a_future_timestamp_within_tolerance_is_valid
nine_minutes_ago = Time.now.utc.to_i - (60 * 9)
ApiToken.stub(:timestamp, nine_minutes_ago) do
assert ApiToken.valid?(@token)
Comment thread
ds-mariole marked this conversation as resolved.
end
end

def test_legacy_encryption_and_decryption_when_enabled
SecureApi.configure do |config|
config.secure_api_pass_phrase = 'test pass phrase'
Expand Down