authlogic 4.5.0 → 6.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/authlogic/acts_as_authentic/base.rb +19 -19
- 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 +67 -256
- 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 +12 -8
- 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 +28 -4
- data/lib/authlogic/controller_adapters/rack_adapter.rb +2 -0
- data/lib/authlogic/controller_adapters/rails_adapter.rb +7 -30
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +6 -0
- data/lib/authlogic/cookie_credentials.rb +63 -0
- data/lib/authlogic/crypto_providers/bcrypt.rb +3 -3
- data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
- data/lib/authlogic/crypto_providers/md5.rb +6 -6
- data/lib/authlogic/crypto_providers/scrypt.rb +2 -0
- data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
- data/lib/authlogic/crypto_providers/sha1.rb +7 -6
- data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
- data/lib/authlogic/crypto_providers/sha256.rb +5 -0
- data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
- data/lib/authlogic/crypto_providers/sha512.rb +9 -5
- data/lib/authlogic/crypto_providers.rb +5 -20
- data/lib/authlogic/errors.rb +50 -0
- data/lib/authlogic/i18n/translator.rb +4 -1
- data/lib/authlogic/i18n.rb +3 -1
- data/lib/authlogic/random.rb +2 -0
- data/lib/authlogic/session/base.rb +2197 -39
- data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
- data/lib/authlogic/test_case/mock_api_controller.rb +52 -0
- data/lib/authlogic/test_case/mock_controller.rb +3 -1
- data/lib/authlogic/test_case/mock_cookie_jar.rb +32 -6
- data/lib/authlogic/test_case/mock_logger.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +12 -0
- data/lib/authlogic/test_case/rails_request_adapter.rb +9 -1
- data/lib/authlogic/test_case.rb +5 -0
- data/lib/authlogic/version.rb +2 -1
- data/lib/authlogic.rb +5 -28
- metadata +175 -200
- 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 -348
- data/CONTRIBUTING.md +0 -91
- data/Gemfile +0 -6
- data/LICENSE +0 -20
- data/README.md +0 -448
- 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 -244
- 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
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authlogic
|
4
|
+
module Session
|
5
|
+
module MagicColumn
|
6
|
+
# Assigns the current time to the `last_request_at` attribute.
|
7
|
+
#
|
8
|
+
# 1. The `last_request_at` column must exist
|
9
|
+
# 2. Assignment can be disabled on a per-controller basis
|
10
|
+
# 3. Assignment will not happen more often than `last_request_at_threshold`
|
11
|
+
# seconds.
|
12
|
+
#
|
13
|
+
# - current_time - a `Time`
|
14
|
+
# - record - eg. a `User`
|
15
|
+
# - controller - an `Authlogic::ControllerAdapters::AbstractAdapter`
|
16
|
+
# - last_request_at_threshold - integer - seconds
|
17
|
+
#
|
18
|
+
# @api private
|
19
|
+
class AssignsLastRequestAt
|
20
|
+
def initialize(current_time, record, controller, last_request_at_threshold)
|
21
|
+
@current_time = current_time
|
22
|
+
@record = record
|
23
|
+
@controller = controller
|
24
|
+
@last_request_at_threshold = last_request_at_threshold
|
25
|
+
end
|
26
|
+
|
27
|
+
def assign
|
28
|
+
return unless assign?
|
29
|
+
@record.last_request_at = @current_time
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# @api private
|
35
|
+
def assign?
|
36
|
+
@record &&
|
37
|
+
@record.class.column_names.include?("last_request_at") &&
|
38
|
+
@controller.last_request_update_allowed? && (
|
39
|
+
@record.last_request_at.blank? ||
|
40
|
+
@last_request_at_threshold.to_i.seconds.ago >= @record.last_request_at
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Authlogic
|
4
|
+
module TestCase
|
5
|
+
# Basically acts like an API controller but doesn't do anything.
|
6
|
+
# Authlogic can interact with this, do it's thing and then you can look at
|
7
|
+
# the controller object to see if anything changed.
|
8
|
+
class MockAPIController < ControllerAdapters::AbstractAdapter
|
9
|
+
attr_writer :request_content_type
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
end
|
13
|
+
|
14
|
+
# Expected API controller has no cookies method.
|
15
|
+
undef :cookies
|
16
|
+
|
17
|
+
def cookie_domain
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def logger
|
22
|
+
@logger ||= MockLogger.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def params
|
26
|
+
@params ||= {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def request
|
30
|
+
@request ||= MockRequest.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def request_content_type
|
34
|
+
@request_content_type ||= "text/html"
|
35
|
+
end
|
36
|
+
|
37
|
+
def session
|
38
|
+
@session ||= {}
|
39
|
+
end
|
40
|
+
|
41
|
+
# If method is defined, it causes below behavior...
|
42
|
+
# controller = Authlogic::ControllerAdapters::RailsAdapter.new(
|
43
|
+
# Authlogic::TestCase::MockAPIController.new
|
44
|
+
# )
|
45
|
+
# controller.responds_to_single_access_allowed? #=> true
|
46
|
+
# controller.single_access_allowed?
|
47
|
+
# #=> NoMethodError: undefined method `single_access_allowed?' for nil:NilClass
|
48
|
+
#
|
49
|
+
undef :single_access_allowed?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module TestCase
|
3
5
|
# Basically acts like a controller but doesn't do anything. Authlogic can interact
|
@@ -37,7 +39,7 @@ module Authlogic
|
|
37
39
|
end
|
38
40
|
|
39
41
|
def request
|
40
|
-
@request ||= MockRequest.new(
|
42
|
+
@request ||= MockRequest.new(self)
|
41
43
|
end
|
42
44
|
|
43
45
|
def request_content_type
|
@@ -1,6 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module TestCase
|
3
5
|
# A mock of `ActionDispatch::Cookies::CookieJar`.
|
6
|
+
# See action_dispatch/middleware/cookies.rb
|
4
7
|
class MockCookieJar < Hash # :nodoc:
|
5
8
|
attr_accessor :set_cookies
|
6
9
|
|
@@ -9,9 +12,12 @@ module Authlogic
|
|
9
12
|
hash && hash[:value]
|
10
13
|
end
|
11
14
|
|
15
|
+
# @param options - "the cookie's value [usually a string] or a hash of
|
16
|
+
# options as documented above [in action_dispatch/middleware/cookies.rb]"
|
12
17
|
def []=(key, options)
|
13
|
-
|
14
|
-
|
18
|
+
opt = cookie_options_to_hash(options)
|
19
|
+
(@set_cookies ||= {})[key.to_s] = opt
|
20
|
+
super(key, opt)
|
15
21
|
end
|
16
22
|
|
17
23
|
def delete(key, _options = {})
|
@@ -25,8 +31,24 @@ module Authlogic
|
|
25
31
|
def encrypted
|
26
32
|
@encrypted ||= MockEncryptedCookieJar.new(self)
|
27
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# @api private
|
38
|
+
def cookie_options_to_hash(options)
|
39
|
+
if options.is_a?(Hash)
|
40
|
+
options
|
41
|
+
else
|
42
|
+
{ value: options }
|
43
|
+
end
|
44
|
+
end
|
28
45
|
end
|
29
46
|
|
47
|
+
# A mock of `ActionDispatch::Cookies::SignedKeyRotatingCookieJar`
|
48
|
+
#
|
49
|
+
# > .. a jar that'll automatically generate a signed representation of
|
50
|
+
# > cookie value and verify it when reading from the cookie again.
|
51
|
+
# > actionpack/lib/action_dispatch/middleware/cookies.rb
|
30
52
|
class MockSignedCookieJar < MockCookieJar
|
31
53
|
attr_reader :parent_jar # helper for testing
|
32
54
|
|
@@ -45,11 +67,14 @@ module Authlogic
|
|
45
67
|
end
|
46
68
|
|
47
69
|
def []=(key, options)
|
48
|
-
|
49
|
-
|
70
|
+
opt = cookie_options_to_hash(options)
|
71
|
+
opt[:value] = "#{opt[:value]}--#{Digest::SHA1.hexdigest opt[:value]}"
|
72
|
+
@parent_jar[key] = opt
|
50
73
|
end
|
51
74
|
end
|
52
75
|
|
76
|
+
# Which ActionDispatch class is this a mock of?
|
77
|
+
# TODO: Document as with other mocks above.
|
53
78
|
class MockEncryptedCookieJar < MockCookieJar
|
54
79
|
attr_reader :parent_jar # helper for testing
|
55
80
|
|
@@ -66,8 +91,9 @@ module Authlogic
|
|
66
91
|
end
|
67
92
|
|
68
93
|
def []=(key, options)
|
69
|
-
|
70
|
-
|
94
|
+
opt = cookie_options_to_hash(options)
|
95
|
+
opt[:value] = self.class.encrypt(opt[:value])
|
96
|
+
@parent_jar[key] = opt
|
71
97
|
end
|
72
98
|
|
73
99
|
# simple caesar cipher for testing
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module TestCase
|
3
5
|
class MockRequest # :nodoc:
|
@@ -7,6 +9,16 @@ module Authlogic
|
|
7
9
|
self.controller = controller
|
8
10
|
end
|
9
11
|
|
12
|
+
def env
|
13
|
+
@env ||= {
|
14
|
+
ControllerAdapters::AbstractAdapter::ENV_SESSION_OPTIONS => {}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def format
|
19
|
+
controller.request_content_type if controller.respond_to? :request_content_type
|
20
|
+
end
|
21
|
+
|
10
22
|
def ip
|
11
23
|
controller&.respond_to?(:env) &&
|
12
24
|
controller.env.is_a?(Hash) &&
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Authlogic
|
2
4
|
module TestCase
|
3
5
|
# Adapts authlogic to work with the @request object when testing. This way Authlogic
|
@@ -10,7 +12,7 @@ module Authlogic
|
|
10
12
|
def cookies
|
11
13
|
new_cookies = MockCookieJar.new
|
12
14
|
super.each do |key, value|
|
13
|
-
new_cookies[key] = value
|
15
|
+
new_cookies[key] = cookie_value(value)
|
14
16
|
end
|
15
17
|
new_cookies
|
16
18
|
end
|
@@ -26,6 +28,12 @@ module Authlogic
|
|
26
28
|
def request_content_type
|
27
29
|
request.format.to_s
|
28
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def cookie_value(value)
|
35
|
+
value.is_a?(Hash) ? value[:value] : value
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
data/lib/authlogic/test_case.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require File.dirname(__FILE__) + "/test_case/rails_request_adapter"
|
4
|
+
require File.dirname(__FILE__) + "/test_case/mock_api_controller"
|
2
5
|
require File.dirname(__FILE__) + "/test_case/mock_cookie_jar"
|
3
6
|
require File.dirname(__FILE__) + "/test_case/mock_controller"
|
4
7
|
require File.dirname(__FILE__) + "/test_case/mock_logger"
|
5
8
|
require File.dirname(__FILE__) + "/test_case/mock_request"
|
6
9
|
|
10
|
+
# :nodoc:
|
7
11
|
module Authlogic
|
8
12
|
# This module is a collection of methods and classes that help you easily test
|
9
13
|
# Authlogic. In fact, I use these same tools to test the internals of
|
@@ -204,6 +208,7 @@ module Authlogic
|
|
204
208
|
end
|
205
209
|
end
|
206
210
|
|
211
|
+
# TODO: Why are these lines inside the `Authlogic` module? Should be outside?
|
207
212
|
::Test::Unit::TestCase.send(:include, TestCase) if defined?(::Test::Unit::TestCase)
|
208
213
|
::MiniTest::Unit::TestCase.send(:include, TestCase) if defined?(::MiniTest::Unit::TestCase)
|
209
214
|
::MiniTest::Test.send(:include, TestCase) if defined?(::MiniTest::Test)
|
data/lib/authlogic/version.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require "rubygems"
|
4
4
|
|
5
|
+
# :nodoc:
|
5
6
|
module Authlogic
|
6
7
|
# Returns a `::Gem::Version`, the version number of the authlogic gem.
|
7
8
|
#
|
@@ -16,6 +17,6 @@ module Authlogic
|
|
16
17
|
#
|
17
18
|
# @api public
|
18
19
|
def self.gem_version
|
19
|
-
::Gem::Version.new("4.
|
20
|
+
::Gem::Version.new("6.4.2")
|
20
21
|
end
|
21
22
|
end
|
data/lib/authlogic.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Authlogic uses ActiveSupport's core extensions like `strip_heredoc` and
|
2
4
|
# `squish`. ActiveRecord does not `require` these exensions, so we must.
|
3
5
|
#
|
@@ -11,18 +13,16 @@ require "active_record"
|
|
11
13
|
path = File.dirname(__FILE__) + "/authlogic/"
|
12
14
|
|
13
15
|
[
|
16
|
+
"errors",
|
14
17
|
"i18n",
|
15
18
|
"random",
|
16
|
-
"regex",
|
17
19
|
"config",
|
18
20
|
|
19
21
|
"controller_adapters/abstract_adapter",
|
22
|
+
"cookie_credentials",
|
20
23
|
|
21
24
|
"crypto_providers",
|
22
25
|
|
23
|
-
"authenticates_many/base",
|
24
|
-
"authenticates_many/association",
|
25
|
-
|
26
26
|
"acts_as_authentic/email",
|
27
27
|
"acts_as_authentic/logged_in_status",
|
28
28
|
"acts_as_authentic/login",
|
@@ -30,34 +30,11 @@ path = File.dirname(__FILE__) + "/authlogic/"
|
|
30
30
|
"acts_as_authentic/password",
|
31
31
|
"acts_as_authentic/perishable_token",
|
32
32
|
"acts_as_authentic/persistence_token",
|
33
|
-
"acts_as_authentic/restful_authentication",
|
34
33
|
"acts_as_authentic/session_maintenance",
|
35
34
|
"acts_as_authentic/single_access_token",
|
36
|
-
"acts_as_authentic/validations_scope",
|
37
35
|
"acts_as_authentic/base",
|
38
36
|
|
39
|
-
"session/
|
40
|
-
"session/active_record_trickery",
|
41
|
-
"session/brute_force_protection",
|
42
|
-
"session/callbacks",
|
43
|
-
"session/cookies",
|
44
|
-
"session/existence",
|
45
|
-
"session/foundation",
|
46
|
-
"session/http_auth",
|
47
|
-
"session/id",
|
48
|
-
"session/klass",
|
49
|
-
"session/magic_columns",
|
50
|
-
"session/magic_states",
|
51
|
-
"session/params",
|
52
|
-
"session/password",
|
53
|
-
"session/perishable_token",
|
54
|
-
"session/persistence",
|
55
|
-
"session/priority_record",
|
56
|
-
"session/scopes",
|
57
|
-
"session/session",
|
58
|
-
"session/timeout",
|
59
|
-
"session/unauthorized_record",
|
60
|
-
"session/validation",
|
37
|
+
"session/magic_column/assigns_last_request_at",
|
61
38
|
"session/base"
|
62
39
|
].each do |library|
|
63
40
|
require path + library
|