summaryrefslogtreecommitdiffstats
path: root/test/unit/token_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-14 21:47:07 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-14 21:47:07 +0000
commit812da860b376d857fc7f1c4b06b26c6bec9232f7 (patch)
tree3c6b72c824c49c1dfef87aff50823c270d6106cc /test/unit/token_test.rb
parentadb4a575dc8878f043e8bf54a6a542ee618a1e64 (diff)
downloadredmine-812da860b376d857fc7f1c4b06b26c6bec9232f7.tar.gz
redmine-812da860b376d857fc7f1c4b06b26c6bec9232f7.zip
Adds token finder methods.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11374 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/token_test.rb')
-rw-r--r--test/unit/token_test.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/unit/token_test.rb b/test/unit/token_test.rb
index 4b7727ab2..45399e0ee 100644
--- a/test/unit/token_test.rb
+++ b/test/unit/token_test.rb
@@ -58,4 +58,56 @@ class TokenTest < ActiveSupport::TestCase
assert_equal 2, Token.destroy_expired
end
end
+
+ def test_find_active_user_should_return_user
+ token = Token.create!(:user_id => 1, :action => 'api')
+ assert_equal User.find(1), Token.find_active_user('api', token.value)
+ end
+
+ def test_find_active_user_should_return_nil_for_locked_user
+ token = Token.create!(:user_id => 1, :action => 'api')
+ User.find(1).lock!
+ assert_nil Token.find_active_user('api', token.value)
+ end
+
+ def test_find_user_should_return_user
+ token = Token.create!(:user_id => 1, :action => 'api')
+ assert_equal User.find(1), Token.find_user('api', token.value)
+ end
+
+ def test_find_user_should_return_locked_user
+ token = Token.create!(:user_id => 1, :action => 'api')
+ User.find(1).lock!
+ assert_equal User.find(1), Token.find_user('api', token.value)
+ end
+
+ def test_find_token_should_return_the_token
+ token = Token.create!(:user_id => 1, :action => 'api')
+ assert_equal token, Token.find_token('api', token.value)
+ end
+
+ def test_find_token_should_return_the_token_with_validity
+ token = Token.create!(:user_id => 1, :action => 'api', :created_on => 1.hour.ago)
+ assert_equal token, Token.find_token('api', token.value, 1)
+ end
+
+ def test_find_token_should_return_nil_with_wrong_action
+ token = Token.create!(:user_id => 1, :action => 'feeds')
+ assert_nil Token.find_token('api', token.value)
+ end
+
+ def test_find_token_should_return_nil_with_wrong_action
+ token = Token.create!(:user_id => 1, :action => 'feeds')
+ assert_nil Token.find_token('api', Token.generate_token_value)
+ end
+
+ def test_find_token_should_return_nil_without_user
+ token = Token.create!(:user_id => 999, :action => 'api')
+ assert_nil Token.find_token('api', token.value)
+ end
+
+ def test_find_token_should_return_nil_with_validity_expired
+ token = Token.create!(:user_id => 999, :action => 'api', :created_on => 2.days.ago)
+ assert_nil Token.find_token('api', token.value, 1)
+ end
end