From 6720fa2c598f26932fc62a607259f4e79175e262 Mon Sep 17 00:00:00 2001 From: maxwell Date: Fri, 22 Oct 2010 16:28:03 -0700 Subject: [PATCH] added tests to make sure Person.by_webfinger only returns exact matches --- app/models/person.rb | 2 +- spec/models/person_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/person.rb b/app/models/person.rb index 211d3fcf0..5a1486653 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 4aae4daad..6bfff0788 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -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 {