IZ MS webfinger now trys ssl first, then http
This commit is contained in:
parent
449a6f3ea0
commit
af3247b62f
2 changed files with 51 additions and 14 deletions
|
|
@ -6,6 +6,7 @@ class EMWebfinger
|
||||||
def initialize(account)
|
def initialize(account)
|
||||||
@account = account.strip.gsub('acct:','').to_s
|
@account = account.strip.gsub('acct:','').to_s
|
||||||
@callbacks = []
|
@callbacks = []
|
||||||
|
@ssl = true
|
||||||
# Raise an error if identifier has a port number
|
# Raise an error if identifier has a port number
|
||||||
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
raise "Identifier is invalid" if(@account.strip.match(/\:\d+$/))
|
||||||
# Raise an error if identifier is not a valid email (generous regexp)
|
# Raise an error if identifier is not a valid email (generous regexp)
|
||||||
|
|
@ -34,6 +35,9 @@ class EMWebfinger
|
||||||
profile_url = webfinger_profile_url(http.response)
|
profile_url = webfinger_profile_url(http.response)
|
||||||
if profile_url
|
if profile_url
|
||||||
get_webfinger_profile(profile_url)
|
get_webfinger_profile(profile_url)
|
||||||
|
elsif @ssl
|
||||||
|
@ssl = false
|
||||||
|
get_xrd
|
||||||
else
|
else
|
||||||
process_callbacks "webfinger does not seem to be enabled for #{@account}'s host"
|
process_callbacks "webfinger does not seem to be enabled for #{@account}'s host"
|
||||||
end
|
end
|
||||||
|
|
@ -73,25 +77,18 @@ class EMWebfinger
|
||||||
##helpers
|
##helpers
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_nil_response(html)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def webfinger_profile_url(xrd_response)
|
def webfinger_profile_url(xrd_response)
|
||||||
doc = Nokogiri::XML::Document.parse(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"
|
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
|
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
|
||||||
end
|
end
|
||||||
|
|
||||||
def xrd_url(ssl = false)
|
def xrd_url
|
||||||
domain = @account.split('@')[1]
|
domain = @account.split('@')[1]
|
||||||
"http#{'s' if ssl}://#{domain}/.well-known/host-meta"
|
"http#{'s' if @ssl}://#{domain}/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
def swizzle(template)
|
def swizzle(template)
|
||||||
template.gsub '{uri}', @account
|
template.gsub '{uri}', @account
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,11 @@ describe EMWebfinger do
|
||||||
EMWebfinger.new('eviljoe@diaspora.local:3000')
|
EMWebfinger.new('eviljoe@diaspora.local:3000')
|
||||||
}.should raise_error(RuntimeError, "Identifier is invalid")
|
}.should raise_error(RuntimeError, "Identifier is invalid")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should set ssl as the default' do
|
||||||
|
foo = EMWebfinger.new(account)
|
||||||
|
foo.instance_variable_get(:@ssl).should be true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -94,14 +99,14 @@ describe EMWebfinger do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#xrd_url' do
|
describe '#xrd_url' do
|
||||||
it 'should return canonical host-meta url' do
|
it 'should return canonical host-meta url for http' do
|
||||||
|
finger.instance_variable_set(:@ssl, false)
|
||||||
finger.send(:xrd_url).should == "http://tom.joindiaspora.com/.well-known/host-meta"
|
finger.send(:xrd_url).should == "http://tom.joindiaspora.com/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'can return the https version' do
|
it 'can return the https version' do
|
||||||
finger.send(:xrd_url, true).should == "https://tom.joindiaspora.com/.well-known/host-meta"
|
finger.send(:xrd_url).should == "https://tom.joindiaspora.com/.well-known/host-meta"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -127,9 +132,44 @@ describe EMWebfinger do
|
||||||
|
|
||||||
EM.run {
|
EM.run {
|
||||||
f.on_person{ |p|
|
f.on_person{ |p|
|
||||||
p.valid?.should be true
|
p.valid?.should be true
|
||||||
EM.stop
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue