diff options
author | jessib <jessib@riseup.net> | 2013-11-12 09:16:45 -0800 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-11-12 09:16:45 -0800 |
commit | 8295db1a8cf334ff8666e5ec29455c199c7ffc73 (patch) | |
tree | c74e801c31a8d58b157df266550bf456934c9cfc /users/test | |
parent | a976436d6c022b5a1d142a931ba0bf6d27a00e9c (diff) | |
parent | a7cd2ef0877e79302f27fb175384a0cf4ded52d9 (diff) |
Merge pull request #110 from azul/feature/cleanup-expired-tokens
Feature/cleanup expired tokens
Diffstat (limited to 'users/test')
-rw-r--r-- | users/test/factories.rb | 4 | ||||
-rw-r--r-- | users/test/unit/token_test.rb | 23 |
2 files changed, 23 insertions, 4 deletions
diff --git a/users/test/factories.rb b/users/test/factories.rb index c87e290..f5fb77d 100644 --- a/users/test/factories.rb +++ b/users/test/factories.rb @@ -19,6 +19,8 @@ FactoryGirl.define do end end - factory :token + factory :token do + user + end end diff --git a/users/test/unit/token_test.rb b/users/test/unit/token_test.rb index f56c576..6c9f209 100644 --- a/users/test/unit/token_test.rb +++ b/users/test/unit/token_test.rb @@ -7,9 +7,6 @@ class ClientCertificateTest < ActiveSupport::TestCase @user = find_record :user end - teardown do - end - test "new token for user" do sample = Token.new(:user_id => @user.id) assert sample.valid? @@ -61,6 +58,26 @@ class ClientCertificateTest < ActiveSupport::TestCase end end + test "Token.destroy_all_expired is noop if no expiry is set" do + expired = FactoryGirl.create :token, last_seen_at: 2.hours.ago + with_config auth: {} do + Token.destroy_all_expired + end + assert_equal expired, Token.find(expired.id) + end + + test "Token.destroy_all_expired cleans up expired tokens only" do + expired = FactoryGirl.create :token, last_seen_at: 2.hours.ago + fresh = FactoryGirl.create :token + with_config auth: {token_expires_after: 60} do + Token.destroy_all_expired + end + assert_nil Token.find(expired.id) + assert_equal fresh, Token.find(fresh.id) + fresh.destroy + end + + end |