Skip to content
Snippets Groups Projects
Commit 6720fa2c authored by maxwell's avatar maxwell
Browse files

added tests to make sure Person.by_webfinger only returns exact matches

parent c0423e5e
No related branches found
No related tags found
No related merge requests found
......@@ -97,7 +97,7 @@ class Person
# Raise an error if identifier is not a valid email (generous regexp)
raise "Identifier is invalid" if !(identifier =~ /\A.*\@.*\..*\Z/)
query = /#{Regexp.escape(identifier.gsub('acct:', '').to_s)}/i
query = /\A^#{Regexp.escape(identifier.gsub('acct:', '').to_s)}\z/i
local_person = Person.first(:diaspora_handle => query)
if local_person
......
......@@ -187,6 +187,25 @@ describe Person do
end
end
it 'should only find people who are exact matches' do
user = Factory(:user, :username => "SaMaNtHa")
person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com")
user.person.diaspora_handle = "tom@tom.joindiaspora.com"
user.person.save
Person.by_webfinger("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com"
end
it 'should return nil if there is not an exact match' do
Redfinger.stub!(:finger).and_return(nil)
Person.stub!(:from_webfinger_profile).and_return(false)
person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com")
#Person.by_webfinger("tom@tom.joindiaspora.com").should_be false
proc{ Person.by_webfinger("tom@tom.joindiaspora.com")}.should raise_error
end
it 'identifier should be a valid email' do
stub_success("joe.valid+email@my-address.com")
Proc.new {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment