mirror of https://github.com/rails/rails
parent
f6918a5b5d
commit
24472e01c1
|
@ -30,16 +30,23 @@ module ActionCable
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class TestCookies < ActiveSupport::HashWithIndifferentAccess
|
||||||
|
def []=(name, options)
|
||||||
|
value = options.is_a?(Hash) ? options.symbolize_keys[:value] : options
|
||||||
|
super(name, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# We don't want to use the whole "encryption stack" for connection unit-tests,
|
# We don't want to use the whole "encryption stack" for connection unit-tests,
|
||||||
# but we want to make sure that users test against the correct types of cookies
|
# but we want to make sure that users test against the correct types of cookies
|
||||||
# (i.e. signed or encrypted or plain)
|
# (i.e. signed or encrypted or plain)
|
||||||
class TestCookieJar < ActiveSupport::HashWithIndifferentAccess
|
class TestCookieJar < TestCookies
|
||||||
def signed
|
def signed
|
||||||
self[:signed] ||= {}.with_indifferent_access
|
@signed ||= TestCookies.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def encrypted
|
def encrypted
|
||||||
self[:encrypted] ||= {}.with_indifferent_access
|
@encrypted ||= TestCookies.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,14 @@ class ConnectionSimpleTest < ActionCable::Connection::TestCase
|
||||||
assert_equal "456", connection.user_id
|
assert_equal "456", connection.user_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_plain_cookie_with_explicit_value_and_string_key
|
||||||
|
cookies["user_id"] = { "value" => "456" }
|
||||||
|
|
||||||
|
connect
|
||||||
|
|
||||||
|
assert_equal "456", connection.user_id
|
||||||
|
end
|
||||||
|
|
||||||
def test_disconnect
|
def test_disconnect
|
||||||
cookies["user_id"] = "456"
|
cookies["user_id"] = "456"
|
||||||
|
|
||||||
|
@ -133,6 +141,14 @@ class EncryptedCookiesConnectionTest < ActionCable::Connection::TestCase
|
||||||
assert_equal "456", connection.user_id
|
assert_equal "456", connection.user_id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_connected_with_encrypted_cookies_with_explicit_value_and_symbol_key
|
||||||
|
cookies.encrypted["user_id"] = { value: "456" }
|
||||||
|
|
||||||
|
connect
|
||||||
|
|
||||||
|
assert_equal "456", connection.user_id
|
||||||
|
end
|
||||||
|
|
||||||
def test_connection_rejected
|
def test_connection_rejected
|
||||||
assert_reject_connection { connect }
|
assert_reject_connection { connect }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue