Skip to content

Commit

Permalink
Merge pull request #41280 from kentakag/fix-raw-params-method-to-not-…
Browse files Browse the repository at this point in the history
…raise-an-exception

Fix raw params method to not raise an exception

Fixes #41279.
  • Loading branch information
kamipo committed Feb 1, 2021
2 parents d5386cf + d7516f4 commit e8d7181
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Expand Up @@ -484,7 +484,7 @@ def rewrite_param_values(array_params)
def raw_params(auth)
_raw_params = auth.sub(TOKEN_REGEX, "").split(/\s*#{AUTHN_PAIR_DELIMITERS}\s*/)

if !_raw_params.first.start_with?(TOKEN_KEY)
if !_raw_params.first&.start_with?(TOKEN_KEY)
_raw_params[0] = "#{TOKEN_KEY}#{_raw_params.first}"
end

Expand Down
16 changes: 15 additions & 1 deletion actionpack/test/controller/http_token_authentication_test.rb
Expand Up @@ -155,7 +155,7 @@ def authenticate_long_credentials
assert_equal(expected, actual)
end

test "token_and_options returns correct token with nounce option" do
test "token_and_options returns correct token with nonce option" do
token = "rcHu+HzSFw89Ypyhn/896A="
nonce_hash = { nonce: "123abc" }
actual = ActionController::HttpAuthentication::Token.token_and_options(sample_request(token, nonce_hash))
Expand All @@ -177,6 +177,20 @@ def authenticate_long_credentials
assert_equal(expected, actual)
end

test "raw_params returns a tuple of key value pair strings when auth does not contain a token key" do
auth = sample_request_without_token_key("rcHu+HzSFw89Ypyhn/896A=").authorization.to_s
actual = ActionController::HttpAuthentication::Token.raw_params(auth)
expected = ["token=rcHu+HzSFw89Ypyhn/896A="]
assert_equal(expected, actual)
end

test "raw_params returns a tuple of key strings when auth does not contain a token key and value" do
auth = sample_request_without_token_key(nil).authorization.to_s
actual = ActionController::HttpAuthentication::Token.raw_params(auth)
expected = ["token="]
assert_equal(expected, actual)
end

test "token_and_options returns right token when token key is not specified in header" do
token = "rcHu+HzSFw89Ypyhn/896A="

Expand Down

0 comments on commit e8d7181

Please sign in to comment.