specs refactoring
This commit is contained in:
parent
749999a377
commit
762233e48f
6 changed files with 102 additions and 82 deletions
|
|
@ -2,7 +2,7 @@ module DiasporaFederation
|
||||||
describe ReceiveController, type: :controller do
|
describe ReceiveController, type: :controller do
|
||||||
routes { DiasporaFederation::Engine.routes }
|
routes { DiasporaFederation::Engine.routes }
|
||||||
|
|
||||||
describe "#public" do
|
describe "POST #public" do
|
||||||
it "succeeds" do
|
it "succeeds" do
|
||||||
post :public, xml: "<diaspora/>"
|
post :public, xml: "<diaspora/>"
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
@ -14,7 +14,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#private" do
|
describe "POST #private" do
|
||||||
it "succeeds" do
|
it "succeeds" do
|
||||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ module DiasporaFederation
|
||||||
describe WebfingerController, type: :controller do
|
describe WebfingerController, type: :controller do
|
||||||
routes { DiasporaFederation::Engine.routes }
|
routes { DiasporaFederation::Engine.routes }
|
||||||
|
|
||||||
describe "#host_meta" do
|
describe "GET #host_meta" do
|
||||||
before do
|
before do
|
||||||
DiasporaFederation.server_uri = URI("http://localhost:3000/")
|
DiasporaFederation.server_uri = URI("http://localhost:3000/")
|
||||||
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
|
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
|
||||||
|
|
@ -35,7 +35,7 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#legacy_webfinger" do
|
describe "GET #legacy_webfinger" do
|
||||||
it "succeeds when the person exists" do
|
it "succeeds when the person exists" do
|
||||||
get :legacy_webfinger, "q" => "alice@localhost:3000"
|
get :legacy_webfinger, "q" => "alice@localhost:3000"
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
it "must not create blank instances" do
|
it "must not create blank instances" do
|
||||||
expect { WebFinger::HCard.new }.to raise_error(NameError)
|
expect { WebFinger::HCard.new }.to raise_error NameError
|
||||||
end
|
end
|
||||||
|
|
||||||
context "generation" do
|
context "generation" do
|
||||||
|
|
@ -127,15 +127,15 @@ HTML
|
||||||
guid: guid,
|
guid: guid,
|
||||||
diaspora_handle: handle
|
diaspora_handle: handle
|
||||||
)
|
)
|
||||||
}.to raise_error(WebFinger::InvalidData)
|
}.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if nothing was given" do
|
it "fails if nothing was given" do
|
||||||
expect { WebFinger::HCard.from_profile({}) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::HCard.from_profile({}) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if nil was given" do
|
it "fails if nil was given" do
|
||||||
expect { WebFinger::HCard.from_profile(nil) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::HCard.from_profile(nil) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -239,11 +239,11 @@ HTML
|
||||||
<span class="fn">#{name}</span>
|
<span class="fn">#{name}</span>
|
||||||
</div>
|
</div>
|
||||||
HTML
|
HTML
|
||||||
expect { WebFinger::HCard.from_html(invalid_html) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::HCard.from_html(invalid_html) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if the document is not HTML" do
|
it "fails if the document is not HTML" do
|
||||||
expect { WebFinger::HCard.from_html("") }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::HCard.from_html("") }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe WebFinger::HostMeta do
|
describe WebFinger::HostMeta do
|
||||||
base_url = "https://pod.example.tld/"
|
let(:base_url) { "https://pod.example.tld/" }
|
||||||
xml = <<-XML
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
<Link rel="lrdd" type="application/xrd+xml" template="#{base_url}webfinger?q={uri}"/>
|
<Link rel="lrdd" type="application/xrd+xml" template="#{base_url}webfinger?q={uri}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
it "must not create blank instances" do
|
it "must not create blank instances" do
|
||||||
expect { WebFinger::HostMeta.new }.to raise_error(NoMethodError)
|
expect { WebFinger::HostMeta.new }.to raise_error NoMethodError
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#to_xml" do
|
context "generation" do
|
||||||
it "creates a nice XML document" do
|
it "creates a nice XML document" do
|
||||||
hm = WebFinger::HostMeta.from_base_url(base_url)
|
hm = WebFinger::HostMeta.from_base_url(base_url)
|
||||||
expect(hm.to_xml).to eq(xml)
|
expect(hm.to_xml).to eq(xml)
|
||||||
|
|
@ -24,11 +26,11 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if the base_url was omitted" do
|
it "fails if the base_url was omitted" do
|
||||||
expect { WebFinger::HostMeta.from_base_url("") }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::HostMeta.from_base_url("") }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#webfinger_template_url" do
|
context "parsing" do
|
||||||
it "parses its own output" do
|
it "parses its own output" do
|
||||||
hm = WebFinger::HostMeta.from_xml(xml)
|
hm = WebFinger::HostMeta.from_xml(xml)
|
||||||
expect(hm.webfinger_template_url).to eq("#{base_url}webfinger?q={uri}")
|
expect(hm.webfinger_template_url).to eq("#{base_url}webfinger?q={uri}")
|
||||||
|
|
@ -57,7 +59,7 @@ XML
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if the document contains a malformed webfinger url" do
|
it "fails if the document contains a malformed webfinger url" do
|
||||||
|
|
@ -67,11 +69,11 @@ XML
|
||||||
<Link rel="lrdd" type="application/xrd+xml" template="#{base_url}webfinger?q="/>
|
<Link rel="lrdd" type="application/xrd+xml" template="#{base_url}webfinger?q="/>
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if the document is invalid" do
|
it "fails if the document is invalid" do
|
||||||
expect { WebFinger::HostMeta.from_xml("") }.to raise_error(WebFinger::InvalidDocument)
|
expect { WebFinger::HostMeta.from_xml("") }.to raise_error WebFinger::InvalidDocument
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,18 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe WebFinger::WebFinger do
|
describe WebFinger::WebFinger do
|
||||||
acct = "acct:user@pod.example.tld"
|
let(:acct) { "acct:user@pod.example.tld" }
|
||||||
alias_url = "http://pod.example.tld/"
|
let(:alias_url) { "http://pod.example.tld/" }
|
||||||
hcard_url = "https://pod.example.tld/hcard/users/abcdef0123456789"
|
let(:hcard_url) { "https://pod.example.tld/hcard/users/abcdef0123456789" }
|
||||||
seed_url = "https://pod.geraspora.de/"
|
let(:seed_url) { "https://pod.geraspora.de/" }
|
||||||
guid = "abcdef0123456789"
|
let(:guid) { "abcdef0123456789" }
|
||||||
profile_url = "https://pod.example.tld/u/user"
|
let(:profile_url) { "https://pod.example.tld/u/user" }
|
||||||
atom_url = "https://pod.example.tld/public/user.atom"
|
let(:atom_url) { "https://pod.example.tld/public/user.atom" }
|
||||||
salmon_url = "https://pod.example.tld/receive/users/abcdef0123456789"
|
let(:salmon_url) { "https://pod.example.tld/receive/users/abcdef0123456789" }
|
||||||
pubkey = "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
|
let(:pubkey) { "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----" }
|
||||||
pubkey_base64 = Base64.strict_encode64(pubkey)
|
let(:pubkey_base64) { Base64.strict_encode64(pubkey) }
|
||||||
|
|
||||||
xml = <<-XML
|
let(:xml) {
|
||||||
|
<<-XML
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
<Subject>#{acct}</Subject>
|
<Subject>#{acct}</Subject>
|
||||||
|
|
@ -25,9 +26,10 @@ module DiasporaFederation
|
||||||
<Link rel="diaspora-public-key" type="RSA" href="#{pubkey_base64}"/>
|
<Link rel="diaspora-public-key" type="RSA" href="#{pubkey_base64}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
it "must not create blank instances" do
|
it "must not create blank instances" do
|
||||||
expect { WebFinger::WebFinger.new }.to raise_error(NameError)
|
expect { WebFinger::WebFinger.new }.to raise_error NameError
|
||||||
end
|
end
|
||||||
|
|
||||||
context "generation" do
|
context "generation" do
|
||||||
|
|
@ -57,11 +59,11 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if empty was given" do
|
it "fails if empty was given" do
|
||||||
expect { WebFinger::WebFinger.from_person({}) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::WebFinger.from_person({}) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if nil was given" do
|
it "fails if nil was given" do
|
||||||
expect { WebFinger::WebFinger.from_person(nil) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::WebFinger.from_person(nil) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -117,11 +119,11 @@ XML
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
expect { WebFinger::WebFinger.from_xml(invalid_xml) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::WebFinger.from_xml(invalid_xml) }.to raise_error WebFinger::InvalidData
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if the document is not XML" do
|
it "fails if the document is not XML" do
|
||||||
expect { WebFinger::WebFinger.from_xml("") }.to raise_error(WebFinger::InvalidDocument)
|
expect { WebFinger::WebFinger.from_xml("") }.to raise_error WebFinger::InvalidDocument
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
module DiasporaFederation
|
module DiasporaFederation
|
||||||
describe WebFinger::XrdDocument do
|
describe WebFinger::XrdDocument do
|
||||||
xml = <<XML
|
let(:xml) {
|
||||||
|
<<XML
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
<Expires>2010-01-30T09:30:00Z</Expires>
|
<Expires>2010-01-30T09:30:00Z</Expires>
|
||||||
|
|
@ -14,8 +15,10 @@ module DiasporaFederation
|
||||||
<Link rel="copyright" template="http://example.com/copyright?id={uri}"/>
|
<Link rel="copyright" template="http://example.com/copyright?id={uri}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
|
}
|
||||||
|
|
||||||
data = {
|
let(:data) {
|
||||||
|
{
|
||||||
subject: "http://blog.example.com/article/id/314",
|
subject: "http://blog.example.com/article/id/314",
|
||||||
expires: DateTime.parse("2010-01-30T09:30:00Z"),
|
expires: DateTime.parse("2010-01-30T09:30:00Z"),
|
||||||
aliases: %w(
|
aliases: %w(
|
||||||
|
|
@ -42,7 +45,9 @@ XML
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context "generation" do
|
||||||
it "creates the xml document" do
|
it "creates the xml document" do
|
||||||
doc = WebFinger::XrdDocument.new
|
doc = WebFinger::XrdDocument.new
|
||||||
doc.expires = data[:expires]
|
doc.expires = data[:expires]
|
||||||
|
|
@ -62,10 +67,21 @@ XML
|
||||||
|
|
||||||
expect(doc.to_xml).to eq(xml)
|
expect(doc.to_xml).to eq(xml)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "parsing" do
|
||||||
it "reads the xml document" do
|
it "reads the xml document" do
|
||||||
doc = WebFinger::XrdDocument.xml_data(xml)
|
doc = WebFinger::XrdDocument.xml_data(xml)
|
||||||
expect(doc).to eq(data)
|
expect(doc).to eq(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises InvalidDocument if the xml is empty" do
|
||||||
|
expect{ WebFinger::XrdDocument.xml_data("") }.to raise_error WebFinger::InvalidDocument
|
||||||
|
end
|
||||||
|
|
||||||
|
it "raises InvalidDocument if the xml is no XRD document" do
|
||||||
|
expect{ WebFinger::XrdDocument.xml_data("<html></html>") }.to raise_error WebFinger::InvalidDocument
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue