Skip to content
Extraits de code Groupes Projets
Valider 9cb80383 rédigé par Jonne Haß's avatar Jonne Haß
Parcourir les fichiers

improve webfinger failure handling

* do not raise if profile xrd isn't found
* error out on a ssl error rather than on the unexpected nil value later
* be more verbose about failed xrd fetches
parent 0f15c3e0
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -28,8 +28,13 @@ class Webfinger
def get(url)
Rails.logger.info("Getting: #{url} for #{account}")
begin
Faraday.get(url).body
begin
res = Faraday.get(url)
return false if res.status == 404
res.body
rescue OpenSSL::SSL::SSLError => e
Rails.logger.info "Failed to fetch #{url}: SSL setup invalid"
raise e
rescue => e
Rails.logger.info("Failed to fetch: #{url} for #{account}; #{e.message}")
raise e
......@@ -51,7 +56,7 @@ class Webfinger
else
person = make_person_from_webfinger
end
FEDERATION_LOGGER.info("successfully webfingered#{@account}")
FEDERATION_LOGGER.info("successfully webfingered#{@account}") if person
person
end
......@@ -64,7 +69,7 @@ class Webfinger
self.ssl = false
retry
else
raise I18n.t('webfinger.xrd_fetch_failed', :account => account)
raise "there was an error getting the xrd from account #{@account}: #{e.message}"
end
end
end
......@@ -90,6 +95,8 @@ class Webfinger
def webfinger_profile_xrd
@webfinger_profile_xrd ||= get(webfinger_profile_url)
FEDERATION_LOGGER.info "#{@account} doesn't exists anymore" if @webfinger_profile_xrd == false
@webfinger_profile_xrd
end
def hcard_xrd
......@@ -97,7 +104,7 @@ class Webfinger
end
def make_person_from_webfinger
Person.create_from_webfinger(webfinger_profile, hcard)
Person.create_from_webfinger(webfinger_profile, hcard) unless webfinger_profile_xrd == false
end
def host_meta_url
......
......@@ -20,7 +20,7 @@ class WebfingerProfile
doc.remove_namespaces!
account_string = doc.css('Subject').text.gsub('acct:', '').strip
raise "account in profile(#{account_string}) and account requested (#{@account}) do not match" if account_string != @account
doc.css('Link').each do |l|
......
......@@ -72,6 +72,15 @@ describe Webfinger do
a_request(:get, redirect_url).should have_been_made
end
it 'returns false on 404' do
url ="https://bar.com/.well-known/host-meta"
stub_request(:get, url).
to_return(:status => 404, :body => nil)
finger.get(url).should_not == nil
finger.get(url).should == false
end
end
describe 'existing_person_with_profile?' do
......@@ -176,10 +185,17 @@ describe Webfinger do
describe '#make_person_from_webfinger' do
it 'with an hcard and a webfinger_profile, it calls Person.create_from_webfinger' do
finger.stub(:hcard).and_return("hcard")
finger.stub(:webfinger_profile_xrd).and_return("webfinger_profile_xrd")
finger.stub(:webfinger_profile).and_return("webfinger_profile")
Person.should_receive(:create_from_webfinger).with("webfinger_profile", "hcard")
finger.make_person_from_webfinger
end
it 'with an false xrd it does not call Person.create_from_webfinger' do
finger.stub(:webfinger_profile_xrd).and_return(false)
Person.should_not_receive(:create_from_webfinger)
finger.make_person_from_webfinger
end
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter