From 60dc3572713d21b3292f7d81a6f264178291d265 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 12 Feb 2009 04:31:28 +0000 Subject: [PATCH] Normalize the identity_url when it's set. OpenId uses a specific format for the url it uses which requires the protocol and trailing slash. This change will normalize the value to when a user sets it. #699 git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2453 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/user.rb | 9 +++++++++ test/unit/user_test.rb | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index b35c1a815..4f8223dc0 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -80,6 +80,15 @@ class User < ActiveRecord::Base super end + def identity_url=(url) + begin + self.write_attribute(:identity_url, OpenIdAuthentication.normalize_identifier(url)) + rescue InvalidOpenId + # Invlaid url, don't save + end + self.read_attribute(:identity_url) + end + # Returns the user that matches provided login and password, or nil def self.try_to_login(login, password) # Make sure no one can sign in with an empty password diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 54f15b69f..515927ff2 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -184,4 +184,23 @@ class UserTest < Test::Unit::TestCase assert !u.password.blank? assert !u.password_confirmation.blank? end + + def test_setting_identity_url + normalized_open_id_url = 'http://example.com/' + u = User.new( :identity_url => 'http://example.com/' ) + assert_equal normalized_open_id_url, u.identity_url + end + + def test_setting_identity_url_without_trailing_slash + normalized_open_id_url = 'http://example.com/' + u = User.new( :identity_url => 'http://example.com' ) + assert_equal normalized_open_id_url, u.identity_url + end + + def test_setting_identity_url_without_protocol + normalized_open_id_url = 'http://example.com/' + u = User.new( :identity_url => 'example.com' ) + assert_equal normalized_open_id_url, u.identity_url + end + end -- 2.39.5