module DiasporaFederation describe WebFinger::HostMeta do let(:base_url) { "https://pod.example.tld/" } let(:xml) { <<-XML XML } it "must not create blank instances" do expect { WebFinger::HostMeta.new }.to raise_error NoMethodError end 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) end it "appends a '/' if necessary" do hm = WebFinger::HostMeta.from_base_url("https://pod.example.tld") expect(hm.to_xml).to eq(xml) end it "fails if the base_url was omitted" do expect { WebFinger::HostMeta.from_base_url("") }.to raise_error WebFinger::InvalidData end end 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}") end it "also reads old-style XML" do historic_xml = <<-XML XML hm = WebFinger::HostMeta.from_xml(historic_xml) expect(hm.webfinger_template_url).to eq("#{base_url}webfinger?q={uri}") end it "fails if the document does not contain a webfinger url" do invalid_xml = < XML expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error WebFinger::InvalidData end it "fails if the document contains a malformed webfinger url" do invalid_xml = < XML 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 end end end end