Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clean up previous commit: Use normalize_identifier, clean whitespace …

…up and fix broken test.
  • Loading branch information...
commit 10764ad81e90a805f00d848c71aca8440212aef0 1 parent 13248aa
@josh josh authored
Showing with 18 additions and 19 deletions.
  1. +15 −16 lib/open_id_authentication.rb
  2. +3 −3 test/normalize_test.rb
View
31 lib/open_id_authentication.rb
@@ -71,43 +71,42 @@ def message
end
# normalizes an OpenID according to http://openid.net/specs/openid-authentication-2_0.html#normalization
- def self.normalize( open_id )
+ def self.normalize_identifier(identifier)
# clean up whitespace
- open_id = open_id.to_s.strip
-
+ identifier = identifier.to_s.strip
+
# if an XRI has a prefix, strip it.
- open_id.gsub!(/xri:\/\//i, '')
-
+ identifier.gsub!(/xri:\/\//i, '')
+
# dodge XRIs -- TODO: validate, don't just skip.
- unless ['=', '@', '+', '$', '!', '('].include? open_id[0].chr
-
+ unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0))
# does it begin with http? if not, add it.
- open_id = "http://#{open_id}" unless open_id =~ /^http/i
+ identifier = "http://#{identifier}" unless identifier =~ /^http/i
# strip any fragments
- open_id.gsub!(/\#(.*)$/, '')
+ identifier.gsub!(/\#(.*)$/, '')
begin
- uri = URI.parse(open_id)
+ uri = URI.parse(identifier)
uri.scheme = uri.scheme.downcase # URI should do this
- open_id = uri.normalize.to_s
+ identifier = uri.normalize.to_s
rescue URI::InvalidURIError
- raise InvalidOpenId.new("#{url} is not an OpenID URL")
+ raise InvalidOpenId.new("#{identifier} is not an OpenID identifier")
end
-
end
- return open_id
+ return identifier
end
# deprecated for OpenID 2.0, where not all OpenIDs are URLs
def self.normalize_url(url)
- self.normalize( url )
+ ActiveSupport::Deprecation.warn "normalize_identifier has been deprecated, use normalize instead"
+ self.normalize_identifier(url)
end
protected
def normalize_url(url)
- OpenIdAuthentication.normalize_url(url)
+ OpenIdAuthentication.normalize_identifier(url)
end
# The parameter name of "openid_identifier" is used rather than the Rails convention "open_id_identifier"
View
6 test/normalize_test.rb
@@ -16,7 +16,8 @@ class NormalizeTest < Test::Unit::TestCase
"http://loudthinking.com:8080" => "http://loudthinking.com:8080/",
"techno-weenie.net" => "http://techno-weenie.net/",
"http://techno-weenie.net" => "http://techno-weenie.net/",
- "http://techno-weenie.net " => "http://techno-weenie.net/"
+ "http://techno-weenie.net " => "http://techno-weenie.net/",
+ "=name" => "=name"
}
def test_normalizations
@@ -24,9 +25,8 @@ def test_normalizations
assert_equal to, normalize_url(from)
end
end
-
+
def test_broken_open_id
assert_raises(InvalidOpenId) { normalize_url(nil) }
- assert_raises(InvalidOpenId) { normalize_url("=name") }
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.