aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-04 14:02:21 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-07-04 14:02:21 -0300
commit2fd8dd7feb27908d29ec57f8c5826bb95c3bd899 (patch)
tree0317aa1792cdbae1a8a9473423d17b5be4a02655 /actionpack/test/controller
parent42de6200eb48f93fc6504003b4693703b6b3a825 (diff)
parentb39a344426fd1a471baf436612a6b38d317babd4 (diff)
downloadrails-2fd8dd7feb27908d29ec57f8c5826bb95c3bd899.tar.gz
rails-2fd8dd7feb27908d29ec57f8c5826bb95c3bd899.tar.bz2
rails-2fd8dd7feb27908d29ec57f8c5826bb95c3bd899.zip
Merge pull request #16011 from xjlu/token_and_options
Improve token_and_options regex and test
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/http_token_authentication_test.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/actionpack/test/controller/http_token_authentication_test.rb b/actionpack/test/controller/http_token_authentication_test.rb
index ef90fff178..8c6c8a0aa7 100644
--- a/actionpack/test/controller/http_token_authentication_test.rb
+++ b/actionpack/test/controller/http_token_authentication_test.rb
@@ -139,16 +139,36 @@ class HttpTokenAuthenticationTest < ActionController::TestCase
assert_equal(expected, actual)
end
+ test "token_and_options returns correct token with nounce option" do
+ token = "rcHu+HzSFw89Ypyhn/896A="
+ nonce_hash = {nonce: "123abc"}
+ actual = ActionController::HttpAuthentication::Token.token_and_options(sample_request(token, nonce_hash))
+ expected_token = token
+ expected_nonce = {"nonce" => nonce_hash[:nonce]}
+ assert_equal(expected_token, actual.first)
+ assert_equal(expected_nonce, actual.last)
+ end
+
test "token_and_options returns nil with no value after the equal sign" do
actual = ActionController::HttpAuthentication::Token.token_and_options(malformed_request).first
expected = nil
assert_equal(expected, actual)
end
+ test "raw_params returns a tuple of two key value pair strings" do
+ auth = sample_request("rcHu+HzSFw89Ypyhn/896A=").authorization.to_s
+ actual = ActionController::HttpAuthentication::Token.raw_params(auth)
+ expected = ["token=\"rcHu+HzSFw89Ypyhn/896A=\"", "nonce=\"def\""]
+ assert_equal(expected, actual)
+ end
+
private
- def sample_request(token)
- @sample_request ||= OpenStruct.new authorization: %{Token token="#{token}", nonce="def"}
+ def sample_request(token, options = {nonce: "def"})
+ authorization = options.inject([%{Token token="#{token}"}]) do |arr, (k, v)|
+ arr << "#{k}=\"#{v}\""
+ end.join(", ")
+ @sample_request ||= OpenStruct.new authorization: authorization
end
def malformed_request