authlogic 5.0.4 → 6.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/authlogic.rb +1 -0
- data/lib/authlogic/acts_as_authentic/base.rb +16 -1
- data/lib/authlogic/acts_as_authentic/password.rb +15 -5
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +5 -3
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +21 -0
- data/lib/authlogic/controller_adapters/rails_adapter.rb +1 -1
- data/lib/authlogic/crypto_providers/md5.rb +3 -0
- data/lib/authlogic/crypto_providers/md5/v2.rb +35 -0
- data/lib/authlogic/crypto_providers/sha1.rb +3 -0
- data/lib/authlogic/crypto_providers/sha1/v2.rb +41 -0
- data/lib/authlogic/crypto_providers/sha256.rb +3 -0
- data/lib/authlogic/crypto_providers/sha256/v2.rb +58 -0
- data/lib/authlogic/crypto_providers/sha512.rb +3 -0
- data/lib/authlogic/crypto_providers/sha512/v2.rb +39 -0
- data/lib/authlogic/errors.rb +50 -0
- data/lib/authlogic/i18n/translator.rb +1 -1
- data/lib/authlogic/session/base.rb +203 -93
- 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 +58 -4
- data/lib/authlogic/test_case/mock_request.rb +10 -0
- data/lib/authlogic/test_case/rails_request_adapter.rb +7 -1
- data/lib/authlogic/version.rb +1 -1
- metadata +53 -33
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
|
@@ -3,6 +3,7 @@
|
|
3
3
|
module Authlogic
|
4
4
|
module TestCase
|
5
5
|
# A mock of `ActionDispatch::Cookies::CookieJar`.
|
6
|
+
# See action_dispatch/middleware/cookies.rb
|
6
7
|
class MockCookieJar < Hash # :nodoc:
|
7
8
|
attr_accessor :set_cookies
|
8
9
|
|
@@ -11,9 +12,12 @@ module Authlogic
|
|
11
12
|
hash && hash[:value]
|
12
13
|
end
|
13
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]"
|
14
17
|
def []=(key, options)
|
15
|
-
|
16
|
-
|
18
|
+
opt = cookie_options_to_hash(options)
|
19
|
+
(@set_cookies ||= {})[key.to_s] = opt
|
20
|
+
super(key, opt)
|
17
21
|
end
|
18
22
|
|
19
23
|
def delete(key, _options = {})
|
@@ -23,6 +27,21 @@ module Authlogic
|
|
23
27
|
def signed
|
24
28
|
@signed ||= MockSignedCookieJar.new(self)
|
25
29
|
end
|
30
|
+
|
31
|
+
def encrypted
|
32
|
+
@encrypted ||= MockEncryptedCookieJar.new(self)
|
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
|
26
45
|
end
|
27
46
|
|
28
47
|
# A mock of `ActionDispatch::Cookies::SignedKeyRotatingCookieJar`
|
@@ -35,6 +54,7 @@ module Authlogic
|
|
35
54
|
|
36
55
|
def initialize(parent_jar)
|
37
56
|
@parent_jar = parent_jar
|
57
|
+
parent_jar.each { |k, v| self[k] = v }
|
38
58
|
end
|
39
59
|
|
40
60
|
def [](val)
|
@@ -47,8 +67,42 @@ module Authlogic
|
|
47
67
|
end
|
48
68
|
|
49
69
|
def []=(key, options)
|
50
|
-
|
51
|
-
|
70
|
+
opt = cookie_options_to_hash(options)
|
71
|
+
opt[:value] = "#{opt[:value]}--#{Digest::SHA1.hexdigest opt[:value]}"
|
72
|
+
@parent_jar[key] = opt
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Which ActionDispatch class is this a mock of?
|
77
|
+
# TODO: Document as with other mocks above.
|
78
|
+
class MockEncryptedCookieJar < MockCookieJar
|
79
|
+
attr_reader :parent_jar # helper for testing
|
80
|
+
|
81
|
+
def initialize(parent_jar)
|
82
|
+
@parent_jar = parent_jar
|
83
|
+
parent_jar.each { |k, v| self[k] = v }
|
84
|
+
end
|
85
|
+
|
86
|
+
def [](val)
|
87
|
+
encrypted_message = @parent_jar[val]
|
88
|
+
if encrypted_message
|
89
|
+
self.class.decrypt(encrypted_message)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def []=(key, options)
|
94
|
+
opt = cookie_options_to_hash(options)
|
95
|
+
opt[:value] = self.class.encrypt(opt[:value])
|
96
|
+
@parent_jar[key] = opt
|
97
|
+
end
|
98
|
+
|
99
|
+
# simple caesar cipher for testing
|
100
|
+
def self.encrypt(str)
|
101
|
+
str.unpack("U*").map(&:succ).pack("U*")
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.decrypt(str)
|
105
|
+
str.unpack("U*").map(&:pred).pack("U*")
|
52
106
|
end
|
53
107
|
end
|
54
108
|
end
|
@@ -9,6 +9,16 @@ module Authlogic
|
|
9
9
|
self.controller = controller
|
10
10
|
end
|
11
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
|
+
|
12
22
|
def ip
|
13
23
|
controller&.respond_to?(:env) &&
|
14
24
|
controller.env.is_a?(Hash) &&
|
@@ -12,7 +12,7 @@ module Authlogic
|
|
12
12
|
def cookies
|
13
13
|
new_cookies = MockCookieJar.new
|
14
14
|
super.each do |key, value|
|
15
|
-
new_cookies[key] = value
|
15
|
+
new_cookies[key] = cookie_value(value)
|
16
16
|
end
|
17
17
|
new_cookies
|
18
18
|
end
|
@@ -28,6 +28,12 @@ module Authlogic
|
|
28
28
|
def request_content_type
|
29
29
|
request.format.to_s
|
30
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def cookie_value(value)
|
35
|
+
value.is_a?(Hash) ? value[:value] : value
|
36
|
+
end
|
31
37
|
end
|
32
38
|
end
|
33
39
|
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:
|
4
|
+
version: 6.4.1
|
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:
|
13
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activemodel
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '5.2'
|
22
22
|
- - "<"
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: '6.
|
24
|
+
version: '6.2'
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
version: '5.2'
|
32
32
|
- - "<"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '6.
|
34
|
+
version: '6.2'
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: activerecord
|
37
37
|
requirement: !ruby/object:Gem::Requirement
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
version: '5.2'
|
42
42
|
- - "<"
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '6.
|
44
|
+
version: '6.2'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
47
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -51,7 +51,7 @@ dependencies:
|
|
51
51
|
version: '5.2'
|
52
52
|
- - "<"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '6.
|
54
|
+
version: '6.2'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activesupport
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +61,7 @@ dependencies:
|
|
61
61
|
version: '5.2'
|
62
62
|
- - "<"
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '6.
|
64
|
+
version: '6.2'
|
65
65
|
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -71,7 +71,7 @@ dependencies:
|
|
71
71
|
version: '5.2'
|
72
72
|
- - "<"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '6.
|
74
|
+
version: '6.2'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: request_store
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,26 +86,6 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '1.0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: scrypt
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '1.2'
|
96
|
-
- - "<"
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
version: '4.0'
|
99
|
-
type: :runtime
|
100
|
-
prerelease: false
|
101
|
-
version_requirements: !ruby/object:Gem::Requirement
|
102
|
-
requirements:
|
103
|
-
- - ">="
|
104
|
-
- !ruby/object:Gem::Version
|
105
|
-
version: '1.2'
|
106
|
-
- - "<"
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
version: '4.0'
|
109
89
|
- !ruby/object:Gem::Dependency
|
110
90
|
name: bcrypt
|
111
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,20 +170,34 @@ dependencies:
|
|
190
170
|
- - "~>"
|
191
171
|
- !ruby/object:Gem::Version
|
192
172
|
version: 1.1.4
|
173
|
+
- !ruby/object:Gem::Dependency
|
174
|
+
name: rake
|
175
|
+
requirement: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - "~>"
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '13.0'
|
180
|
+
type: :development
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - "~>"
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '13.0'
|
193
187
|
- !ruby/object:Gem::Dependency
|
194
188
|
name: rubocop
|
195
189
|
requirement: !ruby/object:Gem::Requirement
|
196
190
|
requirements:
|
197
191
|
- - "~>"
|
198
192
|
- !ruby/object:Gem::Version
|
199
|
-
version: 0.
|
193
|
+
version: 0.80.1
|
200
194
|
type: :development
|
201
195
|
prerelease: false
|
202
196
|
version_requirements: !ruby/object:Gem::Requirement
|
203
197
|
requirements:
|
204
198
|
- - "~>"
|
205
199
|
- !ruby/object:Gem::Version
|
206
|
-
version: 0.
|
200
|
+
version: 0.80.1
|
207
201
|
- !ruby/object:Gem::Dependency
|
208
202
|
name: rubocop-performance
|
209
203
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,6 +212,26 @@ dependencies:
|
|
218
212
|
- - "~>"
|
219
213
|
- !ruby/object:Gem::Version
|
220
214
|
version: '1.1'
|
215
|
+
- !ruby/object:Gem::Dependency
|
216
|
+
name: scrypt
|
217
|
+
requirement: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '1.2'
|
222
|
+
- - "<"
|
223
|
+
- !ruby/object:Gem::Version
|
224
|
+
version: '4.0'
|
225
|
+
type: :development
|
226
|
+
prerelease: false
|
227
|
+
version_requirements: !ruby/object:Gem::Requirement
|
228
|
+
requirements:
|
229
|
+
- - ">="
|
230
|
+
- !ruby/object:Gem::Version
|
231
|
+
version: '1.2'
|
232
|
+
- - "<"
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: '4.0'
|
221
235
|
- !ruby/object:Gem::Dependency
|
222
236
|
name: simplecov
|
223
237
|
requirement: !ruby/object:Gem::Requirement
|
@@ -252,14 +266,14 @@ dependencies:
|
|
252
266
|
requirements:
|
253
267
|
- - "~>"
|
254
268
|
- !ruby/object:Gem::Version
|
255
|
-
version: 1.
|
269
|
+
version: 1.4.0
|
256
270
|
type: :development
|
257
271
|
prerelease: false
|
258
272
|
version_requirements: !ruby/object:Gem::Requirement
|
259
273
|
requirements:
|
260
274
|
- - "~>"
|
261
275
|
- !ruby/object:Gem::Version
|
262
|
-
version: 1.
|
276
|
+
version: 1.4.0
|
263
277
|
- !ruby/object:Gem::Dependency
|
264
278
|
name: timecop
|
265
279
|
requirement: !ruby/object:Gem::Requirement
|
@@ -305,16 +319,22 @@ files:
|
|
305
319
|
- lib/authlogic/crypto_providers.rb
|
306
320
|
- lib/authlogic/crypto_providers/bcrypt.rb
|
307
321
|
- lib/authlogic/crypto_providers/md5.rb
|
322
|
+
- lib/authlogic/crypto_providers/md5/v2.rb
|
308
323
|
- lib/authlogic/crypto_providers/scrypt.rb
|
309
324
|
- lib/authlogic/crypto_providers/sha1.rb
|
325
|
+
- lib/authlogic/crypto_providers/sha1/v2.rb
|
310
326
|
- lib/authlogic/crypto_providers/sha256.rb
|
327
|
+
- lib/authlogic/crypto_providers/sha256/v2.rb
|
311
328
|
- lib/authlogic/crypto_providers/sha512.rb
|
329
|
+
- lib/authlogic/crypto_providers/sha512/v2.rb
|
330
|
+
- lib/authlogic/errors.rb
|
312
331
|
- lib/authlogic/i18n.rb
|
313
332
|
- lib/authlogic/i18n/translator.rb
|
314
333
|
- lib/authlogic/random.rb
|
315
334
|
- lib/authlogic/session/base.rb
|
316
335
|
- lib/authlogic/session/magic_column/assigns_last_request_at.rb
|
317
336
|
- lib/authlogic/test_case.rb
|
337
|
+
- lib/authlogic/test_case/mock_api_controller.rb
|
318
338
|
- lib/authlogic/test_case/mock_controller.rb
|
319
339
|
- lib/authlogic/test_case/mock_cookie_jar.rb
|
320
340
|
- lib/authlogic/test_case/mock_logger.rb
|
@@ -333,7 +353,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
333
353
|
requirements:
|
334
354
|
- - ">="
|
335
355
|
- !ruby/object:Gem::Version
|
336
|
-
version: 2.
|
356
|
+
version: 2.4.0
|
337
357
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
338
358
|
requirements:
|
339
359
|
- - ">="
|