aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/middleware/cookies.rb66
-rw-r--r--actionpack/test/controller/render_test.rb3
2 files changed, 59 insertions, 10 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb
index 2f148752cb..121a11c8e1 100644
--- a/actionpack/lib/action_dispatch/middleware/cookies.rb
+++ b/actionpack/lib/action_dispatch/middleware/cookies.rb
@@ -87,6 +87,9 @@ module ActionDispatch
ENCRYPTED_SIGNED_COOKIE_SALT = "action_dispatch.encrypted_signed_cookie_salt".freeze
TOKEN_KEY = "action_dispatch.secret_token".freeze
+ # Cookies can typically store 4096 bytes.
+ MAX_COOKIE_SIZE = 4096
+
# Raised when storing more than 4K of session data.
CookieOverflow = Class.new StandardError
@@ -293,13 +296,17 @@ module ActionDispatch
end
end
- class PermanentCookieJar < CookieJar #:nodoc:
+ class PermanentCookieJar #:nodoc:
def initialize(parent_jar, key_generator, options = {})
@parent_jar = parent_jar
@key_generator = key_generator
@options = options
end
+ def [](key)
+ @parent_jar[name.to_s]
+ end
+
def []=(key, options)
if options.is_a?(Hash)
options.symbolize_keys!
@@ -311,14 +318,25 @@ module ActionDispatch
@parent_jar[key] = options
end
+ def permanent
+ @permanent ||= PermanentCookieJar.new(self, @key_generator, @options)
+ end
+
+ def signed
+ @signed ||= SignedCookieJar.new(self, @key_generator, @options)
+ end
+
+ def encrypted
+ @encrypted ||= EncryptedCookieJar.new(self, @key_generator, @options)
+ end
+
def method_missing(method, *arguments, &block)
- @parent_jar.send(method, *arguments, &block)
+ ActiveSupport::Deprecation.warn "#{method} is deprecated with no replacement. " +
+ "You probably want to try this method over the parent CookieJar."
end
end
- class SignedCookieJar < CookieJar #:nodoc:
- MAX_COOKIE_SIZE = 4096 # Cookies can typically store 4096 bytes.
-
+ class SignedCookieJar #:nodoc:
def initialize(parent_jar, key_generator, options = {})
@parent_jar = parent_jar
@options = options
@@ -346,12 +364,25 @@ module ActionDispatch
@parent_jar[key] = options
end
+ def permanent
+ @permanent ||= PermanentCookieJar.new(self, @key_generator, @options)
+ end
+
+ def signed
+ @signed ||= SignedCookieJar.new(self, @key_generator, @options)
+ end
+
+ def encrypted
+ @encrypted ||= EncryptedCookieJar.new(self, @key_generator, @options)
+ end
+
def method_missing(method, *arguments, &block)
- @parent_jar.send(method, *arguments, &block)
+ ActiveSupport::Deprecation.warn "#{method} is deprecated with no replacement. " +
+ "You probably want to try this method over the parent CookieJar."
end
end
- class EncryptedCookieJar < SignedCookieJar #:nodoc:
+ class EncryptedCookieJar #:nodoc:
def initialize(parent_jar, key_generator, options = {})
if ActiveSupport::DummyKeyGenerator === key_generator
raise "Encrypted Cookies must be used in conjunction with config.secret_key_base." +
@@ -365,8 +396,8 @@ module ActionDispatch
@encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret)
end
- def [](name)
- if encrypted_message = @parent_jar[name]
+ def [](key)
+ if encrypted_message = @parent_jar[key]
@encryptor.decrypt_and_verify(encrypted_message)
end
rescue ActiveSupport::MessageVerifier::InvalidSignature,
@@ -385,6 +416,23 @@ module ActionDispatch
raise CookieOverflow if options[:value].size > MAX_COOKIE_SIZE
@parent_jar[key] = options
end
+
+ def permanent
+ @permanent ||= PermanentCookieJar.new(self, @key_generator, @options)
+ end
+
+ def signed
+ @signed ||= SignedCookieJar.new(self, @key_generator, @options)
+ end
+
+ def encrypted
+ @encrypted ||= EncryptedCookieJar.new(self, @key_generator, @options)
+ end
+
+ def method_missing(method, *arguments, &block)
+ ActiveSupport::Deprecation.warn "#{method} is deprecated with no replacement. " +
+ "You probably want to try this method over the parent CookieJar."
+ end
end
def initialize(app)
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index b5b5eadd7b..c7a66f4298 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -1444,10 +1444,11 @@ class RenderTest < ActionController::TestCase
end
def test_locals_option_to_assert_template_is_not_supported
+ get :partial_collection_with_locals
+
warning_buffer = StringIO.new
$stderr = warning_buffer
- get :partial_collection_with_locals
assert_template partial: 'customer_greeting', locals: { greeting: 'Bonjour' }
assert_equal "the :locals option to #assert_template is only supported in a ActionView::TestCase\n", warning_buffer.string
ensure