Raise on 404 during Webfinger
That's at least readable, return false just causes silly follow up errors
This commit is contained in:
parent
4b754b51f9
commit
5ca1c1d295
2 changed files with 10 additions and 7 deletions
|
|
@ -31,7 +31,9 @@ class Webfinger
|
||||||
Rails.logger.info("Getting: #{url} for #{account}")
|
Rails.logger.info("Getting: #{url} for #{account}")
|
||||||
begin
|
begin
|
||||||
res = Faraday.get(url)
|
res = Faraday.get(url)
|
||||||
return false if res.status == 404
|
unless res.success?
|
||||||
|
raise "Failed to fetch #{url}: #{res.status}"
|
||||||
|
end
|
||||||
res.body
|
res.body
|
||||||
rescue OpenSSL::SSL::SSLError => e
|
rescue OpenSSL::SSL::SSLError => e
|
||||||
Rails.logger.info "Failed to fetch #{url}: SSL setup invalid"
|
Rails.logger.info "Failed to fetch #{url}: SSL setup invalid"
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ describe Webfinger do
|
||||||
Webfinger.in_background(account)
|
Webfinger.in_background(account)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#fetch' do
|
describe '#fetch' do
|
||||||
it 'works' do
|
it 'works' do
|
||||||
finger = Webfinger.new(account_in_fixtures)
|
finger = Webfinger.new(account_in_fixtures)
|
||||||
|
|
@ -72,14 +72,15 @@ describe Webfinger do
|
||||||
|
|
||||||
expect(a_request(:get, redirect_url)).to have_been_made
|
expect(a_request(:get, redirect_url)).to have_been_made
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false on 404' do
|
it 'raises on 404' do
|
||||||
url ="https://bar.com/.well-known/host-meta"
|
url ="https://bar.com/.well-known/host-meta"
|
||||||
stub_request(:get, url).
|
stub_request(:get, url).
|
||||||
to_return(:status => 404, :body => nil)
|
to_return(:status => 404, :body => nil)
|
||||||
|
|
||||||
expect(finger.get(url)).not_to eq(nil)
|
expect {
|
||||||
expect(finger.get(url)).to eq(false)
|
expect(finger.get(url)).to eq(false)
|
||||||
|
}.to raise_error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -190,7 +191,7 @@ describe Webfinger do
|
||||||
expect(Person).to receive(:create_from_webfinger).with("webfinger_profile", "hcard")
|
expect(Person).to receive(:create_from_webfinger).with("webfinger_profile", "hcard")
|
||||||
finger.make_person_from_webfinger
|
finger.make_person_from_webfinger
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'with an false xrd it does not call Person.create_from_webfinger' do
|
it 'with an false xrd it does not call Person.create_from_webfinger' do
|
||||||
allow(finger).to receive(:webfinger_profile_xrd).and_return(false)
|
allow(finger).to receive(:webfinger_profile_xrd).and_return(false)
|
||||||
expect(Person).not_to receive(:create_from_webfinger)
|
expect(Person).not_to receive(:create_from_webfinger)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue