rename WebFinger module to Discovery

This commit is contained in:
Benjamin Neff 2015-07-11 17:23:19 +02:00
parent c4173fa18c
commit 09904b54d0
16 changed files with 62 additions and 62 deletions

View file

@ -46,7 +46,7 @@ DiasporaFederation.configure do |config|
on :person_webfinger_fetch do |handle|
person = Person.find_local_by_diaspora_handle(handle)
if person
DiasporaFederation::WebFinger::WebFinger.new(
DiasporaFederation::Discovery::WebFinger.new(
# ...
)
end

View file

@ -48,11 +48,11 @@ module DiasporaFederation
# creates the host-meta xml with the configured server_uri and caches it
# @return [String] XML string
def self.host_meta_xml
@host_meta_xml ||= WebFinger::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s).to_xml
@host_meta_xml ||= Discovery::HostMeta.from_base_url(DiasporaFederation.server_uri.to_s).to_xml
end
def find_person_webfinger(query)
DiasporaFederation.callbacks.trigger(:person_webfinger_fetch, query.strip.downcase.gsub("acct:", ""))
DiasporaFederation.callbacks.trigger(:person_webfinger_fetch, query.strip.downcase.sub("acct:", ""))
end
end
end

View file

@ -4,7 +4,7 @@ require "diaspora_federation/callbacks"
require "diaspora_federation/properties_dsl"
require "diaspora_federation/entity"
require "diaspora_federation/web_finger"
require "diaspora_federation/discovery"
# diaspora* federation library
module DiasporaFederation

View file

@ -0,0 +1,13 @@
module DiasporaFederation
# This module provides the namespace for the various classes implementing
# WebFinger and other protocols used for metadata discovery on remote servers
# in the Diaspora* network.
module Discovery
end
end
require "diaspora_federation/discovery/exceptions"
require "diaspora_federation/discovery/xrd_document"
require "diaspora_federation/discovery/host_meta"
require "diaspora_federation/discovery/web_finger"
require "diaspora_federation/discovery/h_card"

View file

@ -1,5 +1,5 @@
module DiasporaFederation
module WebFinger
module Discovery
# Raised, if the XML structure is invalid
class InvalidDocument < RuntimeError
end

View file

@ -1,5 +1,5 @@
module DiasporaFederation
module WebFinger
module Discovery
# This class provides the means of generating an parsing account data to and
# from the hCard format.
# hCard is based on +RFC 2426+ (vCard) which got superseded by +RFC 6350+.

View file

@ -1,6 +1,6 @@
module DiasporaFederation
module WebFinger
module Discovery
# Generates and parses Host Meta documents.
#
# This is a minimal implementation of the standard, only to the degree of what

View file

@ -1,5 +1,5 @@
module DiasporaFederation
module WebFinger
module Discovery
# The WebFinger document used for Diaspora* user discovery is based on an older
# draft of the specification you can find in the wiki of the "webfinger" project
# on {http://code.google.com/p/webfinger/wiki/WebFingerProtocol Google Code}

View file

@ -1,5 +1,5 @@
module DiasporaFederation
module WebFinger
module Discovery
# This class implements basic handling of XRD documents as far as it is
# necessary in the context of the protocols used with Diaspora* federation.
#

View file

@ -1,13 +0,0 @@
module DiasporaFederation
# This module provides the namespace for the various classes implementing
# WebFinger and other protocols used for metadata discovery on remote servers
# in the Diaspora* network.
module WebFinger
end
end
require "diaspora_federation/web_finger/exceptions"
require "diaspora_federation/web_finger/xrd_document"
require "diaspora_federation/web_finger/host_meta"
require "diaspora_federation/web_finger/web_finger"
require "diaspora_federation/web_finger/h_card"

View file

@ -24,13 +24,13 @@ module DiasporaFederation
expect(response.header["Content-Type"]).to include "application/xrd+xml"
end
it "calls WebFinger::HostMeta.from_base_url with the base url" do
expect(WebFinger::HostMeta).to receive(:from_base_url).with("http://localhost:3000/").and_call_original
it "calls Discovery::HostMeta.from_base_url with the base url" do
expect(Discovery::HostMeta).to receive(:from_base_url).with("http://localhost:3000/").and_call_original
get :host_meta
end
it "caches the xml" do
expect(WebFinger::HostMeta).to receive(:from_base_url).exactly(1).times.and_call_original
expect(Discovery::HostMeta).to receive(:from_base_url).exactly(1).times.and_call_original
get :host_meta
get :host_meta
end

View file

@ -1,5 +1,5 @@
module DiasporaFederation
describe WebFinger::HCard do
describe Discovery::HCard do
let(:person) { FactoryGirl.create(:person) }
let(:photo_large_url) { "#{person.url}/upload/large.png" }
let(:photo_medium_url) { "#{person.url}/upload/medium.png" }
@ -93,12 +93,12 @@ HTML
}
it "must not create blank instances" do
expect { WebFinger::HCard.new({}) }.to raise_error ArgumentError
expect { Discovery::HCard.new({}) }.to raise_error ArgumentError
end
context "generation" do
it "creates an instance from a data hash" do
hcard = WebFinger::HCard.new(
hcard = Discovery::HCard.new(
guid: person.guid,
nickname: person.nickname,
full_name: person.full_name,
@ -115,13 +115,13 @@ HTML
end
it "fails if nil was given" do
expect { WebFinger::HCard.new(nil) }.to raise_error ArgumentError, "expected a Hash"
expect { Discovery::HCard.new(nil) }.to raise_error ArgumentError, "expected a Hash"
end
end
context "parsing" do
it "reads its own output" do
hcard = WebFinger::HCard.from_html(html)
hcard = Discovery::HCard.from_html(html)
expect(hcard.guid).to eq(person.guid)
expect(hcard.nickname).to eq(person.nickname)
expect(hcard.full_name).to eq(person.full_name)
@ -137,7 +137,7 @@ HTML
end
it "is frozen after parsing" do
hcard = WebFinger::HCard.from_html(html)
hcard = Discovery::HCard.from_html(html)
expect(hcard).to be_frozen
end
@ -147,7 +147,7 @@ HTML
"class=\"searchable\"><"
)
hcard = WebFinger::HCard.from_html(changed_html)
hcard = Discovery::HCard.from_html(changed_html)
expect(hcard.searchable).to eq(false)
end
@ -218,7 +218,7 @@ HTML
</div>
HTML
hcard = WebFinger::HCard.from_html(historic_html)
hcard = Discovery::HCard.from_html(historic_html)
expect(hcard.url).to eq(person.url)
expect(hcard.photo_large_url).to eq(photo_large_url)
expect(hcard.photo_medium_url).to eq(photo_medium_url)
@ -235,11 +235,11 @@ HTML
<span class="fn">#{person.full_name}</span>
</div>
HTML
expect { WebFinger::HCard.from_html(invalid_html) }.to raise_error WebFinger::InvalidData
expect { Discovery::HCard.from_html(invalid_html) }.to raise_error Discovery::InvalidData
end
it "fails if the document is not HTML" do
expect { WebFinger::HCard.from_html("") }.to raise_error WebFinger::InvalidData
expect { Discovery::HCard.from_html("") }.to raise_error Discovery::InvalidData
end
end
end

View file

@ -1,5 +1,5 @@
module DiasporaFederation
describe WebFinger::HostMeta do
describe Discovery::HostMeta do
let(:base_url) { "https://pod.example.tld/" }
let(:xml) {
<<-XML
@ -11,28 +11,28 @@ XML
}
it "must not create blank instances" do
expect { WebFinger::HostMeta.new }.to raise_error NoMethodError
expect { Discovery::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)
hm = Discovery::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")
hm = Discovery::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
expect { Discovery::HostMeta.from_base_url("") }.to raise_error Discovery::InvalidData
end
end
context "parsing" do
it "parses its own output" do
hm = WebFinger::HostMeta.from_xml(xml)
hm = Discovery::HostMeta.from_xml(xml)
expect(hm.webfinger_template_url).to eq("#{base_url}webfinger?q={uri}")
end
@ -49,7 +49,7 @@ XML
</XRD>
XML
hm = WebFinger::HostMeta.from_xml(historic_xml)
hm = Discovery::HostMeta.from_xml(historic_xml)
expect(hm.webfinger_template_url).to eq("#{base_url}webfinger?q={uri}")
end
@ -59,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 { Discovery::HostMeta.from_xml(invalid_xml) }.to raise_error Discovery::InvalidData
end
it "fails if the document contains a malformed webfinger url" do
@ -69,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 { Discovery::HostMeta.from_xml(invalid_xml) }.to raise_error Discovery::InvalidData
end
it "fails if the document is invalid" do
expect { WebFinger::HostMeta.from_xml("") }.to raise_error WebFinger::InvalidDocument
expect { Discovery::HostMeta.from_xml("") }.to raise_error Discovery::InvalidDocument
end
end
end

View file

@ -1,5 +1,5 @@
module DiasporaFederation
describe WebFinger::WebFinger do
describe Discovery::WebFinger do
let(:person) { FactoryGirl.create(:person) }
let(:acct) { "acct:#{person.diaspora_handle}" }
let(:public_key_base64) { Base64.strict_encode64(person.serialized_public_key) }
@ -22,12 +22,12 @@ XML
}
it "must not create blank instances" do
expect { WebFinger::WebFinger.new({}) }.to raise_error ArgumentError
expect { Discovery::WebFinger.new({}) }.to raise_error ArgumentError
end
context "generation" do
it "creates a nice XML document" do
wf = WebFinger::WebFinger.new(
wf = Discovery::WebFinger.new(
acct_uri: "acct:#{person.diaspora_handle}",
alias_url: person.alias_url,
hcard_url: person.hcard_url,
@ -42,13 +42,13 @@ XML
end
it "fails if nil was given" do
expect { WebFinger::WebFinger.new(nil) }.to raise_error ArgumentError, "expected a Hash"
expect { Discovery::WebFinger.new(nil) }.to raise_error ArgumentError, "expected a Hash"
end
end
context "parsing" do
it "reads its own output" do
wf = WebFinger::WebFinger.from_xml(xml)
wf = Discovery::WebFinger.from_xml(xml)
expect(wf.acct_uri).to eq(acct)
expect(wf.alias_url).to eq(person.alias_url)
expect(wf.hcard_url).to eq(person.hcard_url)
@ -62,7 +62,7 @@ XML
end
it "is frozen after parsing" do
wf = WebFinger::WebFinger.from_xml(xml)
wf = Discovery::WebFinger.from_xml(xml)
expect(wf).to be_frozen
end
@ -84,7 +84,7 @@ XML
</XRD>
XML
wf = WebFinger::WebFinger.from_xml(historic_xml)
wf = Discovery::WebFinger.from_xml(historic_xml)
expect(wf.acct_uri).to eq(acct)
expect(wf.alias_url).to eq(person.alias_url)
expect(wf.hcard_url).to eq(person.hcard_url)
@ -103,11 +103,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 { Discovery::WebFinger.from_xml(invalid_xml) }.to raise_error Discovery::InvalidData
end
it "fails if the document is not XML" do
expect { WebFinger::WebFinger.from_xml("") }.to raise_error WebFinger::InvalidDocument
expect { Discovery::WebFinger.from_xml("") }.to raise_error Discovery::InvalidDocument
end
end
end

View file

@ -1,5 +1,5 @@
module DiasporaFederation
describe WebFinger::XrdDocument do
describe Discovery::XrdDocument do
let(:xml) {
<<XML
<?xml version="1.0" encoding="UTF-8"?>
@ -49,7 +49,7 @@ XML
context "generation" do
it "creates the xml document" do
doc = WebFinger::XrdDocument.new
doc = Discovery::XrdDocument.new
doc.expires = data[:expires]
doc.subject = data[:subject]
@ -71,16 +71,16 @@ XML
context "parsing" do
it "reads the xml document" do
doc = WebFinger::XrdDocument.xml_data(xml)
doc = Discovery::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
expect { Discovery::XrdDocument.xml_data("") }.to raise_error Discovery::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
expect { Discovery::XrdDocument.xml_data("<html></html>") }.to raise_error Discovery::InvalidDocument
end
end
end

View file

@ -1,4 +1,4 @@
require "diaspora_federation/web_finger"
require "diaspora_federation/discovery"
# configure the federation engine
DiasporaFederation.configure do |config|
@ -9,7 +9,7 @@ DiasporaFederation.configure do |config|
on :person_webfinger_fetch do |handle|
person = Person.find_by(diaspora_handle: handle)
if person
DiasporaFederation::WebFinger::WebFinger.new(
DiasporaFederation::Discovery::WebFinger.new(
acct_uri: "acct:#{person.diaspora_handle}",
alias_url: person.alias_url,
hcard_url: person.hcard_url,
@ -26,7 +26,7 @@ DiasporaFederation.configure do |config|
on :person_hcard_fetch do |guid|
person = Person.find_by(guid: guid)
if person
DiasporaFederation::WebFinger::HCard.new(
DiasporaFederation::Discovery::HCard.new(
guid: person.guid,
nickname: person.nickname,
full_name: person.full_name,