authlogic 5.1.0 → 5.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/session/base.rb +44 -12
- data/lib/authlogic/test_case/mock_cookie_jar.rb +35 -0
- data/lib/authlogic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4ede36ceee21501805105c66349d58ba6c6d9d483d5fefc41b8d4cbd5189944
|
4
|
+
data.tar.gz: f323b446e8f8e2a722bb9d896249170596f64ebf8ff441b2740cb834c2b085b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26cda51c7c8e2b5a8be9395ef13e3d39d9ee1c73429542d107bb229747b9a004800771a96b8f516e4f994c8926b1d0ef2fb1bf45e38102646451c48a3e4fb453
|
7
|
+
data.tar.gz: 971d54be27f18e12d8d7eafad90e50627098c689b34e047c0ddea4a96f82abf8c80e45766f49fdd82a9efb45fd3508ca312ee4b0cc0508d06a37887d45f9fcb0
|
@@ -961,6 +961,20 @@ module Authlogic
|
|
961
961
|
end
|
962
962
|
alias sign_cookie= sign_cookie
|
963
963
|
|
964
|
+
# Should the cookie be encrypted? If the controller adapter supports it, this is a
|
965
|
+
# measure to hide the contents of the cookie (e.g. persistence_token)
|
966
|
+
def encrypt_cookie(value = nil)
|
967
|
+
if value && !controller.cookies.respond_to?(:encrypted)
|
968
|
+
raise "Encrypted cookies not supported with #{controller.class}!"
|
969
|
+
end
|
970
|
+
if value && sign_cookie
|
971
|
+
raise "It is recommended to use encrypt_cookie instead of sign_cookie. " \
|
972
|
+
"You may not enable both options."
|
973
|
+
end
|
974
|
+
rw_config(:encrypt_cookie, value, false)
|
975
|
+
end
|
976
|
+
alias_method :encrypt_cookie=, :encrypt_cookie
|
977
|
+
|
964
978
|
# Works exactly like cookie_key, but for sessions. See cookie_key for more info.
|
965
979
|
#
|
966
980
|
# * <tt>Default:</tt> cookie_key
|
@@ -1480,6 +1494,23 @@ module Authlogic
|
|
1480
1494
|
sign_cookie == true || sign_cookie == "true" || sign_cookie == "1"
|
1481
1495
|
end
|
1482
1496
|
|
1497
|
+
# If the cookie should be encrypted
|
1498
|
+
def encrypt_cookie
|
1499
|
+
return @encrypt_cookie if defined?(@encrypt_cookie)
|
1500
|
+
@encrypt_cookie = self.class.encrypt_cookie
|
1501
|
+
end
|
1502
|
+
|
1503
|
+
# Accepts a boolean as to whether the cookie should be encrypted. If true
|
1504
|
+
# the cookie will be saved in an encrypted state.
|
1505
|
+
def encrypt_cookie=(value)
|
1506
|
+
@encrypt_cookie = value
|
1507
|
+
end
|
1508
|
+
|
1509
|
+
# See encrypt_cookie
|
1510
|
+
def encrypt_cookie?
|
1511
|
+
encrypt_cookie == true || encrypt_cookie == "true" || encrypt_cookie == "1"
|
1512
|
+
end
|
1513
|
+
|
1483
1514
|
# The scope of the current object
|
1484
1515
|
def scope
|
1485
1516
|
@scope ||= {}
|
@@ -1623,7 +1654,9 @@ module Authlogic
|
|
1623
1654
|
end
|
1624
1655
|
|
1625
1656
|
def cookie_jar
|
1626
|
-
if self.class.
|
1657
|
+
if self.class.encrypt_cookie
|
1658
|
+
controller.cookies.encrypted
|
1659
|
+
elsif self.class.sign_cookie
|
1627
1660
|
controller.cookies.signed
|
1628
1661
|
else
|
1629
1662
|
controller.cookies
|
@@ -1705,13 +1738,8 @@ module Authlogic
|
|
1705
1738
|
|
1706
1739
|
# @api private
|
1707
1740
|
def generate_cookie_for_saving
|
1708
|
-
creds = ::Authlogic::CookieCredentials.new(
|
1709
|
-
record.persistence_token,
|
1710
|
-
record.send(record.class.primary_key),
|
1711
|
-
remember_me? ? remember_me_until : nil
|
1712
|
-
)
|
1713
1741
|
{
|
1714
|
-
value:
|
1742
|
+
value: generate_cookie_value.to_s,
|
1715
1743
|
expires: remember_me_until,
|
1716
1744
|
secure: secure,
|
1717
1745
|
httponly: httponly,
|
@@ -1720,6 +1748,14 @@ module Authlogic
|
|
1720
1748
|
}
|
1721
1749
|
end
|
1722
1750
|
|
1751
|
+
def generate_cookie_value
|
1752
|
+
::Authlogic::CookieCredentials.new(
|
1753
|
+
record.persistence_token,
|
1754
|
+
record.send(record.class.primary_key),
|
1755
|
+
remember_me? ? remember_me_until : nil
|
1756
|
+
)
|
1757
|
+
end
|
1758
|
+
|
1723
1759
|
# Returns a Proc to be executed by
|
1724
1760
|
# `ActionController::HttpAuthentication::Basic` when credentials are
|
1725
1761
|
# present in the HTTP request.
|
@@ -1935,11 +1971,7 @@ module Authlogic
|
|
1935
1971
|
end
|
1936
1972
|
|
1937
1973
|
def save_cookie
|
1938
|
-
|
1939
|
-
controller.cookies.signed[cookie_key] = generate_cookie_for_saving
|
1940
|
-
else
|
1941
|
-
controller.cookies[cookie_key] = generate_cookie_for_saving
|
1942
|
-
end
|
1974
|
+
cookie_jar[cookie_key] = generate_cookie_for_saving
|
1943
1975
|
end
|
1944
1976
|
|
1945
1977
|
# @api private
|
@@ -23,6 +23,10 @@ module Authlogic
|
|
23
23
|
def signed
|
24
24
|
@signed ||= MockSignedCookieJar.new(self)
|
25
25
|
end
|
26
|
+
|
27
|
+
def encrypted
|
28
|
+
@encrypted ||= MockEncryptedCookieJar.new(self)
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
# A mock of `ActionDispatch::Cookies::SignedKeyRotatingCookieJar`
|
@@ -35,6 +39,7 @@ module Authlogic
|
|
35
39
|
|
36
40
|
def initialize(parent_jar)
|
37
41
|
@parent_jar = parent_jar
|
42
|
+
parent_jar.each { |k, v| self[k] = v }
|
38
43
|
end
|
39
44
|
|
40
45
|
def [](val)
|
@@ -51,5 +56,35 @@ module Authlogic
|
|
51
56
|
@parent_jar[key] = options
|
52
57
|
end
|
53
58
|
end
|
59
|
+
|
60
|
+
class MockEncryptedCookieJar < MockCookieJar
|
61
|
+
attr_reader :parent_jar # helper for testing
|
62
|
+
|
63
|
+
def initialize(parent_jar)
|
64
|
+
@parent_jar = parent_jar
|
65
|
+
parent_jar.each { |k, v| self[k] = v }
|
66
|
+
end
|
67
|
+
|
68
|
+
def [](val)
|
69
|
+
encrypted_message = @parent_jar[val]
|
70
|
+
if encrypted_message
|
71
|
+
self.class.decrypt(encrypted_message)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def []=(key, options)
|
76
|
+
options[:value] = self.class.encrypt(options[:value])
|
77
|
+
@parent_jar[key] = options
|
78
|
+
end
|
79
|
+
|
80
|
+
# simple caesar cipher for testing
|
81
|
+
def self.encrypt(str)
|
82
|
+
str.unpack("U*").map(&:succ).pack("U*")
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.decrypt(str)
|
86
|
+
str.unpack("U*").map(&:pred).pack("U*")
|
87
|
+
end
|
88
|
+
end
|
54
89
|
end
|
55
90
|
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: 5.
|
4
|
+
version: 5.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-05-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|