Raise on 404 during Webfinger

That's at least readable, return false just causes
silly follow up errors
This commit is contained in:
Jonne Haß 2014-09-20 13:47:52 +02:00
parent 4b754b51f9
commit 5ca1c1d295
2 changed files with 10 additions and 7 deletions

View file

@ -31,7 +31,9 @@ class Webfinger
Rails.logger.info("Getting: #{url} for #{account}")
begin
res = Faraday.get(url)
return false if res.status == 404
unless res.success?
raise "Failed to fetch #{url}: #{res.status}"
end
res.body
rescue OpenSSL::SSL::SSLError => e
Rails.logger.info "Failed to fetch #{url}: SSL setup invalid"

View file

@ -36,7 +36,7 @@ describe Webfinger do
Webfinger.in_background(account)
end
end
describe '#fetch' do
it 'works' do
finger = Webfinger.new(account_in_fixtures)
@ -72,14 +72,15 @@ describe Webfinger do
expect(a_request(:get, redirect_url)).to have_been_made
end
it 'returns false on 404' do
it 'raises on 404' do
url ="https://bar.com/.well-known/host-meta"
stub_request(:get, url).
to_return(:status => 404, :body => nil)
expect(finger.get(url)).not_to eq(nil)
expect(finger.get(url)).to eq(false)
expect {
expect(finger.get(url)).to eq(false)
}.to raise_error
end
end
@ -190,7 +191,7 @@ describe Webfinger do
expect(Person).to 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
allow(finger).to receive(:webfinger_profile_xrd).and_return(false)
expect(Person).not_to receive(:create_from_webfinger)