authlogic 6.1.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88e14eb91ceaf33fca0867ad9816d8ee719215bdb9f5ff26c2c4754d84c82dd8
4
- data.tar.gz: 1dfbc1800a0fd0766bde87dfaa4a351b4b377e4240ad81aaa7d163c547d4d2a4
3
+ metadata.gz: f3db4f35b09d1723bab91b36afb8fbd79c1583896b19186846f8b1b25cb7793e
4
+ data.tar.gz: a517af1c9f5341e9bd58722711f7046fb51dfd2c1440e072f81170be196d2518
5
5
  SHA512:
6
- metadata.gz: a9e01562988e0b0a1660b7fa51009d71a76c01bca17711d278fd9d5e7271c3ef0e165da9622a7049b15f45d994d108e51c6fff0689ad4afe063df62525ddc572
7
- data.tar.gz: b0930fa9bc9d370cb71b1e502ece7885319429aff8f49039a8150621f9eb79bd9301c6e028933e156eb28f50a571a0586c23c918280a23f681bc7f45e440aa4f
6
+ metadata.gz: dd2fa0ad62c54eb721a8d3fb1d85ca1aa59b122bed688eca908a4cde2487fce1a5c084ffa365fd3b975d576f99a6a86bd243f950a1f2d07ddc1b6f171afed345
7
+ data.tar.gz: 519fcf4568fee21a0a43c9f7ec5ea740edcb84cf5cb95f48bf5a1819a1c091ba882f2f54f169497c20cf3821eb556a537687330950643b1b7d4f0d2a138961f0
@@ -31,8 +31,8 @@ module Authlogic
31
31
  #
32
32
  # See the various sub modules for the configuration they provide.
33
33
  def acts_as_authentic
34
- return unless db_setup?
35
34
  yield self if block_given?
35
+ return unless db_setup?
36
36
  acts_as_authentic_modules.each { |mod| include mod }
37
37
  end
38
38
 
@@ -65,12 +65,27 @@ module Authlogic
65
65
  self.acts_as_authentic_modules = modules
66
66
  end
67
67
 
68
+ # Some Authlogic modules requires a database connection with a existing
69
+ # users table by the moment when you call the `acts_as_authentic`
70
+ # method. If you try to call `acts_as_authentic` without a database
71
+ # connection, it will raise a `Authlogic::ModelSetupError`.
72
+ #
73
+ # If you rely on the User model before the database is setup correctly,
74
+ # set this field to false.
75
+ # * <tt>Default:</tt> false
76
+ # * <tt>Accepts:</tt> Boolean
77
+ def raise_on_model_setup_error(value = nil)
78
+ rw_config(:raise_on_model_setup_error, value, false)
79
+ end
80
+ alias raise_on_model_setup_error= raise_on_model_setup_error
81
+
68
82
  private
69
83
 
70
84
  def db_setup?
71
85
  column_names
72
86
  true
73
87
  rescue StandardError
88
+ raise ModelSetupError if raise_on_model_setup_error
74
89
  false
75
90
  end
76
91
 
@@ -93,9 +93,9 @@ module Authlogic
93
93
  end
94
94
 
95
95
  # Save the record and skip session maintenance all together.
96
- def save_without_session_maintenance(*args)
96
+ def save_without_session_maintenance(**options)
97
97
  self.skip_session_maintenance = true
98
- result = save(*args)
98
+ result = save(**options)
99
99
  self.skip_session_maintenance = false
100
100
  result
101
101
  end
@@ -14,7 +14,7 @@ module Authlogic
14
14
  # Returns a `ActionDispatch::Cookies::CookieJar`. See the AC guide
15
15
  # http://guides.rubyonrails.org/action_controller_overview.html#cookies
16
16
  def cookies
17
- controller.send(:cookies)
17
+ controller.respond_to?(:cookies, true) ? controller.send(:cookies) : nil
18
18
  end
19
19
 
20
20
  def cookie_domain
@@ -32,4 +32,19 @@ module Authlogic
32
32
  EOS
33
33
  end
34
34
  end
35
+
36
+ # :nodoc:
37
+ class ModelSetupError < Error
38
+ def message
39
+ <<-EOS
40
+ You must establish a database connection and run the migrations before
41
+ using acts_as_authentic. If you need to load the User model before the
42
+ database is set up correctly, please set the following:
43
+
44
+ acts_as_authentic do |c|
45
+ c.raise_on_model_setup_error = false
46
+ end
47
+ EOS
48
+ end
49
+ end
35
50
  end
@@ -415,10 +415,10 @@ module Authlogic
415
415
  before_save :set_last_request_at
416
416
 
417
417
  after_save :reset_perishable_token!
418
- after_save :save_cookie
418
+ after_save :save_cookie, if: :cookie_enabled?
419
419
  after_save :update_session
420
420
 
