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