summaryrefslogtreecommitdiff
path: root/users/test
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-09-03 10:43:34 -0700
committerjessib <jessib@riseup.net>2013-09-03 10:43:34 -0700
commitf3e17149116f6a3aeb87f8a6d0ecf29e8e33ad93 (patch)
tree2dfae950a25c5db22a456d96016898c5a9add5a6 /users/test
parentf97777ed0252abe94f8d94cb4565fb5a6c35ab23 (diff)
parent42cef3117cd97d9c37968a8cf63d33b27b4b8ed2 (diff)
Merge pull request #75 from azul/feature/token-expiry
Token expiry
Diffstat (limited to 'users/test')
-rw-r--r--users/test/functional/test_helpers_test.rb2
-rw-r--r--users/test/support/auth_test_helper.rb2
-rw-r--r--users/test/unit/token_test.rb33
3 files changed, 33 insertions, 4 deletions
diff --git a/users/test/functional/test_helpers_test.rb b/users/test/functional/test_helpers_test.rb
index 9bd01ad..845e516 100644
--- a/users/test/functional/test_helpers_test.rb
+++ b/users/test/functional/test_helpers_test.rb
@@ -21,7 +21,7 @@ class TestHelpersTest < ActionController::TestCase
def test_login_stubs_token
login
assert @token
- assert_equal @current_user, @token.user
+ assert_equal @current_user, @token.authenticate
end
def test_login_adds_token_header
diff --git a/users/test/support/auth_test_helper.rb b/users/test/support/auth_test_helper.rb
index 47147fc..609f115 100644
--- a/users/test/support/auth_test_helper.rb
+++ b/users/test/support/auth_test_helper.rb
@@ -41,7 +41,7 @@ module AuthTestHelper
protected
def header_for_token_auth
- @token = find_record(:token, :user => @current_user)
+ @token = find_record(:token, :authenticate => @current_user)
ActionController::HttpAuthentication::Token.encode_credentials @token.id
end
end
diff --git a/users/test/unit/token_test.rb b/users/test/unit/token_test.rb
index bff6b71..f56c576 100644
--- a/users/test/unit/token_test.rb
+++ b/users/test/unit/token_test.rb
@@ -1,19 +1,20 @@
require 'test_helper'
class ClientCertificateTest < ActiveSupport::TestCase
+ include StubRecordHelper
setup do
- @user = FactoryGirl.create(:user)
+ @user = find_record :user
end
teardown do
- @user.destroy
end
test "new token for user" do
sample = Token.new(:user_id => @user.id)
assert sample.valid?
assert_equal @user.id, sample.user_id
+ assert_equal @user, sample.authenticate
end
test "token id is secure" do
@@ -34,4 +35,32 @@ class ClientCertificateTest < ActiveSupport::TestCase
assert !sample.valid?, "Token should require a user record"
end
+ test "token updates timestamps" do
+ sample = Token.new(user_id: @user.id)
+ sample.last_seen_at = 1.minute.ago
+ sample.expects(:save)
+ assert_equal @user, sample.authenticate
+ assert Time.now - sample.last_seen_at < 1.minute, "last_seen_at has not been updated"
+ end
+
+ test "token will not expire if token_expires_after is not set" do
+ sample = Token.new(user_id: @user.id)
+ sample.last_seen_at = 2.years.ago
+ with_config auth: {} do
+ sample.expects(:save)
+ assert_equal @user, sample.authenticate
+ end
+ end
+
+ test "expired token returns nil on authenticate" do
+ sample = Token.new(user_id: @user.id)
+ sample.last_seen_at = 2.hours.ago
+ with_config auth: {token_expires_after: 60} do
+ sample.expects(:destroy)
+ assert_nil sample.authenticate
+ end
+ end
+
+
+
end