tests are green
This commit is contained in:
parent
7c32649df4
commit
39f66cc5d9
3 changed files with 24 additions and 6 deletions
|
|
@ -27,11 +27,19 @@ class EMWebfinger
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def get_xrd
|
def get_xrd
|
||||||
http = EventMachine::HttpRequest.new(xrd_url).get :timeout => TIMEOUT
|
http = EventMachine::HttpRequest.new(xrd_url).get :timeout => TIMEOUT
|
||||||
http.callback {
|
http.callback {
|
||||||
get_webfinger_profile(webfinger_profile_url(http.response)) }
|
profile_url = webfinger_profile_url(http.response)
|
||||||
http.errback { process_callbacks "there was an error getting the xrd at #{xrd_url}" }
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -73,6 +81,7 @@ class EMWebfinger
|
||||||
|
|
||||||
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"
|
||||||
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
|
swizzle doc.at('Link[rel=lrdd]').attribute('template').value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ describe EMWebfinger do
|
||||||
|
|
||||||
it 'should raise an error on an unresonable email' do
|
it 'should raise an error on an unresonable email' do
|
||||||
proc{
|
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")
|
}.should_not raise_error(RuntimeError, "Identifier is invalid")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -62,14 +62,14 @@ describe EMWebfinger do
|
||||||
|
|
||||||
it 'should not blow up if the returned xrd is nil' do
|
it 'should not blow up if the returned xrd is nil' do
|
||||||
http = FakeHttpRequest.new(:success)
|
http = FakeHttpRequest.new(:success)
|
||||||
|
fake_account = 'foo@example.com'
|
||||||
http.callbacks = ['']
|
http.callbacks = ['']
|
||||||
EventMachine::HttpRequest.should_receive(:new).and_return(http)
|
EventMachine::HttpRequest.should_receive(:new).and_return(http)
|
||||||
n = EMWebfinger.new("foo@example.com")
|
n = EMWebfinger.new("foo@example.com")
|
||||||
|
|
||||||
n.on_person{|person|
|
n.on_person{|person|
|
||||||
person = "sad"
|
person.should == "webfinger does not seem to be enabled for #{fake_account}"
|
||||||
}
|
}
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -85,6 +85,14 @@ describe EMWebfinger do
|
||||||
it 'should parse out the webfinger template' do
|
it 'should parse out the webfinger template' do
|
||||||
finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}"
|
finger.send(:webfinger_profile_url, diaspora_xrd).should == "http://tom.joindiaspora.com/webfinger/?q=#{account}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should return nil if not an xrd' do
|
||||||
|
finger.send(:webfinger_profile_url, '<html></html>').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
|
end
|
||||||
|
|
||||||
describe '#xrd_url' do
|
describe '#xrd_url' do
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,8 @@ describe User do
|
||||||
remote_person.delete
|
remote_person.delete
|
||||||
user3.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 }
|
user.person; else; remote_person.save; remote_person; end }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue