authlogic 4.4.3 → 5.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/authlogic.rb +4 -28
- data/lib/authlogic/acts_as_authentic/base.rb +3 -18
- data/lib/authlogic/acts_as_authentic/email.rb +3 -170
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +3 -1
- data/lib/authlogic/acts_as_authentic/login.rb +7 -174
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +7 -4
- data/lib/authlogic/acts_as_authentic/password.rb +54 -253
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +8 -5
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -4
- data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +36 -20
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +8 -6
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +10 -8
- data/lib/authlogic/config.rb +9 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +7 -4
- data/lib/authlogic/controller_adapters/rack_adapter.rb +2 -0
- data/lib/authlogic/controller_adapters/rails_adapter.rb +6 -29
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +6 -0
- data/lib/authlogic/cookie_credentials.rb +63 -0
- data/lib/authlogic/crypto_providers.rb +5 -20
- data/lib/authlogic/crypto_providers/bcrypt.rb +3 -3
- data/lib/authlogic/crypto_providers/md5.rb +3 -6
- data/lib/authlogic/crypto_providers/scrypt.rb +2 -0
- data/lib/authlogic/crypto_providers/sha1.rb +4 -6
- data/lib/authlogic/crypto_providers/sha256.rb +2 -0
- data/lib/authlogic/crypto_providers/sha512.rb +6 -5
- data/lib/authlogic/i18n.rb +3 -1
- data/lib/authlogic/i18n/translator.rb +3 -0
- data/lib/authlogic/random.rb +2 -0
- data/lib/authlogic/session/base.rb +2087 -39
- data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
- data/lib/authlogic/test_case.rb +4 -0
- data/lib/authlogic/test_case/mock_controller.rb +2 -0
- data/lib/authlogic/test_case/mock_cookie_jar.rb +7 -35
- data/lib/authlogic/test_case/mock_logger.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +2 -0
- data/lib/authlogic/test_case/rails_request_adapter.rb +2 -0
- data/lib/authlogic/version.rb +2 -1
- metadata +136 -182
- data/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
- data/.github/ISSUE_TEMPLATE/feature_proposal.md +0 -32
- data/.github/triage.md +0 -86
- data/.gitignore +0 -15
- data/.rubocop.yml +0 -133
- data/.rubocop_todo.yml +0 -74
- data/.travis.yml +0 -24
- data/CHANGELOG.md +0 -336
- data/CONTRIBUTING.md +0 -91
- data/Gemfile +0 -6
- data/LICENSE +0 -20
- data/README.md +0 -439
- data/Rakefile +0 -21
- data/UPGRADING.md +0 -22
- data/authlogic.gemspec +0 -40
- data/doc/use_normal_rails_validation.md +0 -82
- data/gemfiles/Gemfile.rails-4.2.x +0 -6
- data/gemfiles/Gemfile.rails-5.1.x +0 -6
- data/gemfiles/Gemfile.rails-5.2.x +0 -6
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -106
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -35
- data/lib/authlogic/authenticates_many/association.rb +0 -50
- data/lib/authlogic/authenticates_many/base.rb +0 -81
- data/lib/authlogic/crypto_providers/aes256.rb +0 -71
- data/lib/authlogic/crypto_providers/wordpress.rb +0 -72
- data/lib/authlogic/regex.rb +0 -79
- data/lib/authlogic/session/activation.rb +0 -73
- data/lib/authlogic/session/active_record_trickery.rb +0 -65
- data/lib/authlogic/session/brute_force_protection.rb +0 -127
- data/lib/authlogic/session/callbacks.rb +0 -153
- data/lib/authlogic/session/cookies.rb +0 -329
- data/lib/authlogic/session/existence.rb +0 -103
- data/lib/authlogic/session/foundation.rb +0 -105
- data/lib/authlogic/session/http_auth.rb +0 -107
- data/lib/authlogic/session/id.rb +0 -53
- data/lib/authlogic/session/klass.rb +0 -73
- data/lib/authlogic/session/magic_columns.rb +0 -119
- data/lib/authlogic/session/magic_states.rb +0 -82
- data/lib/authlogic/session/params.rb +0 -130
- data/lib/authlogic/session/password.rb +0 -318
- data/lib/authlogic/session/perishable_token.rb +0 -24
- data/lib/authlogic/session/persistence.rb +0 -77
- data/lib/authlogic/session/priority_record.rb +0 -38
- data/lib/authlogic/session/scopes.rb +0 -138
- data/lib/authlogic/session/session.rb +0 -77
- data/lib/authlogic/session/timeout.rb +0 -103
- data/lib/authlogic/session/unauthorized_record.rb +0 -56
- data/lib/authlogic/session/validation.rb +0 -93
- data/test/acts_as_authentic_test/base_test.rb +0 -27
- data/test/acts_as_authentic_test/email_test.rb +0 -241
- data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -64
- data/test/acts_as_authentic_test/login_test.rb +0 -153
- data/test/acts_as_authentic_test/magic_columns_test.rb +0 -29
- data/test/acts_as_authentic_test/password_test.rb +0 -263
- data/test/acts_as_authentic_test/perishable_token_test.rb +0 -98
- data/test/acts_as_authentic_test/persistence_token_test.rb +0 -62
- data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -48
- data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -150
- data/test/acts_as_authentic_test/single_access_test.rb +0 -46
- data/test/adapter_test.rb +0 -23
- data/test/authenticates_many_test.rb +0 -33
- data/test/config_test.rb +0 -38
- data/test/crypto_provider_test/aes256_test.rb +0 -16
- data/test/crypto_provider_test/bcrypt_test.rb +0 -16
- data/test/crypto_provider_test/scrypt_test.rb +0 -16
- data/test/crypto_provider_test/sha1_test.rb +0 -25
- data/test/crypto_provider_test/sha256_test.rb +0 -16
- data/test/crypto_provider_test/sha512_test.rb +0 -16
- data/test/crypto_provider_test/wordpress_test.rb +0 -26
- data/test/fixtures/companies.yml +0 -5
- data/test/fixtures/employees.yml +0 -17
- data/test/fixtures/projects.yml +0 -3
- data/test/fixtures/users.yml +0 -41
- data/test/i18n/lol.yml +0 -4
- data/test/i18n_test.rb +0 -35
- data/test/libs/affiliate.rb +0 -9
- data/test/libs/company.rb +0 -8
- data/test/libs/employee.rb +0 -9
- data/test/libs/employee_session.rb +0 -4
- data/test/libs/ldaper.rb +0 -5
- data/test/libs/project.rb +0 -5
- data/test/libs/user.rb +0 -9
- data/test/libs/user_session.rb +0 -27
- data/test/random_test.rb +0 -15
- data/test/session_test/activation_test.rb +0 -45
- data/test/session_test/active_record_trickery_test.rb +0 -78
- data/test/session_test/brute_force_protection_test.rb +0 -110
- data/test/session_test/callbacks_test.rb +0 -42
- data/test/session_test/cookies_test.rb +0 -242
- data/test/session_test/credentials_test.rb +0 -0
- data/test/session_test/existence_test.rb +0 -88
- data/test/session_test/foundation_test.rb +0 -24
- data/test/session_test/http_auth_test.rb +0 -60
- data/test/session_test/id_test.rb +0 -19
- data/test/session_test/klass_test.rb +0 -42
- data/test/session_test/magic_columns_test.rb +0 -62
- data/test/session_test/magic_states_test.rb +0 -60
- data/test/session_test/params_test.rb +0 -61
- data/test/session_test/password_test.rb +0 -107
- data/test/session_test/perishability_test.rb +0 -17
- data/test/session_test/persistence_test.rb +0 -35
- data/test/session_test/scopes_test.rb +0 -68
- data/test/session_test/session_test.rb +0 -80
- data/test/session_test/timeout_test.rb +0 -84
- data/test/session_test/unauthorized_record_test.rb +0 -15
- data/test/session_test/validation_test.rb +0 -25
- data/test/test_helper.rb +0 -272
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
class IdTest < ActiveSupport::TestCase
|
7
|
-
def test_credentials
|
8
|
-
session = UserSession.new
|
9
|
-
session.credentials = [:my_id]
|
10
|
-
assert_equal :my_id, session.id
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_id
|
14
|
-
session = UserSession.new
|
15
|
-
session.id = :my_id
|
16
|
-
assert_equal :my_id, session.id
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
module KlassTest
|
7
|
-
class ConfigTest < ActiveSupport::TestCase
|
8
|
-
def test_authenticate_with
|
9
|
-
UserSession.authenticate_with = Employee
|
10
|
-
assert_equal "Employee", UserSession.klass_name
|
11
|
-
assert_equal Employee, UserSession.klass
|
12
|
-
|
13
|
-
UserSession.authenticate_with User
|
14
|
-
assert_equal "User", UserSession.klass_name
|
15
|
-
assert_equal User, UserSession.klass
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_klass
|
19
|
-
assert_equal User, UserSession.klass
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_klass_name
|
23
|
-
assert_equal "User", UserSession.klass_name
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_klass_name_uses_custom_name
|
27
|
-
assert_equal "User", UserSession.klass_name
|
28
|
-
assert_equal "BackOfficeUser", BackOfficeUserSession.klass_name
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class InstanceMethodsTest < ActiveSupport::TestCase
|
33
|
-
def test_record_method
|
34
|
-
ben = users(:ben)
|
35
|
-
set_session_for(ben)
|
36
|
-
session = UserSession.find
|
37
|
-
assert_equal ben, session.record
|
38
|
-
assert_equal ben, session.user
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
module MagicColumnsTest
|
7
|
-
class ConfigTest < ActiveSupport::TestCase
|
8
|
-
def test_last_request_at_threshold_config
|
9
|
-
UserSession.last_request_at_threshold = 2.minutes
|
10
|
-
assert_equal 2.minutes, UserSession.last_request_at_threshold
|
11
|
-
|
12
|
-
UserSession.last_request_at_threshold 0
|
13
|
-
assert_equal 0, UserSession.last_request_at_threshold
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class InstanceMethodsTest < ActiveSupport::TestCase
|
18
|
-
def test_after_persisting_set_last_request_at
|
19
|
-
ben = users(:ben)
|
20
|
-
refute UserSession.create(ben).new_session?
|
21
|
-
|
22
|
-
set_cookie_for(ben)
|
23
|
-
old_last_request_at = ben.last_request_at
|
24
|
-
assert UserSession.find
|
25
|
-
ben.reload
|
26
|
-
assert ben.last_request_at != old_last_request_at
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_valid_increase_failed_login_count
|
30
|
-
ben = users(:ben)
|
31
|
-
old_failed_login_count = ben.failed_login_count
|
32
|
-
session = UserSession.create(login: ben.login, password: "wrong")
|
33
|
-
assert session.new_session?
|
34
|
-
ben.reload
|
35
|
-
assert_equal old_failed_login_count + 1, ben.failed_login_count
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_before_save_update_info
|
39
|
-
aaron = users(:aaron)
|
40
|
-
|
41
|
-
# increase failed login count
|
42
|
-
session = UserSession.create(login: aaron.login, password: "wrong")
|
43
|
-
assert session.new_session?
|
44
|
-
aaron.reload
|
45
|
-
assert_equal 0, aaron.login_count
|
46
|
-
assert_nil aaron.current_login_at
|
47
|
-
assert_nil aaron.current_login_ip
|
48
|
-
|
49
|
-
session = UserSession.create(login: aaron.login, password: "aaronrocks")
|
50
|
-
assert session.valid?
|
51
|
-
|
52
|
-
aaron.reload
|
53
|
-
assert_equal 1, aaron.login_count
|
54
|
-
assert_equal 0, aaron.failed_login_count
|
55
|
-
assert_nil aaron.last_login_at
|
56
|
-
assert_not_nil aaron.current_login_at
|
57
|
-
assert_nil aaron.last_login_ip
|
58
|
-
assert_equal "1.1.1.1", aaron.current_login_ip
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
module SessionTest
|
7
|
-
class ConfigTest < ActiveSupport::TestCase
|
8
|
-
def test_disable_magic_states_config
|
9
|
-
UserSession.disable_magic_states = true
|
10
|
-
assert_equal true, UserSession.disable_magic_states
|
11
|
-
|
12
|
-
UserSession.disable_magic_states false
|
13
|
-
assert_equal false, UserSession.disable_magic_states
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class InstanceMethodsTest < ActiveSupport::TestCase
|
18
|
-
def test_disabling_magic_states
|
19
|
-
UserSession.disable_magic_states = true
|
20
|
-
ben = users(:ben)
|
21
|
-
ben.update_attribute(:active, false)
|
22
|
-
refute UserSession.create(ben).new_session?
|
23
|
-
UserSession.disable_magic_states = false
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_validate_validate_magic_states_active
|
27
|
-
session = UserSession.new
|
28
|
-
ben = users(:ben)
|
29
|
-
session.unauthorized_record = ben
|
30
|
-
assert session.valid?
|
31
|
-
|
32
|
-
ben.update_attribute(:active, false)
|
33
|
-
refute session.valid?
|
34
|
-
refute session.errors[:base].empty?
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_validate_validate_magic_states_approved
|
38
|
-
session = UserSession.new
|
39
|
-
ben = users(:ben)
|
40
|
-
session.unauthorized_record = ben
|
41
|
-
assert session.valid?
|
42
|
-
|
43
|
-
ben.update_attribute(:approved, false)
|
44
|
-
refute session.valid?
|
45
|
-
refute session.errors[:base].empty?
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_validate_validate_magic_states_confirmed
|
49
|
-
session = UserSession.new
|
50
|
-
ben = users(:ben)
|
51
|
-
session.unauthorized_record = ben
|
52
|
-
assert session.valid?
|
53
|
-
|
54
|
-
ben.update_attribute(:confirmed, false)
|
55
|
-
refute session.valid?
|
56
|
-
refute session.errors[:base].empty?
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
module ParamsTest
|
7
|
-
class ConfigTest < ActiveSupport::TestCase
|
8
|
-
def test_params_key
|
9
|
-
UserSession.params_key = "my_params_key"
|
10
|
-
assert_equal "my_params_key", UserSession.params_key
|
11
|
-
|
12
|
-
UserSession.params_key "user_credentials"
|
13
|
-
assert_equal "user_credentials", UserSession.params_key
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_single_access_allowed_request_types
|
17
|
-
UserSession.single_access_allowed_request_types = ["my request type"]
|
18
|
-
assert_equal ["my request type"], UserSession.single_access_allowed_request_types
|
19
|
-
UserSession.single_access_allowed_request_types(
|
20
|
-
["application/rss+xml", "application/atom+xml"]
|
21
|
-
)
|
22
|
-
assert_equal(
|
23
|
-
["application/rss+xml", "application/atom+xml"],
|
24
|
-
UserSession.single_access_allowed_request_types
|
25
|
-
)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class InstanceMethodsTest < ActiveSupport::TestCase
|
30
|
-
def test_persist_persist_by_params
|
31
|
-
ben = users(:ben)
|
32
|
-
session = UserSession.new
|
33
|
-
|
34
|
-
refute session.persisting?
|
35
|
-
set_params_for(ben)
|
36
|
-
|
37
|
-
refute session.persisting?
|
38
|
-
refute session.unauthorized_record
|
39
|
-
refute session.record
|
40
|
-
assert_nil controller.session["user_credentials"]
|
41
|
-
|
42
|
-
set_request_content_type("text/plain")
|
43
|
-
refute session.persisting?
|
44
|
-
refute session.unauthorized_record
|
45
|
-
assert_nil controller.session["user_credentials"]
|
46
|
-
|
47
|
-
set_request_content_type("application/atom+xml")
|
48
|
-
assert session.persisting?
|
49
|
-
assert_equal ben, session.record
|
50
|
-
|
51
|
-
# should not persist since this is single access
|
52
|
-
assert_nil controller.session["user_credentials"]
|
53
|
-
|
54
|
-
set_request_content_type("application/rss+xml")
|
55
|
-
assert session.persisting?
|
56
|
-
assert_equal ben, session.unauthorized_record
|
57
|
-
assert_nil controller.session["user_credentials"]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
module PasswordTest
|
7
|
-
class ConfigTest < ActiveSupport::TestCase
|
8
|
-
def test_find_by_login_method
|
9
|
-
UserSession.find_by_login_method = "my_login_method"
|
10
|
-
assert_equal "my_login_method", UserSession.find_by_login_method
|
11
|
-
|
12
|
-
UserSession.find_by_login_method "find_by_login"
|
13
|
-
assert_equal "find_by_login", UserSession.find_by_login_method
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_verify_password_method
|
17
|
-
UserSession.verify_password_method = "my_login_method"
|
18
|
-
assert_equal "my_login_method", UserSession.verify_password_method
|
19
|
-
|
20
|
-
UserSession.verify_password_method "valid_password?"
|
21
|
-
assert_equal "valid_password?", UserSession.verify_password_method
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_generalize_credentials_error_mesages_set_to_false
|
25
|
-
UserSession.generalize_credentials_error_messages false
|
26
|
-
refute UserSession.generalize_credentials_error_messages
|
27
|
-
session = UserSession.create(login: users(:ben).login, password: "invalud-password")
|
28
|
-
assert_equal ["Password is not valid"], session.errors.full_messages
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_generalize_credentials_error_messages_set_to_true
|
32
|
-
UserSession.generalize_credentials_error_messages true
|
33
|
-
assert UserSession.generalize_credentials_error_messages
|
34
|
-
session = UserSession.create(login: users(:ben).login, password: "invalud-password")
|
35
|
-
assert_equal ["Login/Password combination is not valid"], session.errors.full_messages
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_generalize_credentials_error_messages_set_to_string
|
39
|
-
UserSession.generalize_credentials_error_messages = "Custom Error Message"
|
40
|
-
assert UserSession.generalize_credentials_error_messages
|
41
|
-
session = UserSession.create(login: users(:ben).login, password: "invalud-password")
|
42
|
-
assert_equal ["Custom Error Message"], session.errors.full_messages
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_login_field
|
46
|
-
UserSession.configured_password_methods = false
|
47
|
-
UserSession.login_field = :saweet
|
48
|
-
assert_equal :saweet, UserSession.login_field
|
49
|
-
session = UserSession.new
|
50
|
-
assert session.respond_to?(:saweet)
|
51
|
-
|
52
|
-
UserSession.login_field :login
|
53
|
-
assert_equal :login, UserSession.login_field
|
54
|
-
session = UserSession.new
|
55
|
-
assert session.respond_to?(:login)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_password_field
|
59
|
-
UserSession.configured_password_methods = false
|
60
|
-
UserSession.password_field = :saweet
|
61
|
-
assert_equal :saweet, UserSession.password_field
|
62
|
-
session = UserSession.new
|
63
|
-
assert session.respond_to?(:saweet)
|
64
|
-
|
65
|
-
UserSession.password_field :password
|
66
|
-
assert_equal :password, UserSession.password_field
|
67
|
-
session = UserSession.new
|
68
|
-
assert session.respond_to?(:password)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
class InstanceMethodsTest < ActiveSupport::TestCase
|
73
|
-
def test_init
|
74
|
-
session = UserSession.new
|
75
|
-
assert session.respond_to?(:login)
|
76
|
-
assert session.respond_to?(:login=)
|
77
|
-
assert session.respond_to?(:password)
|
78
|
-
assert session.respond_to?(:password=)
|
79
|
-
assert session.respond_to?(:protected_password, true)
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_credentials
|
83
|
-
session = UserSession.new
|
84
|
-
session.credentials = { login: "login", password: "pass" }
|
85
|
-
assert_equal "login", session.login
|
86
|
-
assert_nil session.password
|
87
|
-
assert_equal "pass", session.send(:protected_password)
|
88
|
-
assert_equal({ password: "<protected>", login: "login" }, session.credentials)
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_credentials_are_params_safe
|
92
|
-
session = UserSession.new
|
93
|
-
assert_nothing_raised { session.credentials = { hacker_method: "error!" } }
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_save_with_credentials
|
97
|
-
aaron = users(:aaron)
|
98
|
-
session = UserSession.new(login: aaron.login, password: "aaronrocks")
|
99
|
-
assert session.save
|
100
|
-
refute session.new_session?
|
101
|
-
assert_equal 1, session.record.login_count
|
102
|
-
assert Time.now >= session.record.current_login_at
|
103
|
-
assert_equal "1.1.1.1", session.record.current_login_ip
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
class PerishabilityTest < ActiveSupport::TestCase
|
7
|
-
def test_after_save
|
8
|
-
ben = users(:ben)
|
9
|
-
old_perishable_token = ben.perishable_token
|
10
|
-
UserSession.create(ben)
|
11
|
-
assert_not_equal old_perishable_token, ben.perishable_token
|
12
|
-
|
13
|
-
drew = employees(:drew)
|
14
|
-
refute UserSession.create(drew).new_session?
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
class PersistenceTest < ActiveSupport::TestCase
|
7
|
-
def test_find
|
8
|
-
aaron = users(:aaron)
|
9
|
-
refute UserSession.find
|
10
|
-
UserSession.allow_http_basic_auth = true
|
11
|
-
http_basic_auth_for(aaron) { assert UserSession.find }
|
12
|
-
set_cookie_for(aaron)
|
13
|
-
assert UserSession.find
|
14
|
-
unset_cookie
|
15
|
-
set_session_for(aaron)
|
16
|
-
session = UserSession.find
|
17
|
-
assert session
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_persisting
|
21
|
-
# tested thoroughly in test_find
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_should_set_remember_me_on_the_next_request
|
25
|
-
aaron = users(:aaron)
|
26
|
-
session = UserSession.new(aaron)
|
27
|
-
session.remember_me = true
|
28
|
-
refute UserSession.remember_me
|
29
|
-
assert session.save
|
30
|
-
assert session.remember_me?
|
31
|
-
session = UserSession.find(aaron)
|
32
|
-
assert session.remember_me?
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "test_helper"
|
4
|
-
|
5
|
-
module SessionTest
|
6
|
-
class ScopesTest < ActiveSupport::TestCase
|
7
|
-
def test_scope_method
|
8
|
-
assert_nil Authlogic::Session::Base.scope
|
9
|
-
|
10
|
-
thread1 = Thread.new do
|
11
|
-
scope = { id: :scope1 }
|
12
|
-
Authlogic::Session::Base.send(:scope=, scope)
|
13
|
-
assert_equal scope, Authlogic::Session::Base.scope
|
14
|
-
end
|
15
|
-
thread1.join
|
16
|
-
|
17
|
-
assert_nil Authlogic::Session::Base.scope
|
18
|
-
|
19
|
-
thread2 = Thread.new do
|
20
|
-
scope = { id: :scope2 }
|
21
|
-
Authlogic::Session::Base.send(:scope=, scope)
|
22
|
-
assert_equal scope, Authlogic::Session::Base.scope
|
23
|
-
end
|
24
|
-
thread2.join
|
25
|
-
|
26
|
-
assert_nil Authlogic::Session::Base.scope
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_with_scope_method
|
30
|
-
assert_raise(ArgumentError) { UserSession.with_scope }
|
31
|
-
|
32
|
-
UserSession.with_scope(find_options: { conditions: "awesome = 1" }, id: "some_id") do
|
33
|
-
assert_equal(
|
34
|
-
{ find_options: { conditions: "awesome = 1" }, id: "some_id" },
|
35
|
-
UserSession.scope
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
assert_nil UserSession.scope
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_initialize
|
43
|
-
UserSession.with_scope(find_options: { conditions: "awesome = 1" }, id: "some_id") do
|
44
|
-
session = UserSession.new
|
45
|
-
assert_equal(
|
46
|
-
{ find_options: { conditions: "awesome = 1" }, id: "some_id" },
|
47
|
-
session.scope
|
48
|
-
)
|
49
|
-
session.id = :another_id
|
50
|
-
assert_equal "another_id_some_id_test", session.send(:build_key, "test")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_search_for_record_with_scopes
|
55
|
-
binary_logic = companies(:binary_logic)
|
56
|
-
ben = users(:ben)
|
57
|
-
zack = users(:zack)
|
58
|
-
|
59
|
-
session = UserSession.new
|
60
|
-
assert_equal zack, session.send(:search_for_record, "find_by_login", zack.login)
|
61
|
-
|
62
|
-
session.scope = { find_options: { conditions: ["company_id = ?", binary_logic.id] } }
|
63
|
-
assert_nil session.send(:search_for_record, "find_by_login", zack.login)
|
64
|
-
|
65
|
-
assert_equal ben, session.send(:search_for_record, "find_by_login", ben.login)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|