check if links is an array in the JRD
This commit is contained in:
parent
2a0e87957f
commit
c0ab42fecc
2 changed files with 13 additions and 2 deletions
|
|
@ -129,6 +129,8 @@ class ConnectionTester
|
||||||
nd_resp = http.get(find_nodeinfo_url(ni_resp.body))
|
nd_resp = http.get(find_nodeinfo_url(ni_resp.body))
|
||||||
find_software_version(nd_resp.body)
|
find_software_version(nd_resp.body)
|
||||||
end
|
end
|
||||||
|
rescue NodeInfoFailure => e
|
||||||
|
raise e
|
||||||
rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError => e
|
rescue JSON::Schema::ValidationError, JSON::Schema::SchemaError => e
|
||||||
raise NodeInfoFailure, "#{e.class}: #{e.message}"
|
raise NodeInfoFailure, "#{e.class}: #{e.message}"
|
||||||
rescue Faraday::ResourceNotFound, JSON::JSONError => e
|
rescue Faraday::ResourceNotFound, JSON::JSONError => e
|
||||||
|
|
@ -183,8 +185,10 @@ class ConnectionTester
|
||||||
|
|
||||||
# walk the JSON document, get the actual document location
|
# walk the JSON document, get the actual document location
|
||||||
def find_nodeinfo_url(body)
|
def find_nodeinfo_url(body)
|
||||||
links = JSON.parse(body)
|
jrd = JSON.parse(body)
|
||||||
links.fetch("links").find { |entry|
|
links = jrd.fetch("links")
|
||||||
|
raise NodeInfoFailure, "invalid JRD: '#/links' is not an array!" unless links.is_a?(Array)
|
||||||
|
links.find { |entry|
|
||||||
entry.fetch("rel") == NODEINFO_SCHEMA
|
entry.fetch("rel") == NODEINFO_SCHEMA
|
||||||
}.fetch("href")
|
}.fetch("href")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,13 @@ describe ConnectionTester do
|
||||||
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
|
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles a invalid jrd document gracefully" do
|
||||||
|
invalid_wellknown = {links: {rel: ConnectionTester::NODEINFO_SCHEMA, href: "/nodeinfo"}}
|
||||||
|
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
|
||||||
|
.to_return(status: 200, body: JSON.generate(invalid_wellknown))
|
||||||
|
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
|
||||||
|
end
|
||||||
|
|
||||||
it "handles a invalid nodeinfo document gracefully" do
|
it "handles a invalid nodeinfo document gracefully" do
|
||||||
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
|
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
|
||||||
.to_return(status: 200, body: JSON.generate(ni_wellknown))
|
.to_return(status: 200, body: JSON.generate(ni_wellknown))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue