summaryrefslogtreecommitdiffstats
path: root/test/test_helper.rb
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-11-05 16:29:56 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-11-05 16:29:56 +0000
commit4b1dd334a596abcb52306a5e90a5d8009c83ac2c (patch)
tree647ebd0ea7e3fca0f901b0be24e77a3e4818d19b /test/test_helper.rb
parentc967899b145619080197d32d801f99484b485ed7 (diff)
downloadredmine-4b1dd334a596abcb52306a5e90a5d8009c83ac2c.tar.gz
redmine-4b1dd334a596abcb52306a5e90a5d8009c83ac2c.zip
Allow key authentication when creating issues (with tests) #6447
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4365 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/test_helper.rb')
-rw-r--r--test/test_helper.rb57
1 files changed, 42 insertions, 15 deletions
diff --git a/test/test_helper.rb b/test/test_helper.rb
index e956cdce5..09e600f27 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -195,10 +195,13 @@ class ActiveSupport::TestCase
# @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
# @param [String] url the request url
# @param [optional, Hash] parameters additional request parameters
- def self.should_allow_api_authentication(http_method, url, parameters={})
- should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters)
- should_allow_http_basic_auth_with_key(http_method, url, parameters)
- should_allow_key_based_auth(http_method, url, parameters)
+ # @param [optional, Hash] options additional options
+ # @option options [Symbol] :success_code Successful response code (:success)
+ # @option options [Symbol] :failure_code Failure response code (:unauthorized)
+ def self.should_allow_api_authentication(http_method, url, parameters={}, options={})
+ should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters, options)
+ should_allow_http_basic_auth_with_key(http_method, url, parameters, options)
+ should_allow_key_based_auth(http_method, url, parameters, options)
end
# Test that a request allows the username and password for HTTP BASIC
@@ -206,7 +209,13 @@ class ActiveSupport::TestCase
# @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
# @param [String] url the request url
# @param [optional, Hash] parameters additional request parameters
- def self.should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters={})
+ # @param [optional, Hash] options additional options
+ # @option options [Symbol] :success_code Successful response code (:success)
+ # @option options [Symbol] :failure_code Failure response code (:unauthorized)
+ def self.should_allow_http_basic_auth_with_username_and_password(http_method, url, parameters={}, options={})
+ success_code = options[:success_code] || :success
+ failure_code = options[:failure_code] || :unauthorized
+
context "should allow http basic auth using a username and password for #{http_method} #{url}" do
context "with a valid HTTP authentication" do
setup do
@@ -215,7 +224,7 @@ class ActiveSupport::TestCase
send(http_method, url, parameters, {:authorization => @authorization})
end
- should_respond_with :success
+ should_respond_with success_code
should_respond_with_content_type_based_on_url(url)
should "login as the user" do
assert_equal @user, User.current
@@ -229,7 +238,7 @@ class ActiveSupport::TestCase
send(http_method, url, parameters, {:authorization => @authorization})
end
- should_respond_with :unauthorized
+ should_respond_with failure_code
should_respond_with_content_type_based_on_url(url)
should "not login as the user" do
assert_equal User.anonymous, User.current
@@ -241,7 +250,7 @@ class ActiveSupport::TestCase
send(http_method, url, parameters, {:authorization => ''})
end
- should_respond_with :unauthorized
+ should_respond_with failure_code
should_respond_with_content_type_based_on_url(url)
should "include_www_authenticate_header" do
assert @controller.response.headers.has_key?('WWW-Authenticate')
@@ -256,7 +265,13 @@ class ActiveSupport::TestCase
# @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
# @param [String] url the request url
# @param [optional, Hash] parameters additional request parameters
- def self.should_allow_http_basic_auth_with_key(http_method, url, parameters={})
+ # @param [optional, Hash] options additional options
+ # @option options [Symbol] :success_code Successful response code (:success)
+ # @option options [Symbol] :failure_code Failure response code (:unauthorized)
+ def self.should_allow_http_basic_auth_with_key(http_method, url, parameters={}, options={})
+ success_code = options[:success_code] || :success
+ failure_code = options[:failure_code] || :unauthorized
+
context "should allow http basic auth with a key for #{http_method} #{url}" do
context "with a valid HTTP authentication using the API token" do
setup do
@@ -266,7 +281,7 @@ class ActiveSupport::TestCase
send(http_method, url, parameters, {:authorization => @authorization})
end
- should_respond_with :success
+ should_respond_with success_code
should_respond_with_content_type_based_on_url(url)
should_be_a_valid_response_string_based_on_url(url)
should "login as the user" do
@@ -282,7 +297,7 @@ class ActiveSupport::TestCase
send(http_method, url, parameters, {:authorization => @authorization})
end
- should_respond_with :unauthorized
+ should_respond_with failure_code
should_respond_with_content_type_based_on_url(url)
should "not login as the user" do
assert_equal User.anonymous, User.current
@@ -296,7 +311,13 @@ class ActiveSupport::TestCase
# @param [Symbol] http_method the HTTP method for request (:get, :post, :put, :delete)
# @param [String] url the request url, without the key=ZXY parameter
# @param [optional, Hash] parameters additional request parameters
- def self.should_allow_key_based_auth(http_method, url, parameters={})
+ # @param [optional, Hash] options additional options
+ # @option options [Symbol] :success_code Successful response code (:success)
+ # @option options [Symbol] :failure_code Failure response code (:unauthorized)
+ def self.should_allow_key_based_auth(http_method, url, parameters={}, options={})
+ success_code = options[:success_code] || :success
+ failure_code = options[:failure_code] || :unauthorized
+
context "should allow key based auth using key=X for #{http_method} #{url}" do
context "with a valid api token" do
setup do
@@ -311,7 +332,7 @@ class ActiveSupport::TestCase
send(http_method, request_url, parameters)
end
- should_respond_with :success
+ should_respond_with success_code
should_respond_with_content_type_based_on_url(url)
should_be_a_valid_response_string_based_on_url(url)
should "login as the user" do
@@ -323,10 +344,16 @@ class ActiveSupport::TestCase
setup do
@user = User.generate_with_protected!
@token = Token.generate!(:user => @user, :action => 'feeds')
- send(http_method, url + "?key=#{@token.value}")
+ # Simple url parse to add on ?key= or &key=
+ request_url = if url.match(/\?/)
+ url + "&key=#{@token.value}"
+ else
+ url + "?key=#{@token.value}"
+ end
+ send(http_method, request_url, parameters)
end
- should_respond_with :unauthorized
+ should_respond_with failure_code
should_respond_with_content_type_based_on_url(url)
should "not login as the user" do
assert_equal User.anonymous, User.current