Fixed: User#identity_url raises an error when invalid url is supplied (#2742).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2476 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2009-02-15 18:46:50 +00:00
parent 3183445aea
commit d643d9a94c
2 changed files with 19 additions and 4 deletions

View File

@ -81,10 +81,14 @@ class User < ActiveRecord::Base
end
def identity_url=(url)
begin
self.write_attribute(:identity_url, OpenIdAuthentication.normalize_identifier(url))
rescue InvalidOpenId
# Invlaid url, don't save
if url.blank?
write_attribute(:identity_url, '')
else
begin
write_attribute(:identity_url, OpenIdAuthentication.normalize_identifier(url))
rescue OpenIdAuthentication::InvalidOpenId
# Invlaid url, don't save
end
end
self.read_attribute(:identity_url)
end

View File

@ -204,6 +204,17 @@ class UserTest < Test::Unit::TestCase
u = User.new( :identity_url => 'example.com' )
assert_equal normalized_open_id_url, u.identity_url
end
def test_setting_blank_identity_url
u = User.new( :identity_url => 'example.com' )
u.identity_url = ''
assert u.identity_url.blank?
end
def test_setting_invalid_identity_url
u = User.new( :identity_url => 'this is not an openid url' )
assert u.identity_url.blank?
end
else
puts "Skipping openid tests."