summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2009-02-11 19:07:18 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2009-02-11 19:07:18 +0000
commit48e26aa75b415045a6b83a37cafef478b996ca8a (patch)
tree8f974a6dece7ed0a64bb3db70997b3dfe6cdda99 /test
parent0310f43126ac8a8a7e14c8c3a09118b34ed6ff2f (diff)
downloadredmine-48e26aa75b415045a6b83a37cafef478b996ca8a.tar.gz
redmine-48e26aa75b415045a6b83a37cafef478b996ca8a.zip
Adding OpenID mock and test. #699
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2444 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test')
-rw-r--r--test/functional/account_controller_test.rb14
-rw-r--r--test/mocks/open_id_authentication_mock.rb45
-rw-r--r--test/test_helper.rb1
3 files changed, 60 insertions, 0 deletions
diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb
index 4d96a3f3b..8de6f64b5 100644
--- a/test/functional/account_controller_test.rb
+++ b/test/functional/account_controller_test.rb
@@ -64,6 +64,20 @@ class AccountControllerTest < Test::Unit::TestCase
:content => /Invalid user or password/
end
+ def test_login_with_openid
+ post :login, :openid_url => 'http://openid.example.com/good_user'
+ assert_redirected_to 'my/page'
+ end
+
+ def test_login_with_openid_with_new_user_created
+
+ end
+
+
+ def test_login_with_openid_with_new_user_with_conflict
+
+ end
+
def test_autologin
Setting.autologin = "7"
Token.delete_all
diff --git a/test/mocks/open_id_authentication_mock.rb b/test/mocks/open_id_authentication_mock.rb
new file mode 100644
index 000000000..cca1e9edb
--- /dev/null
+++ b/test/mocks/open_id_authentication_mock.rb
@@ -0,0 +1,45 @@
+# Mocks out OpenID
+#
+# http://www.northpub.com/articles/2007/04/02/testing-openid-support
+module OpenIdAuthentication
+
+ EXTENSION_FIELDS = {'email' => 'user@somedomain.com',
+ 'nickname' => 'cool_user',
+ 'country' => 'US',
+ 'postcode' => '12345',
+ 'fullname' => 'Cool User',
+ 'dob' => '1970-04-01',
+ 'language' => 'en',
+ 'timezone' => 'America/New_York'}
+
+ protected
+
+ def authenticate_with_open_id(identity_url = params[:openid_url], options = {}) #:doc:
+ if User.find_by_identity_url(identity_url) || identity_url.include?('good')
+ # Don't process registration fields unless it is requested.
+ unless identity_url.include?('blank') || (options[:required].nil? && options[:optional].nil?)
+ extension_response_fields = {}
+
+ options[:required].each do |field|
+ extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
+ end unless options[:required].nil?
+
+ options[:optional].each do |field|
+ extension_response_fields[field.to_s] = EXTENSION_FIELDS[field.to_s]
+ end unless options[:optional].nil?
+ end
+
+ yield Result[:successful], identity_url , extension_response_fields
+ else
+ logger.info "OpenID authentication failed: #{identity_url}"
+ yield Result[:failed], identity_url, nil
+ end
+ end
+
+ private
+
+ def add_simple_registration_fields(open_id_response, fields)
+ open_id_response.add_extension_arg('sreg', 'required', [ fields[:required] ].flatten * ',') if fields[:required]
+ open_id_response.add_extension_arg('sreg', 'optional', [ fields[:optional] ].flatten * ',') if fields[:optional]
+ end
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index f61b88d8c..57866d49e 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -19,6 +19,7 @@ ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
require File.expand_path(File.dirname(__FILE__) + '/helper_testcase')
+load File.join(RAILS_ROOT,'test', 'mocks', 'open_id_authentication_mock.rb')
class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method