From 9a2e3ef158a2d9e3eb040524da6be02108fb31cc Mon Sep 17 00:00:00 2001 From: maxwell <maxwell@joindiaspora.com> Date: Sun, 24 Oct 2010 18:48:45 -0700 Subject: [PATCH] making a few more cleanup and tests --- lib/em-webfinger.rb | 5 +---- spec/lib/em-webfinger_spec.rb | 13 ++++++++++--- spec/models/person_spec.rb | 33 +++++---------------------------- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/lib/em-webfinger.rb b/lib/em-webfinger.rb index 234d54d3b3..6b3d823262 100644 --- a/lib/em-webfinger.rb +++ b/lib/em-webfinger.rb @@ -4,7 +4,7 @@ require File.join(Rails.root, 'lib/webfinger_profile') class EMWebfinger TIMEOUT = 5 def initialize(account) - @account = account + @account = account.strip.gsub('acct:','').to_s @callbacks = [] # Raise an error if identifier has a port number raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/)) @@ -14,9 +14,6 @@ class EMWebfinger def fetch raise 'you need to set a callback before calling fetch' if @callbacks.empty? - query = /\A^#{Regexp.escape(@account.gsub('acct:', '').to_s)}\z/i - local_person = Person.first(:diaspora_handle => query) - person = Person.by_account_identifier(@account) if person process_callbacks person diff --git a/spec/lib/em-webfinger_spec.rb b/spec/lib/em-webfinger_spec.rb index 62afc74c35..76496e38dd 100644 --- a/spec/lib/em-webfinger_spec.rb +++ b/spec/lib/em-webfinger_spec.rb @@ -28,7 +28,6 @@ describe EMWebfinger do let(:non_diaspora_hcard) {File.open(File.join(Rails.root, 'spec/fixtures/evan_hcard')).read} context 'setup' do - let(:action){ Proc.new{|person| puts person.inspect }} describe '#intialize' do it 'sets account ' do @@ -37,8 +36,17 @@ describe EMWebfinger do end it 'should raise an error on an unresonable email' do - proc{EMWebfinger.new("asfadfasdf")}.should raise_error + proc{ + EMWebfinger.new("joe.valid+email@my-address.com") + }.should_not raise_error(RuntimeError, "Identifier is invalid") + end + + it 'should not allow port numbers' do + proc{ + EMWebfinger.new('eviljoe@diaspora.local:3000') + }.should raise_error(RuntimeError, "Identifier is invalid") + end end describe '#on_person' do @@ -104,7 +112,6 @@ describe EMWebfinger do } } end - end end end diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index d6390e41c3..b2bfa0ab0a 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -199,7 +199,7 @@ describe Person do person.should == user1.person end - it 'should only find people who are exact matches' do + it 'should only find people who are exact matches (1/2)' do user = Factory(:user, :username => "SaMaNtHa") person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") user.person.diaspora_handle = "tom@tom.joindiaspora.com" @@ -207,37 +207,14 @@ describe Person do Person.by_account_identifier("tom@tom.joindiaspora.com").diaspora_handle.should == "tom@tom.joindiaspora.com" end - it 'should return nil if there is not an exact match' do - pending "should check in the webfinger client" + it 'should only find people who are exact matches (2/2)' do person = Factory(:person, :diaspora_handle => "tomtom@tom.joindiaspora.com") person1 = Factory(:person, :diaspora_handle => "tom@tom.joindiaspora.comm") - #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 - pending "should check in the webfinger client" - stub_success("joe.valid+email@my-address.com") - Proc.new { - Person.by_account_identifier("joe.valid+email@my-address.com") - }.should_not raise_error(RuntimeError, "Identifier is invalid") - - stub_success("not_a_@valid_email") - Proc.new { - Person.by_account_identifer("not_a_@valid_email") - }.should raise_error(RuntimeError, "Identifier is invalid") - - end - - it 'should not accept a port number' do - pending "should check the webfinger client" - stub_success("eviljoe@diaspora.local:3000") - Proc.new { - Person.by_account_identifier('eviljoe@diaspora.local:3000') - }.should raise_error(RuntimeError, "Identifier is invalid") + f = Person.by_account_identifier("tom@tom.joindiaspora.com") + f.should be nil end + end describe '.local_by_account_identifier' do -- GitLab