Browse Source

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
tags/0.9.0
Eric Davis 15 years ago
parent
commit
60dc357271
2 changed files with 28 additions and 0 deletions
  1. 9
    0
      app/models/user.rb
  2. 19
    0
      test/unit/user_test.rb

+ 9
- 0
app/models/user.rb View File

@@ -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

+ 19
- 0
test/unit/user_test.rb View File

@@ -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

Loading…
Cancel
Save