Skip to content

Commit

Permalink
Merge 063a379 into 4624e84
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw- committed Dec 21, 2020
2 parents 4624e84 + 063a379 commit 093b555
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/authlogic/test_case/mock_cookie_jar.rb
Expand Up @@ -12,6 +12,7 @@ def [](key)
end

def []=(key, options)
options = { value: options } unless options.is_a?(Hash)
(@set_cookies ||= {})[key.to_s] = options
super
end
Expand Down Expand Up @@ -52,6 +53,7 @@ def [](val)
end

def []=(key, options)
options = { value: options } unless options.is_a?(Hash)
options[:value] = "#{options[:value]}--#{Digest::SHA1.hexdigest options[:value]}"
@parent_jar[key] = options
end
Expand All @@ -75,6 +77,7 @@ def [](val)
end

def []=(key, options)
options = { value: options } unless options.is_a?(Hash)
options[:value] = self.class.encrypt(options[:value])
@parent_jar[key] = options
end
Expand Down
8 changes: 7 additions & 1 deletion lib/authlogic/test_case/rails_request_adapter.rb
Expand Up @@ -12,7 +12,7 @@ def authenticate_with_http_basic(&block)
def cookies
new_cookies = MockCookieJar.new
super.each do |key, value|
new_cookies[key] = value[:value]
new_cookies[key] = cookie_value(value)
end
new_cookies
end
Expand All @@ -28,6 +28,12 @@ def request
def request_content_type
request.format.to_s
end

private

def cookie_value(value)
value.is_a?(Hash) ? value[:value] : value
end
end
end
end
21 changes: 21 additions & 0 deletions test/adapter_test.rb
Expand Up @@ -30,5 +30,26 @@ def test_api_controller
assert_nil adapter.cookies
end
end

class RailsRequestAdapterTest < ActiveSupport::TestCase
def test_adapter_with_string_cookie
controller = MockController.new
controller.cookies["foo"] = "bar"
adapter = Authlogic::TestCase::RailsRequestAdapter.new(controller)

assert adapter.cookies
end

def test_adapter_with_hash_cookie
controller = MockController.new
controller.cookies["foo"] = {
value: "bar",
expires: nil
}
adapter = Authlogic::TestCase::RailsRequestAdapter.new(controller)

assert adapter.cookies
end
end
end
end
22 changes: 22 additions & 0 deletions test/session_test/cookies_test.rb
Expand Up @@ -245,6 +245,28 @@ def test_after_destroy_destroy_cookie
assert session.destroy
refute controller.cookies["user_credentials"]
end

def test_string_cookie
payload = "bar"
controller.cookies["foo"] = payload
assert_equal(payload, controller.cookies["foo"])
end

def test_string_cookie_signed
payload = "bar"
session = UserSession.new
session.sign_cookie = true
controller.cookies["foo"] = payload
assert_equal(payload, controller.cookies.signed["foo"])
end

def test_string_cookie_encrypted
payload = "bar"
session = UserSession.new
session.encrypt_cookie = true
controller.cookies["foo"] = payload
assert_equal(payload, controller.cookies.encrypted["foo"])
end
end
end
end

0 comments on commit 093b555

Please sign in to comment.