diff --git a/lib/em-webfinger.rb b/lib/em-webfinger.rb index 97b31184c704c26e73d55ab0de258bb996da26a5..f5c4c6148611699500134c182ede0013e85ef948 100644 --- a/lib/em-webfinger.rb +++ b/lib/em-webfinger.rb @@ -6,7 +6,6 @@ class EMWebfinger def initialize(account) @account = account.strip.gsub('acct:','').to_s @callbacks = [] - @ssl = true # Raise an error if identifier has a port number raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/)) # Raise an error if identifier is not a valid email (generous regexp) @@ -35,9 +34,6 @@ class EMWebfinger profile_url = webfinger_profile_url(http.response) if profile_url get_webfinger_profile(profile_url) - elsif @ssl - @ssl = false - get_xrd else process_callbacks "webfinger does not seem to be enabled for #{@account}'s host" end @@ -77,18 +73,25 @@ class EMWebfinger ##helpers private + def check_nil_response(html) + + end + + + 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 - def xrd_url + def xrd_url(ssl = false) domain = @account.split('@')[1] - "http#{'s' if @ssl}://#{domain}/.well-known/host-meta" + "http#{'s' if ssl}://#{domain}/.well-known/host-meta" end def swizzle(template) template.gsub '{uri}', @account end + end diff --git a/spec/lib/em-webfinger_spec.rb b/spec/lib/em-webfinger_spec.rb index eb88684a4478ed64d077ef8b690f1a5632a179ef..9c6d384a2e7dc8f01a5edbcc5fe61cdbf474970c 100644 --- a/spec/lib/em-webfinger_spec.rb +++ b/spec/lib/em-webfinger_spec.rb @@ -47,11 +47,6 @@ describe EMWebfinger do EMWebfinger.new('eviljoe@diaspora.local:3000') }.should raise_error(RuntimeError, "Identifier is invalid") end - - it 'should set ssl as the default' do - foo = EMWebfinger.new(account) - foo.instance_variable_get(:@ssl).should be true - end end @@ -99,14 +94,14 @@ describe EMWebfinger do end describe '#xrd_url' do - it 'should return canonical host-meta url for http' do - finger.instance_variable_set(:@ssl, false) + it 'should return canonical host-meta url' do finger.send(:xrd_url).should == "http://tom.joindiaspora.com/.well-known/host-meta" end it 'can return the https version' do - finger.send(:xrd_url).should == "https://tom.joindiaspora.com/.well-known/host-meta" + finger.send(:xrd_url, true).should == "https://tom.joindiaspora.com/.well-known/host-meta" end + end end @@ -132,44 +127,9 @@ describe EMWebfinger do EM.run { f.on_person{ |p| - p.valid?.should be true - EM.stop - } - } - end - - it 'should retry with http if https fails' do - good_request.callbacks = [nil, diaspora_xrd, diaspora_finger, hcard_xml] - - #new_person = Factory.build(:person, :diaspora_handle => "tom@tom.joindiaspora.com") - # http://tom.joindiaspora.com/.well-known/host-meta - f = EMWebfinger.new("tom@tom.joindiaspora.com") - - EventMachine::HttpRequest.should_receive(:new).exactly(4).times.and_return(good_request) - - f.should_receive(:xrd_url).twice - - EM.run { - f.on_person{ |p| - EM.stop - } + p.valid?.should be true + EM.stop } - end - - - it 'must try https first' do - single_request = FakeHttpRequest.new(:success) - single_request.callbacks = [diaspora_xrd] - good_request.callbacks = [diaspora_finger, hcard_xml] - EventMachine::HttpRequest.should_receive(:new).with("https://tom.joindiaspora.com/.well-known/host-meta").and_return(single_request) - EventMachine::HttpRequest.should_receive(:new).exactly(2).and_return(good_request) - - f = EMWebfinger.new("tom@tom.joindiaspora.com") - - EM.run { - f.on_person{ |p| - EM.stop - } } end end