Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/connection_tester_spec.rb')
-rw-r--r--spec/lib/connection_tester_spec.rb87
1 files changed, 65 insertions, 22 deletions
diff --git a/spec/lib/connection_tester_spec.rb b/spec/lib/connection_tester_spec.rb
index 01acd20f4..d665dd717 100644
--- a/spec/lib/connection_tester_spec.rb
+++ b/spec/lib/connection_tester_spec.rb
@@ -47,9 +47,8 @@ describe ConnectionTester do
end
describe "#request" do
- it "performs a successful GET request on '/' and '/.well-known/host-meta'" do
+ it "performs a successful GET request on '/'" do
stub_request(:get, url).to_return(status: 200, body: "Hello World!")
- stub_request(:get, "#{url}/.well-known/host-meta").to_return(status: 200, body: "host-meta")
tester.request
expect(result.rt).to be > -1
@@ -60,27 +59,22 @@ describe ConnectionTester do
it "receives a 'normal' 301 redirect" do
stub_request(:get, url).to_return(status: 301, headers: {"Location" => "#{url}/redirect"})
stub_request(:get, "#{url}/redirect").to_return(status: 200, body: "Hello World!")
- stub_request(:get, "#{url}/.well-known/host-meta").to_return(status: 200, body: "host-meta")
tester.request
end
it "updates ssl after https redirect" do
tester = ConnectionTester.new("http://pod.example.com/", result)
- stub_request(:get, "http://pod.example.com/").to_return(status: 200, body: "Hello World!")
- stub_request(:get, "http://pod.example.com/.well-known/host-meta")
- .to_return(status: 301, headers: {"Location" => "#{url}/.well-known/host-meta"})
- stub_request(:get, "#{url}/.well-known/host-meta").to_return(status: 200, body: "host-meta")
+ stub_request(:get, "http://pod.example.com/").to_return(status: 301, headers: {"Location" => url})
+ stub_request(:get, url).to_return(status: 200, body: "Hello World!")
tester.request
expect(result.ssl).to be_truthy
end
- it "rejects other hostname after redirect redirect" do
- stub_request(:get, url).to_return(status: 200, body: "Hello World!")
- stub_request(:get, "#{url}/.well-known/host-meta")
- .to_return(status: 301, headers: {"Location" => "https://example.com/.well-known/host-meta"})
- stub_request(:get, "https://example.com/.well-known/host-meta").to_return(status: 200, body: "host-meta")
+ it "rejects other hostname after redirect" do
+ stub_request(:get, url).to_return(status: 301, headers: {"Location" => "https://example.com/"})
+ stub_request(:get, "https://example.com/").to_return(status: 200, body: "Hello World!")
expect { tester.request }.to raise_error(ConnectionTester::HTTPFailure)
end
@@ -100,6 +94,11 @@ describe ConnectionTester do
expect { tester.request }.to raise_error(ConnectionTester::HTTPFailure)
end
+ it "receives a 502 bad gateway" do
+ stub_request(:get, url).to_return(status: 502, body: "Bad Gateway!")
+ expect { tester.request }.to raise_error(ConnectionTester::HTTPFailure)
+ end
+
it "cannot connect" do
stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Error!"))
expect { tester.request }.to raise_error(ConnectionTester::NetFailure)
@@ -112,48 +111,92 @@ describe ConnectionTester do
end
describe "#nodeinfo" do
- let(:ni_wellknown) { {links: [{rel: ConnectionTester::NODEINFO_SCHEMA, href: "/nodeinfo"}]} }
-
- it "reads the version from the nodeinfo document" do
- ni_document = NodeInfo.build do |doc|
- doc.version = "1.0"
+ def build_ni_document(version)
+ NodeInfo.build do |doc|
+ doc.version = version
doc.open_registrations = true
doc.protocols.protocols << "diaspora"
doc.software.name = "diaspora"
doc.software.version = "a.b.c.d"
end
+ end
+
+ NodeInfo::VERSIONS.each do |version|
+ context "with version #{version}" do
+ let(:ni_wellknown) {
+ {links: [{rel: "http://nodeinfo.diaspora.software/ns/schema/#{version}", href: "/nodeinfo/#{version}"}]}
+ }
+
+ it "reads the version from the nodeinfo document" do
+ ni_document = build_ni_document(version)
+
+ stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
+ .to_return(status: 200, body: JSON.generate(ni_wellknown))
+ stub_request(:get, "#{url}/nodeinfo/#{version}")
+ .to_return(status: 200, body: JSON.generate(ni_document.as_json))
+
+ tester.nodeinfo
+ expect(result.software_version).to eq("diaspora a.b.c.d")
+ end
+ end
+ end
+
+ it "uses the latest commonly supported version" do
+ ni_wellknown = {links: [
+ {rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"},
+ {rel: "http://nodeinfo.diaspora.software/ns/schema/1.1", href: "/nodeinfo/1.1"},
+ {rel: "http://nodeinfo.diaspora.software/ns/schema/2.0", href: "/nodeinfo/2.0"},
+ {rel: "http://nodeinfo.diaspora.software/ns/schema/9.0", href: "/nodeinfo/9.0"}
+ ]}
+
+ ni_document = build_ni_document("2.0")
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
.to_return(status: 200, body: JSON.generate(ni_wellknown))
- stub_request(:get, "#{url}/nodeinfo").to_return(status: 200, body: JSON.generate(ni_document.as_json))
+ stub_request(:get, "#{url}/nodeinfo/2.0").to_return(status: 200, body: JSON.generate(ni_document.as_json))
tester.nodeinfo
expect(result.software_version).to eq("diaspora a.b.c.d")
end
- it "handles a missing nodeinfo document gracefully" do
+ it "handles no common version gracefully" do
+ ni_wellknown = {links: [{rel: "http://nodeinfo.diaspora.software/ns/schema/1.1", href: "/nodeinfo/1.1"}]}
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
- .to_return(status: 404, body: "Not Found")
+ .to_return(status: 200, body: JSON.generate(ni_wellknown))
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
end
+ it "fails the nodeinfo document is missing" do
+ stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}").to_return(status: 404, body: "Not Found")
+ expect { tester.nodeinfo }.to raise_error(ConnectionTester::HTTPFailure)
+ end
+
it "handles a malformed document gracefully" do
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
.to_return(status: 200, body: '{"json"::::"malformed"}')
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
end
+ it "handles timeout gracefully" do
+ ni_wellknown = {links: [{rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}]}
+ stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
+ .to_return(status: 200, body: JSON.generate(ni_wellknown))
+ stub_request(:get, "#{url}/nodeinfo/1.0").to_raise(Faraday::TimeoutError.new)
+ expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
+ end
+
it "handles a invalid jrd document gracefully" do
- invalid_wellknown = {links: {rel: ConnectionTester::NODEINFO_SCHEMA, href: "/nodeinfo"}}
+ invalid_wellknown = {links: {rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}}
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
+ ni_wellknown = {links: [{rel: "http://nodeinfo.diaspora.software/ns/schema/1.0", href: "/nodeinfo/1.0"}]}
stub_request(:get, "#{url}#{ConnectionTester::NODEINFO_FRAGMENT}")
.to_return(status: 200, body: JSON.generate(ni_wellknown))
- stub_request(:get, "#{url}/nodeinfo").to_return(status: 200, body: '{"software": "invalid nodeinfo"}')
+ stub_request(:get, "#{url}/nodeinfo/1.0").to_return(status: 200, body: '{"software": "invalid nodeinfo"}')
expect { tester.nodeinfo }.to raise_error(ConnectionTester::NodeInfoFailure)
end
end