diff --git a/lib/em-webfinger.rb b/lib/em-webfinger.rb index 67b4dee52..1224e8868 100644 --- a/lib/em-webfinger.rb +++ b/lib/em-webfinger.rb @@ -27,11 +27,19 @@ class EMWebfinger end private + def get_xrd http = EventMachine::HttpRequest.new(xrd_url).get :timeout => TIMEOUT http.callback { - get_webfinger_profile(webfinger_profile_url(http.response)) } - http.errback { process_callbacks "there was an error getting the xrd at #{xrd_url}" } + profile_url = webfinger_profile_url(http.response) + if profile_url + get_webfinger_profile(profile_url) + else + process_callbacks "webfinger does not seem to be enabled for #{@account}" + end + } + + http.errback { process_callbacks "there was an error getting the xrd from account#{@account}" } end @@ -73,6 +81,7 @@ class EMWebfinger def webfinger_profile_url(xrd_response) doc = Nokogiri::XML::Document.parse(xrd_response) + return nil if doc.namespaces["xmlns"] != "http://docs.oasis-open.org/ns/xri/xrd-1.0" swizzle doc.at('Link[rel=lrdd]').attribute('template').value end diff --git a/spec/lib/em-webfinger_spec.rb b/spec/lib/em-webfinger_spec.rb index 7ad6ad2db..b7c8bf9a5 100644 --- a/spec/lib/em-webfinger_spec.rb +++ b/spec/lib/em-webfinger_spec.rb @@ -38,7 +38,7 @@ describe EMWebfinger do it 'should raise an error on an unresonable email' do proc{ - EMWebfinger.new("joe.valid+email@my-address.com") + EMWebfinger.new("joe.valid.email@my-address.com") }.should_not raise_error(RuntimeError, "Identifier is invalid") end @@ -62,14 +62,14 @@ describe EMWebfinger do it 'should not blow up if the returned xrd is nil' do http = FakeHttpRequest.new(:success) + fake_account = 'foo@example.com' http.callbacks = [''] EventMachine::HttpRequest.should_receive(:new).and_return(http) n = EMWebfinger.new("foo@example.com") n.on_person{|person| - person = "sad" + person.should == "webfinger does not seem to be enabled for #{fake_account}" } - end end end @@ -85,6 +85,14 @@ describe EMWebfinger do it 'should parse out the webfinger template' do finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}" end + + it 'should return nil if not an xrd' do + finger.send(:webfinger_profile_url, '').should be nil + end + + it 'should return the template for xrd' do + finger.send(:webfinger_profile_url, diaspora_xrd).should == 'http://tom.joindiaspora.com/webfinger/?q=foo@tom.joindiaspora.com' + end end describe '#xrd_url' do diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 1ff2012e8..f0068a32c 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -123,7 +123,8 @@ describe User do remote_person.delete user3.delete - Person.should_receive(:by_webfinger).twice.and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save + #stubs async webfinger + Person.should_receive(:by_account_identifier).twice.and_return{ |handle| if handle == user.person.diaspora_handle; user.person.save user.person; else; remote_person.save; remote_person; end }