2017-07-03 15:06:09 -04:00
|
|
|
require "test_helper"
|
|
|
|
require "active_support/core_ext/securerandom"
|
|
|
|
|
2017-07-05 07:06:29 -04:00
|
|
|
class ActiveVault::VerifiedKeyWithExpirationTest < ActiveSupport::TestCase
|
2017-07-03 15:06:09 -04:00
|
|
|
FIXTURE_KEY = SecureRandom.base58(24)
|
|
|
|
|
|
|
|
test "without expiration" do
|
2017-07-05 07:06:29 -04:00
|
|
|
encoded_key = ActiveVault::VerifiedKeyWithExpiration.encode(FIXTURE_KEY)
|
|
|
|
assert_equal FIXTURE_KEY, ActiveVault::VerifiedKeyWithExpiration.decode(encoded_key)
|
2017-07-03 15:06:09 -04:00
|
|
|
end
|
2017-07-03 15:12:11 -04:00
|
|
|
|
|
|
|
test "with expiration" do
|
2017-07-05 07:06:29 -04:00
|
|
|
encoded_key = ActiveVault::VerifiedKeyWithExpiration.encode(FIXTURE_KEY, expires_in: 1.minute)
|
|
|
|
assert_equal FIXTURE_KEY, ActiveVault::VerifiedKeyWithExpiration.decode(encoded_key)
|
2017-07-03 15:12:11 -04:00
|
|
|
|
|
|
|
travel 2.minutes
|
2017-07-05 07:06:29 -04:00
|
|
|
assert_nil ActiveVault::VerifiedKeyWithExpiration.decode(encoded_key)
|
2017-07-03 15:12:11 -04:00
|
|
|
end
|
2017-07-03 15:06:09 -04:00
|
|
|
end
|