authlogic 2.1.11 → 3.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/Gemfile +9 -1
- data/Gemfile.lock +39 -15
- data/LICENSE +1 -1
- data/README.rdoc +19 -8
- data/Rakefile +19 -0
- data/VERSION.yml +4 -4
- data/authlogic.gemspec +214 -18
- data/lib/authlogic/acts_as_authentic/email.rb +12 -12
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +2 -2
- data/lib/authlogic/acts_as_authentic/login.rb +14 -14
- data/lib/authlogic/acts_as_authentic/password.rb +2 -2
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +15 -15
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +1 -1
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +2 -15
- data/lib/authlogic/authenticates_many/base.rb +3 -4
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +1 -1
- data/lib/authlogic/regex.rb +8 -9
- data/lib/authlogic/session/active_record_trickery.rb +9 -1
- data/lib/authlogic/session/callbacks.rb +1 -1
- data/lib/authlogic/session/cookies.rb +15 -15
- data/lib/authlogic/session/foundation.rb +8 -0
- data/lib/authlogic/session/validation.rb +2 -2
- data/lib/generators/authlogic/USAGE +8 -0
- data/lib/generators/authlogic/session_generator.rb +14 -0
- data/lib/generators/authlogic/templates/session.rb +2 -0
- data/test/acts_as_authentic_test/base_test.rb +1 -1
- data/test/acts_as_authentic_test/email_test.rb +26 -22
- data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
- data/test/acts_as_authentic_test/login_test.rb +21 -21
- data/test/acts_as_authentic_test/magic_columns_test.rb +1 -1
- data/test/acts_as_authentic_test/password_test.rb +1 -1
- data/test/acts_as_authentic_test/perishable_token_test.rb +1 -1
- data/test/acts_as_authentic_test/persistence_token_test.rb +1 -1
- data/test/acts_as_authentic_test/restful_authentication_test.rb +1 -1
- data/test/acts_as_authentic_test/session_maintenance_test.rb +1 -1
- data/test/acts_as_authentic_test/single_access_test.rb +1 -1
- data/test/authenticates_many_test.rb +1 -1
- data/test/crypto_provider_test/aes256_test.rb +1 -1
- data/test/crypto_provider_test/bcrypt_test.rb +1 -1
- data/test/crypto_provider_test/sha1_test.rb +1 -1
- data/test/crypto_provider_test/sha256_test.rb +1 -1
- data/test/crypto_provider_test/sha512_test.rb +1 -1
- data/test/i18n_test.rb +1 -1
- data/test/random_test.rb +1 -1
- data/test/session_test/activation_test.rb +1 -1
- data/test/session_test/active_record_trickery_test.rb +16 -6
- data/test/session_test/brute_force_protection_test.rb +1 -1
- data/test/session_test/callbacks_test.rb +1 -1
- data/test/session_test/cookies_test.rb +43 -21
- data/test/session_test/existence_test.rb +1 -1
- data/test/session_test/http_auth_test.rb +1 -1
- data/test/session_test/id_test.rb +1 -1
- data/test/session_test/klass_test.rb +1 -1
- data/test/session_test/magic_columns_test.rb +1 -1
- data/test/session_test/magic_states_test.rb +1 -1
- data/test/session_test/params_test.rb +1 -1
- data/test/session_test/password_test.rb +1 -1
- data/test/session_test/perishability_test.rb +1 -1
- data/test/session_test/persistence_test.rb +1 -1
- data/test/session_test/scopes_test.rb +1 -1
- data/test/session_test/session_test.rb +1 -1
- data/test/session_test/timeout_test.rb +1 -1
- data/test/session_test/unauthorized_record_test.rb +1 -1
- data/test/session_test/validation_test.rb +1 -1
- data/test/test_helper.rb +3 -19
- metadata +59 -96
- checksums.yaml +0 -7
- data/.gitignore +0 -10
- data/CHANGELOG.rdoc +0 -345
@@ -53,6 +53,14 @@ module Authlogic
|
|
53
53
|
"#<#{self.class.name}: #{credentials.blank? ? "no credentials provided" : credentials.inspect}>"
|
54
54
|
end
|
55
55
|
|
56
|
+
def persisted?
|
57
|
+
!(new_record? || destroyed?)
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_key
|
61
|
+
new_record? ? nil : [ self.send(self.class.primary_key) ]
|
62
|
+
end
|
63
|
+
|
56
64
|
private
|
57
65
|
def build_key(last_part)
|
58
66
|
last_part
|
@@ -13,8 +13,8 @@ module Authlogic
|
|
13
13
|
# errors.add(:base, "You must be awesome to log in") unless attempted_record.awesome?
|
14
14
|
# end
|
15
15
|
# end
|
16
|
-
class Errors < (defined?(::ActiveModel
|
17
|
-
unless defined?(::ActiveModel
|
16
|
+
class Errors < (defined?(::ActiveModel) ? ::ActiveModel::Errors : ::ActiveRecord::Errors)
|
17
|
+
unless defined?(::ActiveModel)
|
18
18
|
def [](key)
|
19
19
|
value = super
|
20
20
|
value.is_a?(Array) ? value : [value].compact
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Authlogic
|
2
|
+
class SessionGenerator < Rails::Generators::Base
|
3
|
+
source_root File.expand_path('../templates', __FILE__)
|
4
|
+
argument :session_class_name, :type => :string, :default => "Session"
|
5
|
+
|
6
|
+
def self.banner
|
7
|
+
"rails generate authlogic:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate_session
|
11
|
+
template "session.rb", "app/models/#{session_class_name.underscore}.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,98 +1,102 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
module ActsAsAuthenticTest
|
4
4
|
class EmailTest < ActiveSupport::TestCase
|
5
5
|
def test_email_field_config
|
6
6
|
assert_equal :email, User.email_field
|
7
7
|
assert_equal :email, Employee.email_field
|
8
|
-
|
8
|
+
|
9
9
|
User.email_field = :nope
|
10
10
|
assert_equal :nope, User.email_field
|
11
11
|
User.email_field :email
|
12
12
|
assert_equal :email, User.email_field
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def test_validate_email_field_config
|
16
16
|
assert User.validate_email_field
|
17
17
|
assert Employee.validate_email_field
|
18
|
-
|
18
|
+
|
19
19
|
User.validate_email_field = false
|
20
20
|
assert !User.validate_email_field
|
21
21
|
User.validate_email_field true
|
22
22
|
assert User.validate_email_field
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_validates_length_of_email_field_options_config
|
26
|
-
assert_equal({:
|
27
|
-
assert_equal({:
|
28
|
-
|
26
|
+
assert_equal({:maximum => 100}, User.validates_length_of_email_field_options)
|
27
|
+
assert_equal({:maximum => 100}, Employee.validates_length_of_email_field_options)
|
28
|
+
|
29
29
|
User.validates_length_of_email_field_options = {:yes => "no"}
|
30
30
|
assert_equal({:yes => "no"}, User.validates_length_of_email_field_options)
|
31
31
|
User.validates_length_of_email_field_options({:within => 6..100})
|
32
32
|
assert_equal({:within => 6..100}, User.validates_length_of_email_field_options)
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def test_validates_format_of_email_field_options_config
|
36
36
|
default = {:with => Authlogic::Regex.email, :message => I18n.t('error_messages.email_invalid', :default => "should look like an email address.")}
|
37
37
|
assert_equal default, User.validates_format_of_email_field_options
|
38
38
|
assert_equal default, Employee.validates_format_of_email_field_options
|
39
|
-
|
39
|
+
|
40
40
|
User.validates_format_of_email_field_options = {:yes => "no"}
|
41
41
|
assert_equal({:yes => "no"}, User.validates_format_of_email_field_options)
|
42
42
|
User.validates_format_of_email_field_options default
|
43
43
|
assert_equal default, User.validates_format_of_email_field_options
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def test_validates_uniqueness_of_email_field_options_config
|
47
47
|
default = {:case_sensitive => false, :scope => Employee.validations_scope, :if => "#{Employee.email_field}_changed?".to_sym}
|
48
48
|
assert_equal default, Employee.validates_uniqueness_of_email_field_options
|
49
|
-
|
49
|
+
|
50
50
|
Employee.validates_uniqueness_of_email_field_options = {:yes => "no"}
|
51
51
|
assert_equal({:yes => "no"}, Employee.validates_uniqueness_of_email_field_options)
|
52
52
|
Employee.validates_uniqueness_of_email_field_options default
|
53
53
|
assert_equal default, Employee.validates_uniqueness_of_email_field_options
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def test_validates_length_of_email_field
|
57
57
|
u = User.new
|
58
58
|
u.email = "a@a.a"
|
59
59
|
assert !u.valid?
|
60
60
|
assert u.errors[:email].size > 0
|
61
|
-
|
61
|
+
|
62
62
|
u.email = "a@a.com"
|
63
63
|
assert !u.valid?
|
64
64
|
assert u.errors[:email].size == 0
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def test_validates_format_of_email_field
|
68
68
|
u = User.new
|
69
69
|
u.email = "aaaaaaaaaaaaa"
|
70
70
|
u.valid?
|
71
|
-
assert u.errors[:email].size > 0
|
72
|
-
|
71
|
+
assert u.errors[:email].size > 0
|
72
|
+
|
73
73
|
u.email = "a@a.com"
|
74
74
|
u.valid?
|
75
75
|
assert u.errors[:email].size == 0
|
76
|
-
|
76
|
+
|
77
77
|
u.email = "damien+test1...etc..@mydomain.com"
|
78
78
|
u.valid?
|
79
79
|
assert u.errors[:email].size == 0
|
80
|
-
|
80
|
+
|
81
81
|
u.email = "dakota.dux+1@gmail.com"
|
82
82
|
u.valid?
|
83
83
|
assert u.errors[:email].size == 0
|
84
|
+
|
85
|
+
u.email = "dakota.d'ux@gmail.com"
|
86
|
+
u.valid?
|
87
|
+
assert u.errors[:email].size == 0
|
84
88
|
end
|
85
|
-
|
89
|
+
|
86
90
|
def test_validates_uniqueness_of_email_field
|
87
91
|
u = User.new
|
88
92
|
u.email = "bjohnson@binarylogic.com"
|
89
93
|
assert !u.valid?
|
90
94
|
assert u.errors[:email].size > 0
|
91
|
-
|
95
|
+
|
92
96
|
u.email = "BJOHNSON@binarylogic.com"
|
93
97
|
assert !u.valid?
|
94
98
|
assert u.errors[:email].size > 0
|
95
|
-
|
99
|
+
|
96
100
|
u.email = "a@a.com"
|
97
101
|
assert !u.valid?
|
98
102
|
assert u.errors[:email].size == 0
|
@@ -1,105 +1,105 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
module ActsAsAuthenticTest
|
4
4
|
class LoginTest < ActiveSupport::TestCase
|
5
5
|
def test_login_field_config
|
6
6
|
assert_equal :login, User.login_field
|
7
7
|
assert_nil Employee.login_field
|
8
|
-
|
8
|
+
|
9
9
|
User.login_field = :nope
|
10
10
|
assert_equal :nope, User.login_field
|
11
11
|
User.login_field :login
|
12
12
|
assert_equal :login, User.login_field
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def test_validate_login_field_config
|
16
16
|
assert User.validate_login_field
|
17
17
|
assert Employee.validate_login_field
|
18
|
-
|
18
|
+
|
19
19
|
User.validate_login_field = false
|
20
20
|
assert !User.validate_login_field
|
21
21
|
User.validate_login_field true
|
22
22
|
assert User.validate_login_field
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def test_validates_length_of_login_field_options_config
|
26
26
|
assert_equal({:within => 3..100}, User.validates_length_of_login_field_options)
|
27
27
|
assert_equal({:within => 3..100}, Employee.validates_length_of_login_field_options)
|
28
|
-
|
28
|
+
|
29
29
|
User.validates_length_of_login_field_options = {:yes => "no"}
|
30
30
|
assert_equal({:yes => "no"}, User.validates_length_of_login_field_options)
|
31
31
|
User.validates_length_of_login_field_options({:within => 3..100})
|
32
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 = {:with => /\A\w[\w\.+\-_@ ]
|
36
|
+
default = {:with => /\A\w[\w\.+\-_@ ]+$/, :message => I18n.t('error_messages.login_invalid', :default => "should use only letters, numbers, spaces, and .-_@ please.")}
|
37
37
|
assert_equal default, User.validates_format_of_login_field_options
|
38
38
|
assert_equal default, Employee.validates_format_of_login_field_options
|
39
|
-
|
39
|
+
|
40
40
|
User.validates_format_of_login_field_options = {:yes => "no"}
|
41
41
|
assert_equal({:yes => "no"}, User.validates_format_of_login_field_options)
|
42
42
|
User.validates_format_of_login_field_options default
|
43
43
|
assert_equal default, User.validates_format_of_login_field_options
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
def test_validates_uniqueness_of_login_field_options_config
|
47
47
|
default = {:case_sensitive => false, :scope => User.validations_scope, :if => "#{User.login_field}_changed?".to_sym}
|
48
48
|
assert_equal default, User.validates_uniqueness_of_login_field_options
|
49
|
-
|
49
|
+
|
50
50
|
User.validates_uniqueness_of_login_field_options = {:yes => "no"}
|
51
51
|
assert_equal({:yes => "no"}, User.validates_uniqueness_of_login_field_options)
|
52
52
|
User.validates_uniqueness_of_login_field_options default
|
53
53
|
assert_equal default, User.validates_uniqueness_of_login_field_options
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def test_validates_length_of_login_field
|
57
57
|
u = User.new
|
58
58
|
u.login = "a"
|
59
59
|
assert !u.valid?
|
60
60
|
assert u.errors[:login].size > 0
|
61
|
-
|
61
|
+
|
62
62
|
u.login = "aaaaaaaaaa"
|
63
63
|
assert !u.valid?
|
64
64
|
assert u.errors[:login].size == 0
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def test_validates_format_of_login_field
|
68
68
|
u = User.new
|
69
69
|
u.login = "fdsf@^&*"
|
70
70
|
assert !u.valid?
|
71
71
|
assert u.errors[:login].size > 0
|
72
|
-
|
72
|
+
|
73
73
|
u.login = "fdsfdsfdsfdsfs"
|
74
74
|
assert !u.valid?
|
75
75
|
assert u.errors[:login].size == 0
|
76
|
-
|
76
|
+
|
77
77
|
u.login = "dakota.dux+1@gmail.com"
|
78
78
|
assert !u.valid?
|
79
79
|
assert u.errors[:login].size == 0
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def test_validates_uniqueness_of_login_field
|
83
83
|
u = User.new
|
84
84
|
u.login = "bjohnson"
|
85
85
|
assert !u.valid?
|
86
86
|
assert u.errors[:login].size > 0
|
87
|
-
|
87
|
+
|
88
88
|
u.login = "BJOHNSON"
|
89
89
|
assert !u.valid?
|
90
90
|
assert u.errors[:login].size > 0
|
91
|
-
|
91
|
+
|
92
92
|
u.login = "fdsfdsf"
|
93
93
|
assert !u.valid?
|
94
94
|
assert u.errors[:login].size == 0
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
def test_find_by_smart_case_login_field
|
98
98
|
ben = users(:ben)
|
99
99
|
assert_equal ben, User.find_by_smart_case_login_field("bjohnson")
|
100
100
|
assert_equal ben, User.find_by_smart_case_login_field("BJOHNSON")
|
101
101
|
assert_equal ben, User.find_by_smart_case_login_field("Bjohnson")
|
102
|
-
|
102
|
+
|
103
103
|
drew = employees(:drew)
|
104
104
|
assert_equal drew, Employee.find_by_smart_case_login_field("dgainor@binarylogic.com")
|
105
105
|
assert_equal drew, Employee.find_by_smart_case_login_field("Dgainor@binarylogic.com")
|
data/test/i18n_test.rb
CHANGED
data/test/random_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
module SessionTest
|
4
4
|
module ActiveRecordTrickeryTest
|
@@ -7,26 +7,36 @@ module SessionTest
|
|
7
7
|
assert_equal "Some attribute", UserSession.human_attribute_name("some_attribute")
|
8
8
|
assert_equal "Some attribute", UserSession.human_attribute_name(:some_attribute)
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def test_human_name
|
12
12
|
assert_equal "Usersession", UserSession.human_name
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def test_self_and_descendents_from_active_record
|
16
16
|
assert_equal [UserSession], UserSession.self_and_descendents_from_active_record
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def test_self_and_descendants_from_active_record
|
20
20
|
assert_equal [UserSession], UserSession.self_and_descendants_from_active_record
|
21
21
|
end
|
22
|
-
end
|
23
22
|
|
23
|
+
def test_i18n_of_human_name
|
24
|
+
I18n.backend.store_translations 'en', :authlogic => {:models => {:user_session => "MySession" } }
|
25
|
+
assert_equal "MySession", UserSession.human_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_i18n_of_model_name_human
|
29
|
+
I18n.backend.store_translations 'en', :authlogic => {:models => {:user_session => "MySession" } }
|
30
|
+
assert_equal "MySession", UserSession.model_name.human
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
class InstanceMethodsTest < ActiveSupport::TestCase
|
25
35
|
def test_new_record
|
26
36
|
session = UserSession.new
|
27
37
|
assert session.new_record?
|
28
38
|
end
|
29
|
-
|
39
|
+
|
30
40
|
def test_to_model
|
31
41
|
session = UserSession.new
|
32
42
|
assert_equal session, session.to_model
|