Empact-authlogic 2.1.5 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Empact-authlogic.gemspec +190 -187
- data/Gemfile +10 -0
- data/Gemfile.lock +49 -0
- data/LICENSE +1 -1
- data/README.rdoc +14 -10
- data/Rakefile +5 -5
- data/VERSION.yml +3 -3
- data/lib/authlogic/acts_as_authentic/base.rb +14 -12
- data/lib/authlogic/acts_as_authentic/email.rb +12 -12
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +8 -9
- data/lib/authlogic/acts_as_authentic/login.rb +19 -18
- data/lib/authlogic/acts_as_authentic/password.rb +3 -3
- 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/authenticates_many/base.rb +3 -4
- data/lib/authlogic/controller_adapters/rails_adapter.rb +1 -1
- data/lib/authlogic/random.rb +1 -1
- data/lib/authlogic/session/active_record_trickery.rb +8 -0
- data/lib/authlogic/session/callbacks.rb +2 -2
- data/lib/authlogic/session/cookies.rb +54 -2
- data/lib/authlogic/session/foundation.rb +17 -3
- data/lib/authlogic/session/http_auth.rb +43 -2
- data/lib/authlogic/session/scopes.rb +9 -9
- data/lib/authlogic/test_case/mock_controller.rb +12 -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 +29 -21
- data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
- data/test/acts_as_authentic_test/login_test.rb +1 -1
- 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 -8
- data/test/session_test/activation_test.rb +1 -1
- data/test/session_test/active_record_trickery_test.rb +12 -2
- 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 +26 -2
- data/test/session_test/existence_test.rb +1 -1
- data/test/session_test/http_auth_test.rb +31 -3
- 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 +12 -12
- 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 +27 -41
- metadata +50 -55
- data/.gitignore +0 -9
- data/CHANGELOG.rdoc +0 -353
@@ -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,79 +1,83 @@
|
|
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
|
+
u.email = "damien+test1...etc..@mydomain.com"
|
78
|
+
u.valid?
|
79
|
+
assert u.errors[:email].size == 0
|
80
|
+
|
77
81
|
u.email = "dakota.dux+1@gmail.com"
|
78
82
|
u.valid?
|
79
83
|
assert u.errors[:email].size == 0
|
@@ -85,18 +89,22 @@ module ActsAsAuthenticTest
|
|
85
89
|
u.email = "dakota.O'Malley+1@gmail.com"
|
86
90
|
u.valid?
|
87
91
|
assert u.errors[:email].size == 0
|
92
|
+
|
93
|
+
u.email = "dakota.d'ux@gmail.com"
|
94
|
+
u.valid?
|
95
|
+
assert u.errors[:email].size == 0
|
88
96
|
end
|
89
|
-
|
97
|
+
|
90
98
|
def test_validates_uniqueness_of_email_field
|
91
99
|
u = User.new
|
92
100
|
u.email = "bjohnson@binarylogic.com"
|
93
101
|
assert !u.valid?
|
94
102
|
assert u.errors[:email].size > 0
|
95
|
-
|
103
|
+
|
96
104
|
u.email = "BJOHNSON@binarylogic.com"
|
97
105
|
assert !u.valid?
|
98
106
|
assert u.errors[:email].size > 0
|
99
|
-
|
107
|
+
|
100
108
|
u.email = "a@a.com"
|
101
109
|
assert !u.valid?
|
102
110
|
assert u.errors[:email].size == 0
|
data/test/i18n_test.rb
CHANGED
data/test/random_test.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
class RandomTest < ActiveSupport::TestCase
|
4
|
-
def test_random_tokens_have_consisten_length
|
5
|
-
with_any_random do
|
6
|
-
assert_equal 128, Authlogic::Random.hex_token.length
|
7
|
-
assert_equal 20, Authlogic::Random.friendly_token.length
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
4
|
def test_random_tokens_are_indeed_random
|
12
5
|
# this might fail if you are *really* unlucky :)
|
13
6
|
with_any_random do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
module SessionTest
|
4
4
|
module ActiveRecordTrickeryTest
|
@@ -19,6 +19,16 @@ module SessionTest
|
|
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
|
+
|
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
|
22
32
|
end
|
23
33
|
|
24
34
|
class InstanceMethodsTest < ActiveSupport::TestCase
|
@@ -29,7 +39,7 @@ module SessionTest
|
|
29
39
|
|
30
40
|
def test_to_model
|
31
41
|
session = UserSession.new
|
32
|
-
|
42
|
+
assert_equal session, session.to_model
|
33
43
|
end
|
34
44
|
end
|
35
45
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
module SessionTest
|
4
4
|
module CookiesTest
|
@@ -41,6 +41,30 @@ module SessionTest
|
|
41
41
|
session.remember_me = true
|
42
42
|
assert_equal 3.months, session.remember_me_for
|
43
43
|
end
|
44
|
+
|
45
|
+
def test_secure
|
46
|
+
UserSession.secure = true
|
47
|
+
assert_equal true, UserSession.secure
|
48
|
+
session = UserSession.new
|
49
|
+
assert_equal true, session.secure
|
50
|
+
|
51
|
+
UserSession.secure false
|
52
|
+
assert_equal false, UserSession.secure
|
53
|
+
session = UserSession.new
|
54
|
+
assert_equal false, session.secure
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_httponly
|
58
|
+
UserSession.httponly = true
|
59
|
+
assert_equal true, UserSession.httponly
|
60
|
+
session = UserSession.new
|
61
|
+
assert_equal true, session.httponly
|
62
|
+
|
63
|
+
UserSession.httponly false
|
64
|
+
assert_equal false, UserSession.httponly
|
65
|
+
session = UserSession.new
|
66
|
+
assert_equal false, session.httponly
|
67
|
+
end
|
44
68
|
end
|
45
69
|
|
46
70
|
class InstanceMethodsTest < ActiveSupport::TestCase
|
@@ -109,4 +133,4 @@ module SessionTest
|
|
109
133
|
end
|
110
134
|
end
|
111
135
|
end
|
112
|
-
end
|
136
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
module SessionTest
|
4
4
|
class HttpAuthTest < ActiveSupport::TestCase
|
@@ -10,19 +10,47 @@ module SessionTest
|
|
10
10
|
UserSession.allow_http_basic_auth true
|
11
11
|
assert_equal true, UserSession.allow_http_basic_auth
|
12
12
|
end
|
13
|
+
|
14
|
+
def test_request_http_basic_auth
|
15
|
+
UserSession.request_http_basic_auth = true
|
16
|
+
assert_equal true, UserSession.request_http_basic_auth
|
17
|
+
|
18
|
+
UserSession.request_http_basic_auth = false
|
19
|
+
assert_equal false, UserSession.request_http_basic_auth
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_http_basic_auth_realm
|
23
|
+
assert_equal 'Application', UserSession.http_basic_auth_realm
|
24
|
+
|
25
|
+
UserSession.http_basic_auth_realm = 'TestRealm'
|
26
|
+
assert_equal 'TestRealm', UserSession.http_basic_auth_realm
|
27
|
+
end
|
13
28
|
end
|
14
29
|
|
15
30
|
class InstanceMethodsTest < ActiveSupport::TestCase
|
16
31
|
def test_persist_persist_by_http_auth
|
17
32
|
ben = users(:ben)
|
18
|
-
http_basic_auth_for
|
33
|
+
http_basic_auth_for do
|
34
|
+
assert !UserSession.find
|
35
|
+
end
|
36
|
+
http_basic_auth_for(ben) do
|
37
|
+
assert session = UserSession.find
|
38
|
+
assert_equal ben, session.record
|
39
|
+
assert_equal ben.login, session.login
|
40
|
+
assert_equal "benrocks", session.send(:protected_password)
|
41
|
+
assert !controller.http_auth_requested?
|
42
|
+
end
|
43
|
+
UserSession.request_http_basic_auth = true
|
44
|
+
UserSession.http_basic_auth_realm = 'PersistTestRealm'
|
19
45
|
http_basic_auth_for(ben) do
|
20
46
|
assert session = UserSession.find
|
21
47
|
assert_equal ben, session.record
|
22
48
|
assert_equal ben.login, session.login
|
23
49
|
assert_equal "benrocks", session.send(:protected_password)
|
50
|
+
assert_equal 'PersistTestRealm', controller.realm
|
51
|
+
assert controller.http_auth_requested?
|
24
52
|
end
|
25
53
|
end
|
26
54
|
end
|
27
55
|
end
|
28
|
-
end
|
56
|
+
end
|