Skip to content

Commit

Permalink
* Allow -'s in #normalize_url [Rick]
Browse files Browse the repository at this point in the history
* remove instance of mattr_accessor, it was breaking tests since they don't load ActiveSupport.  Fix Timeout test [Rick]


git-svn-id: http://svn.rubyonrails.org/rails/plugins/open_id_authentication@7162 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
rick committed Jul 6, 2007
1 parent 11c1a30 commit 424abe6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
* Allow -'s in #normalize_url [Rick]

* remove instance of mattr_accessor, it was breaking tests since they don't load ActiveSupport. Fix Timeout test [Rick]

* Throw a InvalidOpenId exception instead of just a RuntimeError when the URL can't be normalized [DHH]

* Just use the path for the return URL, so extra query parameters don't interfere [DHH]
Expand Down
11 changes: 3 additions & 8 deletions README
Expand Up @@ -91,19 +91,14 @@ app/controllers/sessions_controller.rb

def open_id_authentication
authenticate_with_open_id do |result, identity_url|
case result
when :missing
failed_login "Sorry, the OpenID server couldn't be found"
when :canceled
failed_login "OpenID verification was canceled"
when :failed
failed_login "Sorry, the OpenID verification failed"
when :successful
if result.successful?
if @current_user = @account.users.find_by_identity_url(identity_url)
successful_login
else
failed_login "Sorry, no user by that identity URL exists (#{identity_url})")
end
else
failed_login result.message
end
end
end
Expand Down
15 changes: 11 additions & 4 deletions lib/open_id_authentication.rb
@@ -1,8 +1,15 @@
module OpenIdAuthentication
OPEN_ID_AUTHENTICATION_DIR = RAILS_ROOT + "/tmp/openids"

@@store = :db
mattr_accessor :store
def self.store
@@store
end

def self.store=(value)
@@store = value
end

self.store = :db

class InvalidOpenId < StandardError
end
Expand Down Expand Up @@ -53,9 +60,9 @@ def self.normalize_url(url)
url # already normalized
when %r{^https?://[^/]+$}
url + "/"
when %r{^[.\d\w]+/.*$}
when %r{^[.\d\w-]+/.*$}
"http://" + url
when %r{^[.\d\w]+$}
when %r{^[.\d\w-]+$}
"http://" + url + "/"
else
raise InvalidOpenId.new("#{url} is not an OpenID URL")
Expand Down
4 changes: 3 additions & 1 deletion test/normalize_test.rb
Expand Up @@ -13,7 +13,9 @@ class NormalizeTest < Test::Unit::TestCase
"http://openid.aol.com/nextangler" => "http://openid.aol.com/nextangler",
"https://openid.aol.com/nextangler" => "https://openid.aol.com/nextangler",
"loudthinking.com" => "http://loudthinking.com/",
"http://loudthinking.com" => "http://loudthinking.com/"
"http://loudthinking.com" => "http://loudthinking.com/",
"techno-weenie.net" => "http://techno-weenie.net/",
"http://techno-weenie.net" => "http://techno-weenie.net/"
}

def test_normalizations
Expand Down
2 changes: 1 addition & 1 deletion test/open_id_authentication_test.rb
Expand Up @@ -28,7 +28,7 @@ def test_authentication_should_fail_when_the_identity_server_is_missing
end

def test_authentication_should_fail_when_the_identity_server_times_out
@controller.stubs(:open_id_consumer).returns(stub(:begin => Proc.new { raise Timeout::Error }))
@controller.stubs(:open_id_consumer).returns(stub(:begin => Proc.new { raise Timeout::Error, "Identity Server took too long." }))

@controller.send(:authenticate_with_open_id, "http://someone.example.com") do |result, identity_url|
assert result.missing?
Expand Down

0 comments on commit 424abe6

Please sign in to comment.