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
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
describe "#public" do
|
||||
describe "POST #public" do
|
||||
it "succeeds" do
|
||||
post :public, xml: "<diaspora/>"
|
||||
expect(response).to be_success
|
||||
|
|
@ -14,7 +14,7 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
describe "#private" do
|
||||
describe "POST #private" do
|
||||
it "succeeds" do
|
||||
post :private, guid: "any-guid", xml: "<diaspora/>"
|
||||
expect(response).to be_success
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ module DiasporaFederation
|
|||
describe WebfingerController, type: :controller do
|
||||
routes { DiasporaFederation::Engine.routes }
|
||||
|
||||
describe "#host_meta" do
|
||||
describe "GET #host_meta" do
|
||||
before do
|
||||
DiasporaFederation.server_uri = URI("http://localhost:3000/")
|
||||
WebfingerController.instance_variable_set(:@host_meta_xml, nil) # clear cache
|
||||
|
|
@ -35,7 +35,7 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
describe "#legacy_webfinger" do
|
||||
describe "GET #legacy_webfinger" do
|
||||
it "succeeds when the person exists" do
|
||||
get :legacy_webfinger, "q" => "alice@localhost:3000"
|
||||
expect(response).to be_success
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ HTML
|
|||
}
|
||||
|
||||
it "must not create blank instances" do
|
||||
expect { WebFinger::HCard.new }.to raise_error(NameError)
|
||||
expect { WebFinger::HCard.new }.to raise_error NameError
|
||||
end
|
||||
|
||||
context "generation" do
|
||||
|
|
@ -127,15 +127,15 @@ HTML
|
|||
guid: guid,
|
||||
diaspora_handle: handle
|
||||
)
|
||||
}.to raise_error(WebFinger::InvalidData)
|
||||
}.to raise_error WebFinger::InvalidData
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -239,11 +239,11 @@ HTML
|
|||
<span class="fn">#{name}</span>
|
||||
</div>
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
module DiasporaFederation
|
||||
describe WebFinger::HostMeta do
|
||||
base_url = "https://pod.example.tld/"
|
||||
xml = <<-XML
|
||||
let(:base_url) { "https://pod.example.tld/" }
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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}"/>
|
||||
</XRD>
|
||||
XML
|
||||
}
|
||||
|
||||
it "must not create blank instances" do
|
||||
expect { WebFinger::HostMeta.new }.to raise_error(NoMethodError)
|
||||
expect { WebFinger::HostMeta.new }.to raise_error NoMethodError
|
||||
end
|
||||
|
||||
context "#to_xml" do
|
||||
context "generation" do
|
||||
it "creates a nice XML document" do
|
||||
hm = WebFinger::HostMeta.from_base_url(base_url)
|
||||
expect(hm.to_xml).to eq(xml)
|
||||
|
|
@ -24,11 +26,11 @@ XML
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
context "#webfinger_template_url" do
|
||||
context "parsing" do
|
||||
it "parses its own output" do
|
||||
hm = WebFinger::HostMeta.from_xml(xml)
|
||||
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>
|
||||
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
|
||||
|
||||
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="/>
|
||||
</XRD>
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
module DiasporaFederation
|
||||
describe WebFinger::WebFinger do
|
||||
acct = "acct:user@pod.example.tld"
|
||||
alias_url = "http://pod.example.tld/"
|
||||
hcard_url = "https://pod.example.tld/hcard/users/abcdef0123456789"
|
||||
seed_url = "https://pod.geraspora.de/"
|
||||
guid = "abcdef0123456789"
|
||||
profile_url = "https://pod.example.tld/u/user"
|
||||
atom_url = "https://pod.example.tld/public/user.atom"
|
||||
salmon_url = "https://pod.example.tld/receive/users/abcdef0123456789"
|
||||
pubkey = "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
|
||||
pubkey_base64 = Base64.strict_encode64(pubkey)
|
||||
let(:acct) { "acct:user@pod.example.tld" }
|
||||
let(:alias_url) { "http://pod.example.tld/" }
|
||||
let(:hcard_url) { "https://pod.example.tld/hcard/users/abcdef0123456789" }
|
||||
let(:seed_url) { "https://pod.geraspora.de/" }
|
||||
let(:guid) { "abcdef0123456789" }
|
||||
let(:profile_url) { "https://pod.example.tld/u/user" }
|
||||
let(:atom_url) { "https://pod.example.tld/public/user.atom" }
|
||||
let(:salmon_url) { "https://pod.example.tld/receive/users/abcdef0123456789" }
|
||||
let(:pubkey) { "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----" }
|
||||
let(:pubkey_base64) { Base64.strict_encode64(pubkey) }
|
||||
|
||||
xml = <<-XML
|
||||
let(:xml) {
|
||||
<<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Subject>#{acct}</Subject>
|
||||
|
|
@ -25,9 +26,10 @@ module DiasporaFederation
|
|||
<Link rel="diaspora-public-key" type="RSA" href="#{pubkey_base64}"/>
|
||||
</XRD>
|
||||
XML
|
||||
}
|
||||
|
||||
it "must not create blank instances" do
|
||||
expect { WebFinger::WebFinger.new }.to raise_error(NameError)
|
||||
expect { WebFinger::WebFinger.new }.to raise_error NameError
|
||||
end
|
||||
|
||||
context "generation" do
|
||||
|
|
@ -57,11 +59,11 @@ XML
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -117,11 +119,11 @@ XML
|
|||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
</XRD>
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
module DiasporaFederation
|
||||
describe WebFinger::XrdDocument do
|
||||
xml = <<XML
|
||||
let(:xml) {
|
||||
<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Expires>2010-01-30T09:30:00Z</Expires>
|
||||
|
|
@ -14,58 +15,73 @@ module DiasporaFederation
|
|||
<Link rel="copyright" template="http://example.com/copyright?id={uri}"/>
|
||||
</XRD>
|
||||
XML
|
||||
|
||||
data = {
|
||||
subject: "http://blog.example.com/article/id/314",
|
||||
expires: DateTime.parse("2010-01-30T09:30:00Z"),
|
||||
aliases: %w(
|
||||
http://blog.example.com/cool_new_thing
|
||||
http://blog.example.com/steve/article/7
|
||||
),
|
||||
properties: {
|
||||
"http://blgx.example.net/ns/version" => "1.3",
|
||||
"http://blgx.example.net/ns/ext" => nil
|
||||
},
|
||||
links: [
|
||||
{
|
||||
rel: "author",
|
||||
type: "text/html",
|
||||
href: "http://blog.example.com/author/steve"
|
||||
},
|
||||
{
|
||||
rel: "author",
|
||||
href: "http://example.com/author/john"
|
||||
},
|
||||
{
|
||||
rel: "copyright",
|
||||
template: "http://example.com/copyright?id={uri}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
it "creates the xml document" do
|
||||
doc = WebFinger::XrdDocument.new
|
||||
doc.expires = data[:expires]
|
||||
doc.subject = data[:subject]
|
||||
let(:data) {
|
||||
{
|
||||
subject: "http://blog.example.com/article/id/314",
|
||||
expires: DateTime.parse("2010-01-30T09:30:00Z"),
|
||||
aliases: %w(
|
||||
http://blog.example.com/cool_new_thing
|
||||
http://blog.example.com/steve/article/7
|
||||
),
|
||||
properties: {
|
||||
"http://blgx.example.net/ns/version" => "1.3",
|
||||
"http://blgx.example.net/ns/ext" => nil
|
||||
},
|
||||
links: [
|
||||
{
|
||||
rel: "author",
|
||||
type: "text/html",
|
||||
href: "http://blog.example.com/author/steve"
|
||||
},
|
||||
{
|
||||
rel: "author",
|
||||
href: "http://example.com/author/john"
|
||||
},
|
||||
{
|
||||
rel: "copyright",
|
||||
template: "http://example.com/copyright?id={uri}"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
data[:aliases].each do |a|
|
||||
doc.aliases << a
|
||||
context "generation" do
|
||||
it "creates the xml document" do
|
||||
doc = WebFinger::XrdDocument.new
|
||||
doc.expires = data[:expires]
|
||||
doc.subject = data[:subject]
|
||||
|
||||
data[:aliases].each do |a|
|
||||
doc.aliases << a
|
||||
end
|
||||
|
||||
data[:properties].each do |t, v|
|
||||
doc.properties[t] = v
|
||||
end
|
||||
|
||||
data[:links].each do |h|
|
||||
doc.links << h
|
||||
end
|
||||
|
||||
expect(doc.to_xml).to eq(xml)
|
||||
end
|
||||
|
||||
data[:properties].each do |t, v|
|
||||
doc.properties[t] = v
|
||||
end
|
||||
|
||||
data[:links].each do |h|
|
||||
doc.links << h
|
||||
end
|
||||
|
||||
expect(doc.to_xml).to eq(xml)
|
||||
end
|
||||
|
||||
it "reads the xml document" do
|
||||
doc = WebFinger::XrdDocument.xml_data(xml)
|
||||
expect(doc).to eq(data)
|
||||
context "parsing" do
|
||||
it "reads the xml document" do
|
||||
doc = WebFinger::XrdDocument.xml_data(xml)
|
||||
expect(doc).to eq(data)
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue