Namespace
Methods
S
T
Constants
SALT = 'b3c631c314c0bbca50c1b2843150fe33'
 
Instance Public methods
setup()
# File actionpack/test/dispatch/cookies_test.rb, line 281
def setup
  super

  @request.env["action_dispatch.key_generator"] = ActiveSupport::KeyGenerator.new(SALT, iterations: 2)

  @request.env["action_dispatch.signed_cookie_salt"] =
    @request.env["action_dispatch.encrypted_cookie_salt"] =
    @request.env["action_dispatch.encrypted_signed_cookie_salt"] = SALT

  @request.host = "www.nextangle.com"
end
test_can_set_request_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 1141
def test_can_set_request_cookies
  @request.cookies['user_name'] = 'david'
  get :noop
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]

  get :noop
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]

  @request.cookies[:user_name] = 'andrew'
  get :noop
  assert_equal 'andrew', cookies['user_name']
  assert_equal 'andrew', cookies[:user_name]
end
test_cookies_can_be_cleared()
# File actionpack/test/dispatch/cookies_test.rb, line 1113
def test_cookies_can_be_cleared
  get :symbol_key
  assert_equal "david", cookies[:user_name]

  cookies.clear
  get :noop
  assert_nil cookies[:user_name]

  get :symbol_key
  assert_equal "david", cookies[:user_name]
end
test_cookies_hash_is_indifferent_access()
# File actionpack/test/dispatch/cookies_test.rb, line 1078
def test_cookies_hash_is_indifferent_access
  get :symbol_key
  assert_equal "david", cookies[:user_name]
  assert_equal "david", cookies['user_name']
  get :string_key
  assert_equal "dhh", cookies[:user_name]
  assert_equal "dhh", cookies['user_name']
end
test_cookies_persist_throughout_request()
# File actionpack/test/dispatch/cookies_test.rb, line 400
def test_cookies_persist_throughout_request
  response = get :authenticate
  assert_match(/user_name=david/, response.headers["Set-Cookie"])
end
test_cookies_precedence_over_request_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 1168
def test_cookies_precedence_over_request_cookies
  @request.cookies['user_name'] = 'andrew'
  get :authenticate
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]

  get :noop
  assert_equal 'david', cookies['user_name']
  assert_equal 'david', cookies[:user_name]
end
test_cookies_retained_across_requests()
# File actionpack/test/dispatch/cookies_test.rb, line 1099
def test_cookies_retained_across_requests
  get :symbol_key
  assert_cookie_header "user_name=david; path=/"
  assert_equal "david", cookies[:user_name]

  get :noop
  assert !@response.headers.include?("Set-Cookie")
  assert_equal "david", cookies[:user_name]

  get :noop
  assert !@response.headers.include?("Set-Cookie")
  assert_equal "david", cookies[:user_name]
end
test_multiple_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 357
def test_multiple_cookies
  get :set_multiple_cookies
  assert_equal 2, @response.cookies.size
  assert_cookie_header "user_name=david; path=/; expires=Mon, 10 Oct 2005 05:00:00 -0000\nlogin=XJ-122; path=/"
  assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies)
end
test_raise_data_overflow()
# File actionpack/test/dispatch/cookies_test.rb, line 662
def test_raise_data_overflow
  assert_raise(ActionDispatch::Cookies::CookieOverflow) do
    get :raise_data_overflow
  end
end
test_raises_argument_error_if_missing_secret()
# File actionpack/test/dispatch/cookies_test.rb, line 684
def test_raises_argument_error_if_missing_secret
  assert_raise(ArgumentError, nil.inspect) {
    @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new(nil)
    get :set_signed_cookie
  }

  assert_raise(ArgumentError, ''.inspect) {
    @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new("")
    get :set_signed_cookie
  }
end
test_raises_argument_error_if_secret_is_probably_insecure()
# File actionpack/test/dispatch/cookies_test.rb, line 696
def test_raises_argument_error_if_secret_is_probably_insecure
  assert_raise(ArgumentError, "password".inspect) {
    @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new("password")
    get :set_signed_cookie
  }

  assert_raise(ArgumentError, "secret".inspect) {
    @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new("secret")
    get :set_signed_cookie
  }

  assert_raise(ArgumentError, "12345678901234567890123456789".inspect) {
    @request.env["action_dispatch.key_generator"] = ActiveSupport::LegacyKeyGenerator.new("12345678901234567890123456789")
    get :set_signed_cookie
  }
end
test_setting_request_cookies_is_indifferent_access()
# File actionpack/test/dispatch/cookies_test.rb, line 1087
def test_setting_request_cookies_is_indifferent_access
  cookies.clear
  cookies[:user_name] = "andrew"
  get :string_key_mock
  assert_equal "david", cookies['user_name']

  cookies.clear
  cookies['user_name'] = "andrew"
  get :symbol_key_mock
  assert_equal "david", cookies[:user_name]
end
test_setting_with_escapable_characters()
# File actionpack/test/dispatch/cookies_test.rb, line 311
def test_setting_with_escapable_characters
  get :set_with_with_escapable_characters
  assert_cookie_header "that+%26+guy=foo+%26+bar+%3D%3E+baz; path=/"
  assert_equal({"that & guy" => "foo & bar => baz"}, @response.cookies)
end
test_tampered_cookies()
# File actionpack/test/dispatch/cookies_test.rb, line 668
def test_tampered_cookies
  assert_nothing_raised do
    get :tampered_cookies
    assert_response :success
  end
end