Skip to content

Commit

Permalink
Allow single component domains (such as localhost) to be recognized a…
Browse files Browse the repository at this point in the history
…s OpenID identities.
  • Loading branch information
xaviershay committed Jul 23, 2011
1 parent 60ea50e commit 4e42e43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def blank_openid_fields
end

def requires_openid_authentication?
!!self.author.try(:index, '.')
return false unless author

!!(author =~ %r{^https?://} || author.index('.'))
end

def trusted_user?
Expand Down
7 changes: 7 additions & 0 deletions spec/models/comment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def set_comment_attributes(comment, extra = {})
@comment.requires_openid_authentication?.should == true
end

it "requires OpenID authentication when the author's name starts with http" do
@comment.author = "http://localhost:9294"
@comment.requires_openid_authentication?.should == true
@comment.author = "https://localhost:9294"
@comment.requires_openid_authentication?.should == true
end

it "asks post to update it's comment counter after save" do
set_comment_attributes(@comment)
@comment.blank_openid_fields
Expand Down

0 comments on commit 4e42e43

Please sign in to comment.