421
- after_destroy :destroy_cookie
421
+ after_destroy :destroy_cookie, if: :cookie_enabled?
422
422
  after_destroy :update_session
423
423
 
424
424
  # `validate` callbacks, in deliberate order. For example,
@@ -948,7 +948,7 @@ module Authlogic
948
948
  # Should the cookie be signed? If the controller adapter supports it, this is a
949
949
  # measure against cookie tampering.
950
950
  def sign_cookie(value = nil)
951
- if value && !controller.cookies.respond_to?(:signed)
951
+ if value && controller && !controller.cookies.respond_to?(:signed)
952
952
  raise "Signed cookies not supported with #{controller.class}!"
953
953
  end
954
954
  rw_config(:sign_cookie, value, false)
@@ -958,7 +958,7 @@ module Authlogic
958
958
  # Should the cookie be encrypted? If the controller adapter supports it, this is a
959
959
  # measure to hide the contents of the cookie (e.g. persistence_token)
960
960
  def encrypt_cookie(value = nil)
961
- if value && !controller.cookies.respond_to?(:encrypted)
961
+ if value && controller && !controller.cookies.respond_to?(:encrypted)
962
962
  raise "Encrypted cookies not supported with #{controller.class}!"
963
963
  end
964
964
  if value && sign_cookie
@@ -967,7 +967,7 @@ module Authlogic
967
967
  end
968
968
  rw_config(:encrypt_cookie, value, false)
969
969
  end
970
- alias_method :encrypt_cookie=, :encrypt_cookie
970
+ alias encrypt_cookie= encrypt_cookie
971
971
 
972
972
  # Works exactly like cookie_key, but for sessions. See cookie_key for more info.
973
973
  #
@@ -1623,12 +1623,18 @@ module Authlogic
1623
1623
  # @api private
1624
1624
  # @return ::Authlogic::CookieCredentials or if no cookie is found, nil
1625
1625
  def cookie_credentials
1626
+ return unless cookie_enabled?
1627
+
1626
1628
  cookie_value = cookie_jar[cookie_key]
1627
1629
  unless cookie_value.nil?
1628
1630
  ::Authlogic::CookieCredentials.parse(cookie_value)
1629
1631
  end
1630
1632
  end
1631
1633
 
1634
+ def cookie_enabled?
1635
+ !controller.cookies.nil?
1636
+ end
1637
+
1632
1638
  def cookie_jar
1633
1639
  if self.class.encrypt_cookie
1634
1640
  controller.cookies.encrypted
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require File.dirname(__FILE__) + "/test_case/rails_request_adapter"
4
+ require File.dirname(__FILE__) + "/test_case/mock_api_controller"
4
5
  require File.dirname(__FILE__) + "/test_case/mock_cookie_jar"
5
6
  require File.dirname(__FILE__) + "/test_case/mock_controller"
6
7
  require File.dirname(__FILE__) + "/test_case/mock_logger"
@@ -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
@@ -39,7 +39,7 @@ module Authlogic
39
39
  end
40
40
 
41
41
  def request
42
- @request ||= MockRequest.new(controller)
42
+ @request ||= MockRequest.new(self)
43
43
  end
44
44
 
45
45
  def request_content_type
@@ -57,6 +57,8 @@ module Authlogic
57
57
  end
58
58
  end
59
59
 
60
+ # Which ActionDispatch class is this a mock of?
61
+ # TODO: Document as with other mocks above.
60
62
  class MockEncryptedCookieJar < MockCookieJar
61
63
  attr_reader :parent_jar # helper for testing
62
64
 
@@ -9,6 +9,10 @@ module Authlogic
9
9
  self.controller = controller
10
10
  end
11
11
 
12
+ def format
13
+ controller.request_content_type if controller.respond_to? :request_content_type
14
+ end
15
+
12
16
  def ip
13
17
  controller&.respond_to?(:env) &&
14
18
  controller.env.is_a?(Hash) &&
@@ -17,6 +17,6 @@ module Authlogic
17
17
  #
18
18
  # @api public
19
19
  def self.gem_version
20
- ::Gem::Version.new("6.1.0")
20
+ ::Gem::Version.new("6.2.0")
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authlogic
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Johnson
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-05-08 00:00:00.000000000 Z
13
+ date: 2020-09-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activemodel
@@ -320,6 +320,7 @@ files:
320
320
  - lib/authlogic/session/base.rb
321
321
  - lib/authlogic/session/magic_column/assigns_last_request_at.rb
322
322
  - lib/authlogic/test_case.rb
323
+ - lib/authlogic/test_case/mock_api_controller.rb
323
324
  - lib/authlogic/test_case/mock_controller.rb
324
325
  - lib/authlogic/test_case/mock_cookie_jar.rb
325
326
  - lib/authlogic/test_case/mock_logger.rb