authlogic 4.5.0 → 6.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/lib/authlogic/acts_as_authentic/base.rb +19 -19
  3. data/lib/authlogic/acts_as_authentic/email.rb +3 -170
  4. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +3 -1
  5. data/lib/authlogic/acts_as_authentic/login.rb +7 -174
  6. data/lib/authlogic/acts_as_authentic/magic_columns.rb +7 -4
  7. data/lib/authlogic/acts_as_authentic/password.rb +67 -256
  8. data/lib/authlogic/acts_as_authentic/perishable_token.rb +8 -5
  9. data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -4
  10. data/lib/authlogic/acts_as_authentic/queries/case_sensitivity.rb +53 -0
  11. data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +36 -20
  12. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +12 -8
  13. data/lib/authlogic/acts_as_authentic/single_access_token.rb +10 -8
  14. data/lib/authlogic/config.rb +9 -1
  15. data/lib/authlogic/controller_adapters/abstract_adapter.rb +28 -4
  16. data/lib/authlogic/controller_adapters/rack_adapter.rb +2 -0
  17. data/lib/authlogic/controller_adapters/rails_adapter.rb +7 -30
  18. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +6 -0
  19. data/lib/authlogic/cookie_credentials.rb +63 -0
  20. data/lib/authlogic/crypto_providers/bcrypt.rb +3 -3
  21. data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
  22. data/lib/authlogic/crypto_providers/md5.rb +6 -6
  23. data/lib/authlogic/crypto_providers/scrypt.rb +2 -0
  24. data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
  25. data/lib/authlogic/crypto_providers/sha1.rb +7 -6
  26. data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
  27. data/lib/authlogic/crypto_providers/sha256.rb +5 -0
  28. data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
  29. data/lib/authlogic/crypto_providers/sha512.rb +9 -5
  30. data/lib/authlogic/crypto_providers.rb +5 -20
  31. data/lib/authlogic/errors.rb +50 -0
  32. data/lib/authlogic/i18n/translator.rb +4 -1
  33. data/lib/authlogic/i18n.rb +3 -1
  34. data/lib/authlogic/random.rb +2 -0
  35. data/lib/authlogic/session/base.rb +2197 -39
  36. data/lib/authlogic/session/magic_column/assigns_last_request_at.rb +46 -0
  37. data/lib/authlogic/test_case/mock_api_controller.rb +52 -0
  38. data/lib/authlogic/test_case/mock_controller.rb +3 -1
  39. data/lib/authlogic/test_case/mock_cookie_jar.rb +32 -6
  40. data/lib/authlogic/test_case/mock_logger.rb +2 -0
  41. data/lib/authlogic/test_case/mock_request.rb +12 -0
  42. data/lib/authlogic/test_case/rails_request_adapter.rb +9 -1
  43. data/lib/authlogic/test_case.rb +5 -0
  44. data/lib/authlogic/version.rb +2 -1
  45. data/lib/authlogic.rb +5 -28
  46. metadata +175 -200
  47. data/.github/ISSUE_TEMPLATE/bug_report.md +0 -28
  48. data/.github/ISSUE_TEMPLATE/feature_proposal.md +0 -32
  49. data/.github/triage.md +0 -86
  50. data/.gitignore +0 -15
  51. data/.rubocop.yml +0 -133
  52. data/.rubocop_todo.yml +0 -74
  53. data/.travis.yml +0 -24
  54. data/CHANGELOG.md +0 -348
  55. data/CONTRIBUTING.md +0 -91
  56. data/Gemfile +0 -6
  57. data/LICENSE +0 -20
  58. data/README.md +0 -448
  59. data/Rakefile +0 -21
  60. data/UPGRADING.md +0 -22
  61. data/authlogic.gemspec +0 -40
  62. data/doc/use_normal_rails_validation.md +0 -82
  63. data/gemfiles/Gemfile.rails-4.2.x +0 -6
  64. data/gemfiles/Gemfile.rails-5.1.x +0 -6
  65. data/gemfiles/Gemfile.rails-5.2.x +0 -6
  66. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +0 -106
  67. data/lib/authlogic/acts_as_authentic/validations_scope.rb +0 -35
  68. data/lib/authlogic/authenticates_many/association.rb +0 -50
  69. data/lib/authlogic/authenticates_many/base.rb +0 -81
  70. data/lib/authlogic/crypto_providers/aes256.rb +0 -71
  71. data/lib/authlogic/crypto_providers/wordpress.rb +0 -72
  72. data/lib/authlogic/regex.rb +0 -79
  73. data/lib/authlogic/session/activation.rb +0 -73
  74. data/lib/authlogic/session/active_record_trickery.rb +0 -65
  75. data/lib/authlogic/session/brute_force_protection.rb +0 -127
  76. data/lib/authlogic/session/callbacks.rb +0 -153
  77. data/lib/authlogic/session/cookies.rb +0 -329
  78. data/lib/authlogic/session/existence.rb +0 -103
  79. data/lib/authlogic/session/foundation.rb +0 -105
  80. data/lib/authlogic/session/http_auth.rb +0 -107
  81. data/lib/authlogic/session/id.rb +0 -53
  82. data/lib/authlogic/session/klass.rb +0 -73
  83. data/lib/authlogic/session/magic_columns.rb +0 -119
  84. data/lib/authlogic/session/magic_states.rb +0 -82
  85. data/lib/authlogic/session/params.rb +0 -130
  86. data/lib/authlogic/session/password.rb +0 -318
  87. data/lib/authlogic/session/perishable_token.rb +0 -24
  88. data/lib/authlogic/session/persistence.rb +0 -77
  89. data/lib/authlogic/session/priority_record.rb +0 -38
  90. data/lib/authlogic/session/scopes.rb +0 -138
  91. data/lib/authlogic/session/session.rb +0 -77
  92. data/lib/authlogic/session/timeout.rb +0 -103
  93. data/lib/authlogic/session/unauthorized_record.rb +0 -56
  94. data/lib/authlogic/session/validation.rb +0 -93
  95. data/test/acts_as_authentic_test/base_test.rb +0 -27
  96. data/test/acts_as_authentic_test/email_test.rb +0 -241
  97. data/test/acts_as_authentic_test/logged_in_status_test.rb +0 -64
  98. data/test/acts_as_authentic_test/login_test.rb +0 -153
  99. data/test/acts_as_authentic_test/magic_columns_test.rb +0 -29
  100. data/test/acts_as_authentic_test/password_test.rb +0 -263
  101. data/test/acts_as_authentic_test/perishable_token_test.rb +0 -98
  102. data/test/acts_as_authentic_test/persistence_token_test.rb +0 -62
  103. data/test/acts_as_authentic_test/restful_authentication_test.rb +0 -48
  104. data/test/acts_as_authentic_test/session_maintenance_test.rb +0 -150
  105. data/test/acts_as_authentic_test/single_access_test.rb +0 -46
  106. data/test/adapter_test.rb +0 -23
  107. data/test/authenticates_many_test.rb +0 -33
  108. data/test/config_test.rb +0 -38
  109. data/test/crypto_provider_test/aes256_test.rb +0 -16
  110. data/test/crypto_provider_test/bcrypt_test.rb +0 -16
  111. data/test/crypto_provider_test/scrypt_test.rb +0 -16
  112. data/test/crypto_provider_test/sha1_test.rb +0 -25
  113. data/test/crypto_provider_test/sha256_test.rb +0 -16
  114. data/test/crypto_provider_test/sha512_test.rb +0 -16
  115. data/test/crypto_provider_test/wordpress_test.rb +0 -26
  116. data/test/fixtures/companies.yml +0 -5
  117. data/test/fixtures/employees.yml +0 -17
  118. data/test/fixtures/projects.yml +0 -3
  119. data/test/fixtures/users.yml +0 -41
  120. data/test/i18n/lol.yml +0 -4
  121. data/test/i18n_test.rb +0 -35
  122. data/test/libs/affiliate.rb +0 -9
  123. data/test/libs/company.rb +0 -8
  124. data/test/libs/employee.rb +0 -9
  125. data/test/libs/employee_session.rb +0 -4
  126. data/test/libs/ldaper.rb +0 -5
  127. data/test/libs/project.rb +0 -5
  128. data/test/libs/user.rb +0 -9
  129. data/test/libs/user_session.rb +0 -27
  130. data/test/random_test.rb +0 -15
  131. data/test/session_test/activation_test.rb +0 -45
  132. data/test/session_test/active_record_trickery_test.rb +0 -78
  133. data/test/session_test/brute_force_protection_test.rb +0 -110
  134. data/test/session_test/callbacks_test.rb +0 -42
  135. data/test/session_test/cookies_test.rb +0 -244
  136. data/test/session_test/credentials_test.rb +0 -0
  137. data/test/session_test/existence_test.rb +0 -88
  138. data/test/session_test/foundation_test.rb +0 -24
  139. data/test/session_test/http_auth_test.rb +0 -60
  140. data/test/session_test/id_test.rb +0 -19
  141. data/test/session_test/klass_test.rb +0 -42
  142. data/test/session_test/magic_columns_test.rb +0 -62
  143. data/test/session_test/magic_states_test.rb +0 -60
  144. data/test/session_test/params_test.rb +0 -61
  145. data/test/session_test/password_test.rb +0 -107
  146. data/test/session_test/perishability_test.rb +0 -17
  147. data/test/session_test/persistence_test.rb +0 -35
  148. data/test/session_test/scopes_test.rb +0 -68
  149. data/test/session_test/session_test.rb +0 -80
  150. data/test/session_test/timeout_test.rb +0 -84
  151. data/test/session_test/unauthorized_record_test.rb +0 -15
  152. data/test/session_test/validation_test.rb +0 -25
  153. 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(controller)
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
- (@set_cookies ||= {})[key.to_s] = options
14
- super
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
- options[:value] = "#{options[:value]}--#{Digest::SHA1.hexdigest options[:value]}"
49
- @parent_jar[key] = options
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
- options[:value] = self.class.encrypt(options[:value])
70
- @parent_jar[key] = options
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
  # Simple class to replace real loggers, so that we can raise any errors being logged.
@@ -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[: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
@@ -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)
@@ -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.5.0")
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/activation",
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