authlogic 6.1.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/authlogic/acts_as_authentic/base.rb +16 -1
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +2 -2
- data/lib/authlogic/controller_adapters/rails_adapter.rb +1 -1
- data/lib/authlogic/errors.rb +15 -0
- data/lib/authlogic/session/base.rb +11 -5
- data/lib/authlogic/test_case.rb +1 -0
- data/lib/authlogic/test_case/mock_api_controller.rb +52 -0
- data/lib/authlogic/test_case/mock_controller.rb +1 -1
- data/lib/authlogic/test_case/mock_cookie_jar.rb +2 -0
- data/lib/authlogic/test_case/mock_request.rb +4 -0
- data/lib/authlogic/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3db4f35b09d1723bab91b36afb8fbd79c1583896b19186846f8b1b25cb7793e
|
4
|
+
data.tar.gz: a517af1c9f5341e9bd58722711f7046fb51dfd2c1440e072f81170be196d2518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
96
|
+
def save_without_session_maintenance(**options)
|
97
97
|
self.skip_session_maintenance = true
|
98
|
-
result = save(
|
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
|
data/lib/authlogic/errors.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/authlogic/test_case.rb
CHANGED
@@ -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
|
data/lib/authlogic/version.rb
CHANGED
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.
|
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-
|
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
|