Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Clean up previous commit: Use normalize_identifier, clean whitespace …

…up and fix broken test.
  • Loading branch information...
commit 10764ad81e90a805f00d848c71aca8440212aef0 1 parent 13248aa
Joshua Peek josh authored

Showing 2 changed files with 18 additions and 19 deletions. Show diff stats Hide diff stats

  1. +15 16 lib/open_id_authentication.rb
  2. +3 3 test/normalize_test.rb
31 lib/open_id_authentication.rb
@@ -71,43 +71,42 @@ def message
71 71 end
72 72
73 73 # normalizes an OpenID according to http://openid.net/specs/openid-authentication-2_0.html#normalization
74   - def self.normalize( open_id )
  74 + def self.normalize_identifier(identifier)
75 75 # clean up whitespace
76   - open_id = open_id.to_s.strip
77   -
  76 + identifier = identifier.to_s.strip
  77 +
78 78 # if an XRI has a prefix, strip it.
79   - open_id.gsub!(/xri:\/\//i, '')
80   -
  79 + identifier.gsub!(/xri:\/\//i, '')
  80 +
81 81 # dodge XRIs -- TODO: validate, don't just skip.
82   - unless ['=', '@', '+', '$', '!', '('].include? open_id[0].chr
83   -
  82 + unless ['=', '@', '+', '$', '!', '('].include?(identifier.at(0))
84 83 # does it begin with http? if not, add it.
85   - open_id = "http://#{open_id}" unless open_id =~ /^http/i
  84 + identifier = "http://#{identifier}" unless identifier =~ /^http/i
86 85
87 86 # strip any fragments
88   - open_id.gsub!(/\#(.*)$/, '')
  87 + identifier.gsub!(/\#(.*)$/, '')
89 88
90 89 begin
91   - uri = URI.parse(open_id)
  90 + uri = URI.parse(identifier)
92 91 uri.scheme = uri.scheme.downcase # URI should do this
93   - open_id = uri.normalize.to_s
  92 + identifier = uri.normalize.to_s
94 93 rescue URI::InvalidURIError
95   - raise InvalidOpenId.new("#{url} is not an OpenID URL")
  94 + raise InvalidOpenId.new("#{identifier} is not an OpenID identifier")
96 95 end
97   -
98 96 end
99 97
100   - return open_id
  98 + return identifier
101 99 end
102 100
103 101 # deprecated for OpenID 2.0, where not all OpenIDs are URLs
104 102 def self.normalize_url(url)
105   - self.normalize( url )
  103 + ActiveSupport::Deprecation.warn "normalize_identifier has been deprecated, use normalize instead"
  104 + self.normalize_identifier(url)
106 105 end
107 106
108 107 protected
109 108 def normalize_url(url)
110   - OpenIdAuthentication.normalize_url(url)
  109 + OpenIdAuthentication.normalize_identifier(url)
111 110 end
112 111
113 112 # The parameter name of "openid_identifier" is used rather than the Rails convention "open_id_identifier"
6 test/normalize_test.rb
@@ -16,7 +16,8 @@ class NormalizeTest < Test::Unit::TestCase
16 16 "http://loudthinking.com:8080" => "http://loudthinking.com:8080/",
17 17 "techno-weenie.net" => "http://techno-weenie.net/",
18 18 "http://techno-weenie.net" => "http://techno-weenie.net/",
19   - "http://techno-weenie.net " => "http://techno-weenie.net/"
  19 + "http://techno-weenie.net " => "http://techno-weenie.net/",
  20 + "=name" => "=name"
20 21 }
21 22
22 23 def test_normalizations
@@ -24,9 +25,8 @@ def test_normalizations
24 25 assert_equal to, normalize_url(from)
25 26 end
26 27 end
27   -
  28 +
28 29 def test_broken_open_id
29 30 assert_raises(InvalidOpenId) { normalize_url(nil) }
30   - assert_raises(InvalidOpenId) { normalize_url("=name") }
31 31 end
32 32 end

0 comments on commit 10764ad

Please sign in to comment.
Something went wrong with that request. Please try again.