authlogic 1.4.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of authlogic might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +19 -0
- data/Manifest.txt +111 -0
- data/README.rdoc +116 -389
- data/Rakefile +14 -7
- data/lib/authlogic.rb +33 -35
- data/lib/authlogic/acts_as_authentic/base.rb +91 -0
- data/lib/authlogic/acts_as_authentic/email.rb +77 -0
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +54 -0
- data/lib/authlogic/acts_as_authentic/login.rb +65 -0
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +24 -0
- data/lib/authlogic/acts_as_authentic/password.rb +215 -0
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +100 -0
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +66 -0
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +60 -0
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +127 -0
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +58 -0
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +32 -0
- data/lib/authlogic/{session/authenticates_many_association.rb → authenticates_many/association.rb} +10 -6
- data/lib/authlogic/authenticates_many/base.rb +55 -0
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -3
- data/lib/authlogic/controller_adapters/merb_adapter.rb +0 -4
- data/lib/authlogic/controller_adapters/rails_adapter.rb +0 -4
- data/lib/authlogic/crypto_providers/aes256.rb +0 -2
- data/lib/authlogic/crypto_providers/bcrypt.rb +0 -2
- data/lib/authlogic/crypto_providers/md5.rb +34 -0
- data/lib/authlogic/crypto_providers/sha1.rb +0 -2
- data/lib/authlogic/crypto_providers/sha512.rb +1 -3
- data/lib/authlogic/i18n.rb +1 -4
- data/lib/authlogic/random.rb +33 -0
- data/lib/authlogic/session/activation.rb +56 -0
- data/lib/authlogic/session/active_record_trickery.rb +15 -7
- data/lib/authlogic/session/base.rb +31 -456
- data/lib/authlogic/session/brute_force_protection.rb +50 -27
- data/lib/authlogic/session/callbacks.rb +24 -15
- data/lib/authlogic/session/cookies.rb +108 -22
- data/lib/authlogic/session/existence.rb +89 -0
- data/lib/authlogic/session/foundation.rb +63 -0
- data/lib/authlogic/session/http_auth.rb +23 -0
- data/lib/authlogic/session/id.rb +41 -0
- data/lib/authlogic/session/klass.rb +75 -0
- data/lib/authlogic/session/magic_columns.rb +75 -0
- data/lib/authlogic/session/magic_states.rb +58 -0
- data/lib/authlogic/session/params.rb +82 -19
- data/lib/authlogic/session/password.rb +156 -0
- data/lib/authlogic/session/{perishability.rb → perishable_token.rb} +4 -4
- data/lib/authlogic/session/persistence.rb +70 -0
- data/lib/authlogic/session/priority_record.rb +34 -0
- data/lib/authlogic/session/scopes.rb +57 -53
- data/lib/authlogic/session/session.rb +46 -31
- data/lib/authlogic/session/timeout.rb +65 -31
- data/lib/authlogic/session/unauthorized_record.rb +50 -0
- data/lib/authlogic/session/validation.rb +76 -0
- data/lib/authlogic/testing/test_unit_helpers.rb +3 -3
- data/lib/authlogic/version.rb +3 -3
- data/test/acts_as_authentic_test/base_test.rb +12 -0
- data/test/acts_as_authentic_test/email_test.rb +79 -0
- data/test/acts_as_authentic_test/logged_in_status_test.rb +36 -0
- data/test/acts_as_authentic_test/login_test.rb +79 -0
- data/test/acts_as_authentic_test/magic_columns_test.rb +27 -0
- data/test/acts_as_authentic_test/password_test.rb +212 -0
- data/test/acts_as_authentic_test/perishable_token_test.rb +56 -0
- data/test/acts_as_authentic_test/persistence_token_test.rb +55 -0
- data/test/acts_as_authentic_test/session_maintenance_test.rb +68 -0
- data/test/acts_as_authentic_test/single_access_test.rb +39 -0
- data/test/authenticates_many_test.rb +16 -0
- data/test/{crypto_provider_tests → crypto_provider_test}/aes256_test.rb +1 -1
- data/test/{crypto_provider_tests → crypto_provider_test}/bcrypt_test.rb +1 -1
- data/test/{crypto_provider_tests → crypto_provider_test}/sha1_test.rb +1 -1
- data/test/{crypto_provider_tests → crypto_provider_test}/sha512_test.rb +1 -1
- data/test/fixtures/employees.yml +4 -4
- data/test/fixtures/users.yml +6 -6
- data/test/libs/company.rb +6 -0
- data/test/libs/employee.rb +7 -0
- data/test/libs/employee_session.rb +2 -0
- data/test/libs/project.rb +3 -0
- data/test/libs/user_session.rb +2 -0
- data/test/random_test.rb +49 -0
- data/test/session_test/activation_test.rb +43 -0
- data/test/session_test/active_record_trickery_test.rb +26 -0
- data/test/session_test/brute_force_protection_test.rb +76 -0
- data/test/session_test/callbacks_test.rb +6 -0
- data/test/session_test/cookies_test.rb +107 -0
- data/test/session_test/credentials_test.rb +0 -0
- data/test/session_test/existence_test.rb +64 -0
- data/test/session_test/http_auth_test.rb +16 -0
- data/test/session_test/id_test.rb +17 -0
- data/test/session_test/klass_test.rb +35 -0
- data/test/session_test/magic_columns_test.rb +59 -0
- data/test/session_test/magic_states_test.rb +60 -0
- data/test/session_test/params_test.rb +53 -0
- data/test/session_test/password_test.rb +84 -0
- data/test/{session_tests → session_test}/perishability_test.rb +1 -1
- data/test/session_test/persistence_test.rb +21 -0
- data/test/{session_tests → session_test}/scopes_test.rb +2 -3
- data/test/session_test/session_test.rb +59 -0
- data/test/session_test/timeout_test.rb +43 -0
- data/test/session_test/unauthorized_record_test.rb +13 -0
- data/test/session_test/validation_test.rb +23 -0
- data/test/test_helper.rb +14 -29
- metadata +120 -112
- data/Manifest +0 -76
- data/authlogic.gemspec +0 -38
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/base.rb +0 -22
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb +0 -238
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb +0 -155
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/logged_in.rb +0 -51
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/perishability.rb +0 -71
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/persistence.rb +0 -94
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/session_maintenance.rb +0 -87
- data/lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/single_access.rb +0 -61
- data/lib/authlogic/orm_adapters/active_record_adapter/authenticates_many.rb +0 -58
- data/lib/authlogic/session/config.rb +0 -421
- data/lib/authlogic/session/errors.rb +0 -18
- data/lib/authlogic/session/record_info.rb +0 -24
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb +0 -154
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb +0 -157
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb +0 -24
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/perishability_test.rb +0 -41
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb +0 -54
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/session_maintenance_test.rb +0 -62
- data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/single_access_test.rb +0 -41
- data/test/orm_adapters_tests/active_record_adapter_tests/authenticates_many_test.rb +0 -32
- data/test/session_tests/active_record_trickery_test.rb +0 -14
- data/test/session_tests/authenticates_many_association_test.rb +0 -28
- data/test/session_tests/base_test.rb +0 -307
- data/test/session_tests/brute_force_protection_test.rb +0 -53
- data/test/session_tests/config_test.rb +0 -184
- data/test/session_tests/cookies_test.rb +0 -32
- data/test/session_tests/params_test.rb +0 -32
- data/test/session_tests/session_test.rb +0 -45
- data/test/session_tests/timeout_test.rb +0 -71
@@ -1,18 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
module Session
|
3
|
-
class Errors < ::ActiveRecord::Errors # :nodoc:
|
4
|
-
end
|
5
|
-
|
6
|
-
class NotActivated < ::StandardError # :nodoc:
|
7
|
-
def initialize(session)
|
8
|
-
super("You must activate the Authlogic::Session::Base.controller with a controller object before creating objects")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
class SessionInvalid < ::StandardError # :nodoc:
|
13
|
-
def initialize(session)
|
14
|
-
super("Authentication failed: #{session.errors.full_messages.to_sentence}")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Authlogic
|
2
|
-
module Session
|
3
|
-
module RecordInfo
|
4
|
-
def self.included(klass)
|
5
|
-
klass.before_create :update_info
|
6
|
-
end
|
7
|
-
|
8
|
-
private
|
9
|
-
def update_info
|
10
|
-
record.login_count = (record.login_count.blank? ? 1 : record.login_count + 1) if record.respond_to?(:login_count)
|
11
|
-
|
12
|
-
if record.respond_to?(:current_login_at)
|
13
|
-
record.last_login_at = record.current_login_at if record.respond_to?(:last_login_at)
|
14
|
-
record.current_login_at = klass.default_timezone == :utc ? Time.now.utc : Time.now
|
15
|
-
end
|
16
|
-
|
17
|
-
if record.respond_to?(:current_login_ip)
|
18
|
-
record.last_login_ip = record.current_login_ip if record.respond_to?(:last_login_ip)
|
19
|
-
record.current_login_ip = controller.request.remote_ip
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../test_helper.rb'
|
2
|
-
|
3
|
-
module ORMAdaptersTests
|
4
|
-
module ActiveRecordAdapterTests
|
5
|
-
module ActsAsAuthenticTests
|
6
|
-
class ConfigTest < ActiveSupport::TestCase
|
7
|
-
setup :get_default_configuration
|
8
|
-
teardown :restore_default_configuration
|
9
|
-
|
10
|
-
def test_first_column_to_exist
|
11
|
-
assert_equal :login, User.first_column_to_exist(:login, :crypted_password)
|
12
|
-
assert_equal nil, User.first_column_to_exist(nil, :unknown)
|
13
|
-
assert_equal :login, User.first_column_to_exist(:unknown, :login)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_acts_as_authentic_config
|
17
|
-
default_config = {
|
18
|
-
:session_ids => [nil],
|
19
|
-
:email_field_validates_length_of_options => {},
|
20
|
-
:logged_in_timeout => 600,
|
21
|
-
:validate_password_field => true,
|
22
|
-
:login_field_validates_length_of_options => {},
|
23
|
-
:password_field_validation_options => {},
|
24
|
-
:login_field_type => :login,
|
25
|
-
:email_field_validates_format_of_options => {},
|
26
|
-
:crypted_password_field => :crypted_password,
|
27
|
-
:password_salt_field => :password_salt,
|
28
|
-
:login_field_validates_format_of_options => {},
|
29
|
-
:email_field_validation_options => {},
|
30
|
-
:crypto_provider => Authlogic::CryptoProviders::Sha512,
|
31
|
-
:persistence_token_field => :persistence_token,
|
32
|
-
:email_field_validates_uniqueness_of_options => {},
|
33
|
-
:session_class => "UserSession",
|
34
|
-
:single_access_token_field => :single_access_token,
|
35
|
-
:login_field_validates_uniqueness_of_options => {},
|
36
|
-
:validate_fields => true,
|
37
|
-
:login_field => :login,
|
38
|
-
:perishable_token_valid_for => 600,
|
39
|
-
:password_field_validates_length_of_options => {},
|
40
|
-
:password_field => :password,
|
41
|
-
:validate_login_field => true,
|
42
|
-
:email_field => :email,
|
43
|
-
:perishable_token_field => :perishable_token,
|
44
|
-
:password_field_validates_confirmation_of_options => {},
|
45
|
-
:validate_email_field => true,
|
46
|
-
:validation_options => {},
|
47
|
-
:login_field_validation_options => {},
|
48
|
-
:transition_from_crypto_provider => [],
|
49
|
-
:password_confirmation_field_validates_presence_of_options => {}
|
50
|
-
}
|
51
|
-
assert_equal default_config, User.acts_as_authentic_config
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_session_class
|
55
|
-
EmployeeSession.authenticate_with User
|
56
|
-
User.acts_as_authentic(:session_class => EmployeeSession)
|
57
|
-
assert_equal EmployeeSession, User.acts_as_authentic_config[:session_class]
|
58
|
-
|
59
|
-
ben = users(:ben)
|
60
|
-
assert !EmployeeSession.find
|
61
|
-
ben.password = "benrocks"
|
62
|
-
ben.password_confirmation = "benrocks"
|
63
|
-
assert ben.save
|
64
|
-
assert EmployeeSession.find
|
65
|
-
EmployeeSession.authenticate_with Employee
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_crypto_provider
|
69
|
-
User.acts_as_authentic(:crypto_provider => Authlogic::CryptoProviders::BCrypt)
|
70
|
-
ben = users(:ben)
|
71
|
-
assert !ben.valid_password?("benrocks")
|
72
|
-
ben.password = "benrocks"
|
73
|
-
ben.password_confirmation = "benrocks"
|
74
|
-
assert ben.save
|
75
|
-
assert ben.valid_password?("benrocks")
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_transition_from_crypto_provider
|
79
|
-
ben = users(:ben)
|
80
|
-
convert_password_to(Authlogic::CryptoProviders::BCrypt, ben)
|
81
|
-
convert_password_to(Authlogic::CryptoProviders::Sha1, ben, [Authlogic::CryptoProviders::Sha512, Authlogic::CryptoProviders::BCrypt])
|
82
|
-
convert_password_to(Authlogic::CryptoProviders::Sha512, ben, [Authlogic::CryptoProviders::Sha1, Authlogic::CryptoProviders::BCrypt])
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_act_like_restful_authentication
|
86
|
-
ben = users(:ben)
|
87
|
-
convert_password_to(Authlogic::CryptoProviders::Sha1, ben)
|
88
|
-
User.acts_as_authentic(:act_like_restful_authentication => true)
|
89
|
-
set_session_for(ben)
|
90
|
-
assert UserSession.find
|
91
|
-
|
92
|
-
# Let's try a brute force approach
|
93
|
-
salt = "7e3041ebc2fc05a40c60028e2c4901a81035d3cd"
|
94
|
-
digest = "00742970dc9e6319f8019fd54864d3ea740f04b1"
|
95
|
-
assert ben.class.connection.execute("update users set crypted_password = '#{digest}', password_salt = '#{salt}' where id = '#{ben.id}';")
|
96
|
-
ben.reload
|
97
|
-
assert_equal 1, Authlogic::CryptoProviders::Sha1.stretches
|
98
|
-
assert ben.valid_password?("test")
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_transition_from_restful_authentication
|
102
|
-
User.acts_as_authentic(:transition_from_restful_authentication => true)
|
103
|
-
assert_equal Authlogic::CryptoProviders::Sha512, User.acts_as_authentic_config[:crypto_provider]
|
104
|
-
assert_equal [Authlogic::CryptoProviders::Sha1], User.acts_as_authentic_config[:transition_from_crypto_provider]
|
105
|
-
end
|
106
|
-
|
107
|
-
# Need to finish this when I can figure out the best way to implement "transactions" for ruby constants inbetween tests
|
108
|
-
def test_password_field_validation_options
|
109
|
-
#User.acts_as_authentic(:password_field_validates_length_of_options => {:if => Proc.new { |user| false }})
|
110
|
-
#user = User.new
|
111
|
-
#assert !user.save!
|
112
|
-
#assert !user.errors.on(:password)
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_disable_perishable_token_maintenance
|
116
|
-
ben = users(:ben)
|
117
|
-
assert !ben.disable_perishable_token_maintenance?
|
118
|
-
User.acts_as_authentic(:disable_perishable_token_maintenance => true)
|
119
|
-
assert ben.disable_perishable_token_maintenance?
|
120
|
-
old_perishable_token = ben.perishable_token
|
121
|
-
assert ben.valid?
|
122
|
-
assert_equal old_perishable_token, ben.perishable_token
|
123
|
-
end
|
124
|
-
|
125
|
-
private
|
126
|
-
def get_default_configuration
|
127
|
-
@default_configuration = User.acts_as_authentic_config
|
128
|
-
end
|
129
|
-
|
130
|
-
def restore_default_configuration
|
131
|
-
User.acts_as_authentic @default_configuration
|
132
|
-
end
|
133
|
-
|
134
|
-
def convert_password_to(crypto_provider, records, from_crypto_providers = Authlogic::CryptoProviders::Sha512)
|
135
|
-
records = [records] unless records.is_a?(Array)
|
136
|
-
User.acts_as_authentic(:crypto_provider => crypto_provider, :transition_from_crypto_provider => from_crypto_providers)
|
137
|
-
records.each do |record|
|
138
|
-
old_hash = record.crypted_password
|
139
|
-
old_persistence_token = record.persistence_token
|
140
|
-
assert record.valid_password?(password_for(record))
|
141
|
-
assert_not_equal old_hash.to_s, record.crypted_password.to_s
|
142
|
-
assert_not_equal old_persistence_token.to_s, record.persistence_token.to_s # we need to make sure the persistence token gets reset, what if it is nil and has never been used before?
|
143
|
-
|
144
|
-
old_hash = record.crypted_password
|
145
|
-
old_persistence_token = record.persistence_token
|
146
|
-
assert record.valid_password?(password_for(record))
|
147
|
-
assert_equal old_hash.to_s, record.crypted_password.to_s
|
148
|
-
assert_equal old_persistence_token.to_s, record.persistence_token.to_s
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/credentials_test.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../test_helper.rb'
|
2
|
-
|
3
|
-
module ORMAdaptersTests
|
4
|
-
module ActiveRecordAdapterTests
|
5
|
-
module ActsAsAuthenticTests
|
6
|
-
class CredentialsTest < ActiveSupport::TestCase
|
7
|
-
def test_user_validations
|
8
|
-
user = User.new
|
9
|
-
assert !user.valid?
|
10
|
-
assert user.errors.on(:login)
|
11
|
-
assert user.errors.on(:password)
|
12
|
-
assert user.errors.on(:email)
|
13
|
-
|
14
|
-
user.login = "a"
|
15
|
-
assert !user.valid?
|
16
|
-
assert user.errors.on(:login)
|
17
|
-
assert user.errors.on(:password)
|
18
|
-
assert user.errors.on(:email)
|
19
|
-
|
20
|
-
user.login = "%ben*"
|
21
|
-
assert !user.valid?
|
22
|
-
assert user.errors.on(:login)
|
23
|
-
assert user.errors.on(:password)
|
24
|
-
assert user.errors.on(:email)
|
25
|
-
|
26
|
-
user.login = "bjohnson"
|
27
|
-
assert !user.valid?
|
28
|
-
assert user.errors.on(:login)
|
29
|
-
assert user.errors.on(:password)
|
30
|
-
assert user.errors.on(:email)
|
31
|
-
|
32
|
-
user.login = "my login"
|
33
|
-
assert !user.valid?
|
34
|
-
assert !user.errors.on(:login)
|
35
|
-
assert user.errors.on(:password)
|
36
|
-
assert user.errors.on(:email)
|
37
|
-
|
38
|
-
user.password = "my pass"
|
39
|
-
assert !user.valid?
|
40
|
-
assert !user.errors.on(:password)
|
41
|
-
assert user.errors.on(:password_confirmation)
|
42
|
-
|
43
|
-
user.password_confirmation = "my pizass"
|
44
|
-
assert !user.valid?
|
45
|
-
assert user.errors.on(:password)
|
46
|
-
assert user.errors.on(:email)
|
47
|
-
|
48
|
-
user.password_confirmation = "my pass"
|
49
|
-
assert !user.valid?
|
50
|
-
assert user.errors.on(:email)
|
51
|
-
|
52
|
-
user.email = "some email"
|
53
|
-
assert !user.valid?
|
54
|
-
assert user.errors.on(:email)
|
55
|
-
|
56
|
-
user.email = "a@a.com"
|
57
|
-
assert user.valid?
|
58
|
-
end
|
59
|
-
|
60
|
-
# Make sure the default :within option is ignored, since AR will raise an error if :within and :minimum are passed.
|
61
|
-
def test_multiple_length_options
|
62
|
-
User.acts_as_authentic(:login_field_validates_length_of_options => {:minimum => 6})
|
63
|
-
user = User.new
|
64
|
-
assert_nothing_raised { user.valid? }
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_employee_validations
|
68
|
-
employee = Employee.new
|
69
|
-
employee.password = "pass"
|
70
|
-
employee.password_confirmation = "pass"
|
71
|
-
|
72
|
-
assert !employee.valid?
|
73
|
-
assert employee.errors.on(:email)
|
74
|
-
|
75
|
-
employee.email = "fdsf"
|
76
|
-
assert !employee.valid?
|
77
|
-
assert employee.errors.on(:email)
|
78
|
-
|
79
|
-
employee.email = "fake@email.fake"
|
80
|
-
assert !employee.valid?
|
81
|
-
assert employee.errors.on(:email)
|
82
|
-
|
83
|
-
employee.email = "notfake@email.com"
|
84
|
-
assert employee.valid?
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_friendly_unique_token
|
88
|
-
assert_equal 20, User.friendly_unique_token.length
|
89
|
-
assert_equal 20, Employee.friendly_unique_token.length # make sure encryptions use hashes also
|
90
|
-
|
91
|
-
unique_tokens = []
|
92
|
-
1000.times { unique_tokens << User.friendly_unique_token }
|
93
|
-
unique_tokens.uniq!
|
94
|
-
|
95
|
-
assert_equal 1000, unique_tokens.size
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_password
|
99
|
-
user = User.new
|
100
|
-
user.password = "sillywilly"
|
101
|
-
assert user.crypted_password
|
102
|
-
assert user.password_salt
|
103
|
-
assert user.persistence_token
|
104
|
-
assert_equal "sillywilly", user.password
|
105
|
-
|
106
|
-
employee = Employee.new
|
107
|
-
employee.password = "awesome"
|
108
|
-
assert employee.crypted_password
|
109
|
-
assert employee.persistence_token
|
110
|
-
assert_equal "awesome", employee.password
|
111
|
-
end
|
112
|
-
|
113
|
-
def test_valid_password
|
114
|
-
ben = users(:ben)
|
115
|
-
assert ben.valid_password?("benrocks")
|
116
|
-
assert !ben.valid_password?(ben.crypted_password)
|
117
|
-
|
118
|
-
drew = employees(:drew)
|
119
|
-
assert drew.valid_password?("drewrocks")
|
120
|
-
assert !drew.valid_password?(drew.crypted_password)
|
121
|
-
end
|
122
|
-
|
123
|
-
def test_reset_password
|
124
|
-
ben = users(:ben)
|
125
|
-
UserSession.create(ben)
|
126
|
-
assert UserSession.find
|
127
|
-
|
128
|
-
old_password = ben.crypted_password
|
129
|
-
old_salt = ben.password_salt
|
130
|
-
old_persistence_token = ben.persistence_token
|
131
|
-
ben.reset_password
|
132
|
-
assert_not_equal old_password, ben.crypted_password
|
133
|
-
assert_not_equal old_salt, ben.password_salt
|
134
|
-
assert_not_equal old_persistence_token, ben.persistence_token
|
135
|
-
assert UserSession.find
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_reset_password!
|
139
|
-
UserSession.create(users(:ben))
|
140
|
-
session = UserSession.find
|
141
|
-
assert session
|
142
|
-
ben = session.record
|
143
|
-
|
144
|
-
old_password = ben.crypted_password
|
145
|
-
old_salt = ben.password_salt
|
146
|
-
old_persistence_token = ben.persistence_token
|
147
|
-
ben.reset_password!
|
148
|
-
ben.reload
|
149
|
-
assert_not_equal old_password, ben.crypted_password
|
150
|
-
assert_not_equal old_salt, ben.password_salt
|
151
|
-
assert_not_equal old_persistence_token, ben.persistence_token
|
152
|
-
assert !UserSession.find
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/logged_in_test.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../test_helper.rb'
|
2
|
-
|
3
|
-
module ORMAdaptersTests
|
4
|
-
module ActiveRecordAdapterTests
|
5
|
-
module ActsAsAuthenticTests
|
6
|
-
class LoggedInTest < ActiveSupport::TestCase
|
7
|
-
def test_named_scopes
|
8
|
-
assert_equal 0, User.logged_in.count
|
9
|
-
assert_equal User.count, User.logged_out.count
|
10
|
-
http_basic_auth_for(users(:ben)) { UserSession.find }
|
11
|
-
assert_equal 1, User.logged_in.count
|
12
|
-
assert_equal User.count - 1, User.logged_out.count
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_logged_in
|
16
|
-
ben = users(:ben)
|
17
|
-
assert !ben.logged_in?
|
18
|
-
assert ben.update_attribute(:last_request_at, Time.now)
|
19
|
-
assert ben.logged_in?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../test_helper.rb'
|
2
|
-
|
3
|
-
module ORMAdaptersTests
|
4
|
-
module ActiveRecordAdapterTests
|
5
|
-
module ActsAsAuthenticTests
|
6
|
-
class PerishabilityTest < ActiveSupport::TestCase
|
7
|
-
def test_before_validation
|
8
|
-
ben = users(:ben)
|
9
|
-
old_perishable_token = ben.perishable_token
|
10
|
-
assert ben.valid?
|
11
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
12
|
-
ben.reload
|
13
|
-
assert_equal old_perishable_token, ben.perishable_token
|
14
|
-
assert ben.save
|
15
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_find_using_perishable_token
|
19
|
-
ben = users(:ben)
|
20
|
-
assert_nil User.find_using_perishable_token("")
|
21
|
-
assert_equal ben, User.find_using_perishable_token(ben.perishable_token)
|
22
|
-
assert ben.class.connection.execute("update users set updated_at = '#{10.minutes.ago.to_s(:db)}' where id = '#{ben.id}';")
|
23
|
-
assert_nil User.find_using_perishable_token(ben.perishable_token)
|
24
|
-
assert_equal ben, User.find_using_perishable_token(ben.perishable_token, 20.minutes)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_reset_perishable_token
|
28
|
-
ben = users(:ben)
|
29
|
-
old_perishable_token = ben.perishable_token
|
30
|
-
ben.reset_perishable_token
|
31
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
32
|
-
ben.reload
|
33
|
-
assert_equal old_perishable_token, ben.perishable_token
|
34
|
-
ben.reset_perishable_token!
|
35
|
-
ben.reload
|
36
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/persistence_test.rb
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../test_helper.rb'
|
2
|
-
|
3
|
-
module ORMAdaptersTests
|
4
|
-
module ActiveRecordAdapterTests
|
5
|
-
module ActsAsAuthenticTests
|
6
|
-
class PersistenceTest < ActiveSupport::TestCase
|
7
|
-
def test_unique_token
|
8
|
-
assert_equal 128, User.unique_token.length
|
9
|
-
assert_equal 128, Employee.unique_token.length # make sure encryptions use hashes also
|
10
|
-
|
11
|
-
unique_tokens = []
|
12
|
-
1000.times { unique_tokens << User.unique_token }
|
13
|
-
unique_tokens.uniq!
|
14
|
-
|
15
|
-
assert_equal 1000, unique_tokens.size
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_forget_all
|
19
|
-
http_basic_auth_for(users(:ben)) { UserSession.find }
|
20
|
-
http_basic_auth_for(users(:zack)) { UserSession.find(:ziggity_zack) }
|
21
|
-
assert UserSession.find
|
22
|
-
assert UserSession.find(:ziggity_zack)
|
23
|
-
User.forget_all!
|
24
|
-
assert !UserSession.find
|
25
|
-
assert !UserSession.find(:ziggity_zack)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_forget
|
29
|
-
ben = users(:ben)
|
30
|
-
zack = users(:zack)
|
31
|
-
http_basic_auth_for(ben) { UserSession.find }
|
32
|
-
http_basic_auth_for(zack) { UserSession.find(:ziggity_zack) }
|
33
|
-
|
34
|
-
assert ben.reload.logged_in?
|
35
|
-
assert zack.reload.logged_in?
|
36
|
-
|
37
|
-
ben.forget!
|
38
|
-
|
39
|
-
assert !UserSession.find
|
40
|
-
assert UserSession.find(:ziggity_zack)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_password
|
44
|
-
ben = users(:ben)
|
45
|
-
old_persistence_token = ben.persistence_token
|
46
|
-
ben.password = ""
|
47
|
-
assert_equal old_persistence_token, ben.persistence_token
|
48
|
-
ben.password = "newpass"
|
49
|
-
assert_not_equal old_persistence_token, ben.persistence_token
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|