authlogic 3.4.6 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +33 -0
- data/.rubocop_todo.yml +427 -0
- data/.travis.yml +24 -3
- data/CHANGELOG.md +9 -2
- data/CONTRIBUTING.md +40 -1
- data/Gemfile +1 -1
- data/README.md +295 -0
- data/Rakefile +10 -2
- data/authlogic.gemspec +6 -5
- data/lib/authlogic.rb +2 -2
- data/lib/authlogic/acts_as_authentic/base.rb +2 -2
- data/lib/authlogic/acts_as_authentic/email.rb +59 -14
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +4 -3
- data/lib/authlogic/acts_as_authentic/login.rb +62 -12
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
- data/lib/authlogic/acts_as_authentic/password.rb +107 -53
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -9
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +2 -0
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +48 -35
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +19 -15
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +2 -2
- data/lib/authlogic/authenticates_many/association.rb +6 -5
- data/lib/authlogic/authenticates_many/base.rb +22 -12
- data/lib/authlogic/config.rb +2 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -1
- data/lib/authlogic/controller_adapters/rack_adapter.rb +3 -4
- data/lib/authlogic/controller_adapters/rails_adapter.rb +26 -14
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +1 -1
- data/lib/authlogic/crypto_providers/aes256.rb +16 -12
- data/lib/authlogic/crypto_providers/bcrypt.rb +10 -4
- data/lib/authlogic/crypto_providers/md5.rb +7 -7
- data/lib/authlogic/crypto_providers/scrypt.rb +10 -2
- data/lib/authlogic/crypto_providers/sha1.rb +3 -3
- data/lib/authlogic/crypto_providers/sha256.rb +3 -3
- data/lib/authlogic/crypto_providers/sha512.rb +4 -4
- data/lib/authlogic/crypto_providers/wordpress.rb +13 -13
- data/lib/authlogic/i18n.rb +22 -16
- data/lib/authlogic/i18n/translator.rb +1 -1
- data/lib/authlogic/random.rb +13 -12
- data/lib/authlogic/regex.rb +3 -3
- data/lib/authlogic/session/activation.rb +7 -6
- data/lib/authlogic/session/active_record_trickery.rb +1 -2
- data/lib/authlogic/session/base.rb +7 -6
- data/lib/authlogic/session/brute_force_protection.rb +58 -34
- data/lib/authlogic/session/callbacks.rb +16 -12
- data/lib/authlogic/session/cookies.rb +29 -14
- data/lib/authlogic/session/existence.rb +10 -10
- data/lib/authlogic/session/foundation.rb +11 -7
- data/lib/authlogic/session/http_auth.rb +6 -5
- data/lib/authlogic/session/id.rb +5 -4
- data/lib/authlogic/session/klass.rb +2 -1
- data/lib/authlogic/session/magic_columns.rb +21 -14
- data/lib/authlogic/session/magic_states.rb +25 -14
- data/lib/authlogic/session/params.rb +41 -26
- data/lib/authlogic/session/password.rb +62 -40
- data/lib/authlogic/session/perishable_token.rb +3 -2
- data/lib/authlogic/session/persistence.rb +3 -3
- data/lib/authlogic/session/priority_record.rb +5 -4
- data/lib/authlogic/session/scopes.rb +20 -9
- data/lib/authlogic/session/session.rb +9 -4
- data/lib/authlogic/session/timeout.rb +40 -23
- data/lib/authlogic/session/unauthorized_record.rb +6 -5
- data/lib/authlogic/session/validation.rb +18 -9
- data/lib/authlogic/test_case.rb +2 -2
- data/lib/authlogic/test_case/mock_controller.rb +9 -9
- data/lib/authlogic/test_case/mock_cookie_jar.rb +2 -2
- data/lib/authlogic/test_case/mock_logger.rb +1 -1
- data/lib/authlogic/test_case/mock_request.rb +2 -1
- data/lib/authlogic/test_case/rails_request_adapter.rb +5 -5
- data/test/acts_as_authentic_test/email_test.rb +29 -17
- data/test/acts_as_authentic_test/logged_in_status_test.rb +9 -3
- data/test/acts_as_authentic_test/login_test.rb +47 -13
- data/test/acts_as_authentic_test/magic_columns_test.rb +4 -4
- data/test/acts_as_authentic_test/password_test.rb +31 -21
- data/test/acts_as_authentic_test/perishable_token_test.rb +15 -15
- data/test/acts_as_authentic_test/session_maintenance_test.rb +20 -13
- data/test/acts_as_authentic_test/single_access_test.rb +8 -8
- data/test/authenticates_many_test.rb +4 -4
- data/test/crypto_provider_test/aes256_test.rb +2 -2
- data/test/crypto_provider_test/scrypt_test.rb +1 -1
- data/test/crypto_provider_test/sha1_test.rb +3 -3
- data/test/crypto_provider_test/sha256_test.rb +1 -1
- data/test/crypto_provider_test/sha512_test.rb +2 -2
- data/test/gemfiles/Gemfile.rails-3.2.x +2 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
- data/test/i18n_test.rb +5 -5
- data/test/libs/affiliate.rb +2 -2
- data/test/libs/company.rb +1 -1
- data/test/libs/employee.rb +2 -2
- data/test/libs/employee_session.rb +1 -1
- data/test/libs/ldaper.rb +1 -1
- data/test/libs/project.rb +1 -1
- data/test/random_test.rb +5 -4
- data/test/session_test/activation_test.rb +5 -5
- data/test/session_test/active_record_trickery_test.rb +7 -5
- data/test/session_test/cookies_test.rb +8 -6
- data/test/session_test/existence_test.rb +19 -13
- data/test/session_test/http_auth_test.rb +0 -3
- data/test/session_test/id_test.rb +2 -2
- data/test/session_test/klass_test.rb +1 -1
- data/test/session_test/magic_columns_test.rb +0 -3
- data/test/session_test/magic_states_test.rb +11 -11
- data/test/session_test/params_test.rb +10 -10
- data/test/session_test/password_test.rb +4 -5
- data/test/session_test/perishability_test.rb +3 -3
- data/test/session_test/scopes_test.rb +8 -8
- data/test/session_test/session_test.rb +5 -4
- data/test/session_test/timeout_test.rb +8 -8
- data/test/session_test/unauthorized_record_test.rb +2 -2
- data/test/session_test/validation_test.rb +3 -3
- data/test/test_helper.rb +9 -5
- metadata +54 -24
- data/README.rdoc +0 -232
@@ -18,7 +18,7 @@ module Authlogic
|
|
18
18
|
validate :validate_by_unauthorized_record, :if => :authenticating_with_unauthorized_record?
|
19
19
|
end
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# Returning meaningful credentials
|
23
23
|
def credentials
|
24
24
|
if authenticating_with_unauthorized_record?
|
@@ -29,22 +29,23 @@ module Authlogic
|
|
29
29
|
super
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Setting the unauthorized record if it exists in the credentials passed.
|
34
34
|
def credentials=(value)
|
35
35
|
super
|
36
36
|
values = value.is_a?(Array) ? value : [value]
|
37
37
|
self.unauthorized_record = values.first if values.first.class < ::ActiveRecord::Base
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
private
|
41
|
+
|
41
42
|
def authenticating_with_unauthorized_record?
|
42
43
|
!unauthorized_record.nil?
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def validate_by_unauthorized_record
|
46
47
|
self.attempted_record = unauthorized_record
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
50
|
-
end
|
51
|
+
end
|
@@ -21,19 +21,19 @@ module Authlogic
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# You should use this as a place holder for any records that you find during validation. The main reason for this is to
|
26
26
|
# allow other modules to use it if needed. Take the failed_login_count feature, it needs this in order to increase
|
27
27
|
# the failed login count.
|
28
28
|
def attempted_record
|
29
29
|
@attempted_record
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
# See attempted_record
|
33
33
|
def attempted_record=(value)
|
34
34
|
@attempted_record = value
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# The errors in Authlogic work JUST LIKE ActiveRecord. In fact, it uses the exact same ActiveRecord errors class.
|
38
38
|
# Use it the same way:
|
39
39
|
#
|
@@ -51,31 +51,40 @@ module Authlogic
|
|
51
51
|
def errors
|
52
52
|
@errors ||= Errors.new(self)
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# Determines if the information you provided for authentication is valid or not. If there is
|
56
56
|
# a problem with the information provided errors will be added to the errors object and this
|
57
57
|
# method will return false.
|
58
58
|
def valid?
|
59
59
|
errors.clear
|
60
60
|
self.attempted_record = nil
|
61
|
-
|
61
|
+
|
62
62
|
before_validation
|
63
63
|
new_session? ? before_validation_on_create : before_validation_on_update
|
64
64
|
validate
|
65
65
|
ensure_authentication_attempted
|
66
|
-
|
66
|
+
|
67
67
|
if errors.size == 0
|
68
68
|
new_session? ? after_validation_on_create : after_validation_on_update
|
69
69
|
after_validation
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
save_record(attempted_record)
|
73
73
|
errors.size == 0
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
private
|
77
|
+
|
77
78
|
def ensure_authentication_attempted
|
78
|
-
|
79
|
+
if errors.empty? && attempted_record.nil?
|
80
|
+
errors.add(
|
81
|
+
:base,
|
82
|
+
I18n.t(
|
83
|
+
'error_messages.no_authentication_details',
|
84
|
+
:default => "You did not provide any details for authentication."
|
85
|
+
)
|
86
|
+
)
|
87
|
+
end
|
79
88
|
end
|
80
89
|
end
|
81
90
|
end
|
data/lib/authlogic/test_case.rb
CHANGED
@@ -31,7 +31,7 @@ module Authlogic
|
|
31
31
|
# Now that everything is ready to go, let's move onto actually testing. Here is the basic idea behind testing:
|
32
32
|
#
|
33
33
|
# Authlogic requires a "connection" to your controller to activate it. In the same manner that ActiveRecord requires a connection to
|
34
|
-
# your database. It can't do anything until it gets
|
34
|
+
# your database. It can't do anything until it gets connected. That being said, Authlogic will raise an
|
35
35
|
# Authlogic::Session::Activation::NotActivatedError any time you try to instantiate an object without a "connection".
|
36
36
|
# So before you do anything with Authlogic, you need to activate / connect Authlogic. Let's walk through how to do this in tests:
|
37
37
|
#
|
@@ -100,7 +100,7 @@ module Authlogic
|
|
100
100
|
#
|
101
101
|
# setup :activate_authlogic
|
102
102
|
def activate_authlogic
|
103
|
-
if @request &&
|
103
|
+
if @request && !@request.respond_to?(:params)
|
104
104
|
class <<@request
|
105
105
|
alias_method :params, :parameters
|
106
106
|
end
|
@@ -5,14 +5,14 @@ module Authlogic
|
|
5
5
|
class MockController < ControllerAdapters::AbstractAdapter
|
6
6
|
attr_accessor :http_user, :http_password, :realm
|
7
7
|
attr_writer :request_content_type
|
8
|
-
|
8
|
+
|
9
9
|
def initialize
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def authenticate_with_http_basic(&block)
|
13
13
|
yield http_user, http_password
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
def authenticate_or_request_with_http_basic(realm = 'DefaultRealm', &block)
|
17
17
|
self.realm = realm
|
18
18
|
@http_auth_requested = true
|
@@ -22,27 +22,27 @@ module Authlogic
|
|
22
22
|
def cookies
|
23
23
|
@cookies ||= MockCookieJar.new
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
def cookie_domain
|
27
27
|
nil
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def logger
|
31
31
|
@logger ||= MockLogger.new
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
def params
|
35
35
|
@params ||= {}
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def request
|
39
39
|
@request ||= MockRequest.new(controller)
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def request_content_type
|
43
43
|
@request_content_type ||= "text/html"
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def session
|
47
47
|
@session ||= {}
|
48
48
|
end
|
@@ -5,7 +5,7 @@ module Authlogic
|
|
5
5
|
class RailsRequestAdapter < ControllerAdapters::AbstractAdapter
|
6
6
|
def authenticate_with_http_basic(&block)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
def cookies
|
10
10
|
new_cookies = MockCookieJar.new
|
11
11
|
super.each do |key, value|
|
@@ -13,18 +13,18 @@ module Authlogic
|
|
13
13
|
end
|
14
14
|
new_cookies
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def cookie_domain
|
18
18
|
nil
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def request
|
22
22
|
@request ||= MockRequest.new(controller)
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def request_content_type
|
26
26
|
request.format.to_s
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -3,7 +3,6 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
module ActsAsAuthenticTest
|
5
5
|
class EmailTest < ActiveSupport::TestCase
|
6
|
-
|
7
6
|
GOOD_ASCII_EMAILS = [
|
8
7
|
"a@a.com",
|
9
8
|
"damien+test1...etc..@mydomain.com",
|
@@ -83,17 +82,25 @@ module ActsAsAuthenticTest
|
|
83
82
|
end
|
84
83
|
|
85
84
|
def test_validates_length_of_email_field_options_config
|
86
|
-
assert_equal({:maximum => 100}, User.validates_length_of_email_field_options)
|
87
|
-
assert_equal({:maximum => 100}, Employee.validates_length_of_email_field_options)
|
85
|
+
assert_equal({ :maximum => 100 }, User.validates_length_of_email_field_options)
|
86
|
+
assert_equal({ :maximum => 100 }, Employee.validates_length_of_email_field_options)
|
88
87
|
|
89
|
-
User.validates_length_of_email_field_options = {:yes => "no"}
|
90
|
-
assert_equal({:yes => "no"}, User.validates_length_of_email_field_options)
|
91
|
-
User.validates_length_of_email_field_options({:within => 6..100})
|
92
|
-
assert_equal({:within => 6..100}, User.validates_length_of_email_field_options)
|
88
|
+
User.validates_length_of_email_field_options = { :yes => "no" }
|
89
|
+
assert_equal({ :yes => "no" }, User.validates_length_of_email_field_options)
|
90
|
+
User.validates_length_of_email_field_options({ :within => 6..100 })
|
91
|
+
assert_equal({ :within => 6..100 }, User.validates_length_of_email_field_options)
|
93
92
|
end
|
94
93
|
|
95
94
|
def test_validates_format_of_email_field_options_config
|
96
|
-
default = {
|
95
|
+
default = {
|
96
|
+
:with => Authlogic::Regex.email,
|
97
|
+
:message => Proc.new do
|
98
|
+
I18n.t(
|
99
|
+
'error_messages.email_invalid',
|
100
|
+
:default => "should look like an email address."
|
101
|
+
)
|
102
|
+
end
|
103
|
+
}
|
97
104
|
dmessage = default.delete(:message).call
|
98
105
|
|
99
106
|
options = User.validates_format_of_email_field_options
|
@@ -108,13 +115,20 @@ module ActsAsAuthenticTest
|
|
108
115
|
assert_equal dmessage, message.call
|
109
116
|
assert_equal default, options
|
110
117
|
|
111
|
-
|
112
|
-
|
113
|
-
assert_equal({:yes => "no"}, User.validates_format_of_email_field_options)
|
118
|
+
User.validates_format_of_email_field_options = { :yes => "no" }
|
119
|
+
assert_equal({ :yes => "no" }, User.validates_format_of_email_field_options)
|
114
120
|
User.validates_format_of_email_field_options default
|
115
121
|
assert_equal default, User.validates_format_of_email_field_options
|
116
122
|
|
117
|
-
with_email_nonascii = {
|
123
|
+
with_email_nonascii = {
|
124
|
+
:with => Authlogic::Regex.email_nonascii,
|
125
|
+
:message => Proc.new do
|
126
|
+
I18n.t(
|
127
|
+
'error_messages.email_invalid_international',
|
128
|
+
:default => "should look like an international email address."
|
129
|
+
)
|
130
|
+
end
|
131
|
+
}
|
118
132
|
User.validates_format_of_email_field_options = with_email_nonascii
|
119
133
|
assert_equal(with_email_nonascii, User.validates_format_of_email_field_options)
|
120
134
|
User.validates_format_of_email_field_options with_email_nonascii
|
@@ -141,11 +155,11 @@ module ActsAsAuthenticTest
|
|
141
155
|
end
|
142
156
|
|
143
157
|
def test_validates_uniqueness_of_email_field_options_config
|
144
|
-
default = {:case_sensitive => false, :scope => Employee.validations_scope, :if => "#{Employee.email_field}_changed?".to_sym}
|
158
|
+
default = { :case_sensitive => false, :scope => Employee.validations_scope, :if => "#{Employee.email_field}_changed?".to_sym }
|
145
159
|
assert_equal default, Employee.validates_uniqueness_of_email_field_options
|
146
160
|
|
147
|
-
Employee.validates_uniqueness_of_email_field_options = {:yes => "no"}
|
148
|
-
assert_equal({:yes => "no"}, Employee.validates_uniqueness_of_email_field_options)
|
161
|
+
Employee.validates_uniqueness_of_email_field_options = { :yes => "no" }
|
162
|
+
assert_equal({ :yes => "no" }, Employee.validates_uniqueness_of_email_field_options)
|
149
163
|
Employee.validates_uniqueness_of_email_field_options default
|
150
164
|
assert_equal default, Employee.validates_uniqueness_of_email_field_options
|
151
165
|
end
|
@@ -193,7 +207,6 @@ module ActsAsAuthenticTest
|
|
193
207
|
end
|
194
208
|
|
195
209
|
def test_validates_format_of_nonascii_email_field
|
196
|
-
|
197
210
|
(GOOD_ASCII_EMAILS + GOOD_ISO88591_EMAILS + GOOD_UTF8_EMAILS).each do |e|
|
198
211
|
assert e =~ Authlogic::Regex.email_nonascii, "Good email should validate: #{e}"
|
199
212
|
end
|
@@ -201,7 +214,6 @@ module ActsAsAuthenticTest
|
|
201
214
|
(BAD_ASCII_EMAILS + BAD_ISO88591_EMAILS + BAD_UTF8_EMAILS).each do |e|
|
202
215
|
assert e !~ Authlogic::Regex.email_nonascii, "Bad email should not validate: #{e}"
|
203
216
|
end
|
204
|
-
|
205
217
|
end
|
206
218
|
|
207
219
|
def test_validates_uniqueness_of_email_field
|
@@ -19,9 +19,12 @@ module ActsAsAuthenticTest
|
|
19
19
|
# slightly different. This is an attempt to make sure the scope is lambda wrapped
|
20
20
|
# so that it is re-evaluated every time its called. My biggest concern is that the
|
21
21
|
# test happens so fast that the test fails... I just don't know a better way to test it!
|
22
|
-
|
22
|
+
|
23
|
+
# for rails 5 I've changed the where_values to to_sql to compare
|
24
|
+
|
25
|
+
query1 = User.logged_in.to_sql
|
23
26
|
sleep 0.1
|
24
|
-
query2 = User.logged_in.
|
27
|
+
query2 = User.logged_in.to_sql
|
25
28
|
assert query1 != query2, ERROR_MSG % '#logged_in'
|
26
29
|
|
27
30
|
assert_equal 0, User.logged_in.count
|
@@ -37,7 +40,10 @@ module ActsAsAuthenticTest
|
|
37
40
|
# slightly different. This is an attempt to make sure the scope is lambda wrapped
|
38
41
|
# so that it is re-evaluated every time its called. My biggest concern is that the
|
39
42
|
# test happens so fast that the test fails... I just don't know a better way to test it!
|
40
|
-
|
43
|
+
|
44
|
+
# for rails 5 I've changed the where_values to to_sql to compare
|
45
|
+
|
46
|
+
assert User.logged_in.to_sql != User.logged_out.to_sql, ERROR_MSG % '#logged_out'
|
41
47
|
|
42
48
|
assert_equal 3, User.logged_out.count
|
43
49
|
User.first.update_attribute(:last_request_at, Time.now)
|
@@ -23,32 +23,38 @@ module ActsAsAuthenticTest
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_validates_length_of_login_field_options_config
|
26
|
-
assert_equal({:within => 3..100}, User.validates_length_of_login_field_options)
|
27
|
-
assert_equal({:within => 3..100}, Employee.validates_length_of_login_field_options)
|
26
|
+
assert_equal({ :within => 3..100 }, User.validates_length_of_login_field_options)
|
27
|
+
assert_equal({ :within => 3..100 }, Employee.validates_length_of_login_field_options)
|
28
28
|
|
29
|
-
User.validates_length_of_login_field_options = {:yes => "no"}
|
30
|
-
assert_equal({:yes => "no"}, User.validates_length_of_login_field_options)
|
31
|
-
User.validates_length_of_login_field_options({:within => 3..100})
|
32
|
-
assert_equal({:within => 3..100}, User.validates_length_of_login_field_options)
|
29
|
+
User.validates_length_of_login_field_options = { :yes => "no" }
|
30
|
+
assert_equal({ :yes => "no" }, User.validates_length_of_login_field_options)
|
31
|
+
User.validates_length_of_login_field_options({ :within => 3..100 })
|
32
|
+
assert_equal({ :within => 3..100 }, User.validates_length_of_login_field_options)
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_validates_format_of_login_field_options_config
|
36
|
-
default = {
|
36
|
+
default = {
|
37
|
+
:with => /\A[a-zA-Z0-9_][a-zA-Z0-9\.+\-_@ ]+\z/,
|
38
|
+
:message => I18n.t(
|
39
|
+
'error_messages.login_invalid',
|
40
|
+
:default => "should use only letters, numbers, spaces, and .-_@+ please."
|
41
|
+
)
|
42
|
+
}
|
37
43
|
assert_equal default, User.validates_format_of_login_field_options
|
38
44
|
assert_equal default, Employee.validates_format_of_login_field_options
|
39
45
|
|
40
|
-
User.validates_format_of_login_field_options = {:yes => "no"}
|
41
|
-
assert_equal({:yes => "no"}, User.validates_format_of_login_field_options)
|
46
|
+
User.validates_format_of_login_field_options = { :yes => "no" }
|
47
|
+
assert_equal({ :yes => "no" }, User.validates_format_of_login_field_options)
|
42
48
|
User.validates_format_of_login_field_options default
|
43
49
|
assert_equal default, User.validates_format_of_login_field_options
|
44
50
|
end
|
45
51
|
|
46
52
|
def test_validates_uniqueness_of_login_field_options_config
|
47
|
-
default = {:case_sensitive => false, :scope => User.validations_scope, :if => "#{User.login_field}_changed?".to_sym}
|
53
|
+
default = { :case_sensitive => false, :scope => User.validations_scope, :if => "#{User.login_field}_changed?".to_sym }
|
48
54
|
assert_equal default, User.validates_uniqueness_of_login_field_options
|
49
55
|
|
50
|
-
User.validates_uniqueness_of_login_field_options = {:yes => "no"}
|
51
|
-
assert_equal({:yes => "no"}, User.validates_uniqueness_of_login_field_options)
|
56
|
+
User.validates_uniqueness_of_login_field_options = { :yes => "no" }
|
57
|
+
assert_equal({ :yes => "no" }, User.validates_uniqueness_of_login_field_options)
|
52
58
|
User.validates_uniqueness_of_login_field_options default
|
53
59
|
assert_equal default, User.validates_uniqueness_of_login_field_options
|
54
60
|
end
|
@@ -77,6 +83,34 @@ module ActsAsAuthenticTest
|
|
77
83
|
u.login = "dakota.dux+1@gmail.com"
|
78
84
|
assert !u.valid?
|
79
85
|
assert u.errors[:login].size == 0
|
86
|
+
|
87
|
+
u.login = "marks .-_@+"
|
88
|
+
assert !u.valid?
|
89
|
+
assert u.errors[:login].size == 0
|
90
|
+
|
91
|
+
u.login = " space"
|
92
|
+
assert !u.valid?
|
93
|
+
assert u.errors[:login].size > 0
|
94
|
+
|
95
|
+
u.login = ".dot"
|
96
|
+
assert !u.valid?
|
97
|
+
assert u.errors[:login].size > 0
|
98
|
+
|
99
|
+
u.login = "-hyphen"
|
100
|
+
assert !u.valid?
|
101
|
+
assert u.errors[:login].size > 0
|
102
|
+
|
103
|
+
u.login = "_underscore"
|
104
|
+
assert !u.valid?
|
105
|
+
assert u.errors[:login].size == 0
|
106
|
+
|
107
|
+
u.login = "@atmark"
|
108
|
+
assert !u.valid?
|
109
|
+
assert u.errors[:login].size > 0
|
110
|
+
|
111
|
+
u.login = "+plus"
|
112
|
+
assert !u.valid?
|
113
|
+
assert u.errors[:login].size > 0
|
80
114
|
end
|
81
115
|
|
82
116
|
def test_validates_uniqueness_of_login_field
|
@@ -106,4 +140,4 @@ module ActsAsAuthenticTest
|
|
106
140
|
assert_equal drew, Employee.find_by_smart_case_login_field("DGAINOR@BINARYLOGIC.COM")
|
107
141
|
end
|
108
142
|
end
|
109
|
-
end
|
143
|
+
end
|