Make optional properties optional when generating webfinger
This commit is contained in:
parent
83a6434c32
commit
5fef7633c3
2 changed files with 35 additions and 21 deletions
|
|
@ -38,7 +38,7 @@ module DiasporaFederation
|
||||||
# @!attribute [r] alias_url
|
# @!attribute [r] alias_url
|
||||||
# @note could be nil
|
# @note could be nil
|
||||||
# @return [String] link to the users profile
|
# @return [String] link to the users profile
|
||||||
property :alias_url, :string
|
property :alias_url, :string, default: nil
|
||||||
|
|
||||||
# @!attribute [r] hcard_url
|
# @!attribute [r] hcard_url
|
||||||
# @return [String] link to the +hCard+
|
# @return [String] link to the +hCard+
|
||||||
|
|
@ -50,7 +50,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
# @!attribute [r] profile_url
|
# @!attribute [r] profile_url
|
||||||
# @return [String] link to the users profile
|
# @return [String] link to the users profile
|
||||||
property :profile_url, :string
|
property :profile_url, :string, default: nil
|
||||||
|
|
||||||
# @!attribute [r] atom_url
|
# @!attribute [r] atom_url
|
||||||
# This atom feed is an Activity Stream of the user's public posts. diaspora*
|
# This atom feed is an Activity Stream of the user's public posts. diaspora*
|
||||||
|
|
@ -61,18 +61,18 @@ module DiasporaFederation
|
||||||
# Note that this feed MAY also be made available through the PubSubHubbub
|
# Note that this feed MAY also be made available through the PubSubHubbub
|
||||||
# mechanism by supplying a <link rel="hub"> in the atom feed itself.
|
# mechanism by supplying a <link rel="hub"> in the atom feed itself.
|
||||||
# @return [String] atom feed url
|
# @return [String] atom feed url
|
||||||
property :atom_url, :string
|
property :atom_url, :string, default: nil
|
||||||
|
|
||||||
# @!attribute [r] salmon_url
|
# @!attribute [r] salmon_url
|
||||||
# @note could be nil
|
# @note could be nil
|
||||||
# @return [String] salmon endpoint url
|
# @return [String] salmon endpoint url
|
||||||
# @see https://cdn.rawgit.com/salmon-protocol/salmon-protocol/master/draft-panzer-salmon-00.html#SMLR
|
# @see https://cdn.rawgit.com/salmon-protocol/salmon-protocol/master/draft-panzer-salmon-00.html#SMLR
|
||||||
# Panzer draft for Salmon, paragraph 3.3
|
# Panzer draft for Salmon, paragraph 3.3
|
||||||
property :salmon_url, :string
|
property :salmon_url, :string, default: nil
|
||||||
|
|
||||||
# @!attribute [r] subscribe_url
|
# @!attribute [r] subscribe_url
|
||||||
# This url is used to find another user on the home-pod of the user in the webfinger.
|
# This url is used to find another user on the home-pod of the user in the webfinger.
|
||||||
property :subscribe_url, :string
|
property :subscribe_url, :string, default: nil
|
||||||
|
|
||||||
# +hcard_url+ link relation
|
# +hcard_url+ link relation
|
||||||
REL_HCARD = "http://microformats.org/profile/hcard".freeze
|
REL_HCARD = "http://microformats.org/profile/hcard".freeze
|
||||||
|
|
@ -97,8 +97,8 @@ module DiasporaFederation
|
||||||
# @return [String] XML string
|
# @return [String] XML string
|
||||||
def to_xml
|
def to_xml
|
||||||
doc = XrdDocument.new
|
doc = XrdDocument.new
|
||||||
doc.subject = @acct_uri
|
doc.subject = acct_uri
|
||||||
doc.aliases << @alias_url
|
doc.aliases << alias_url
|
||||||
|
|
||||||
add_links_to(doc)
|
add_links_to(doc)
|
||||||
|
|
||||||
|
|
@ -147,14 +147,18 @@ module DiasporaFederation
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_links_to(doc)
|
def add_links_to(doc)
|
||||||
doc.links << {rel: REL_HCARD, type: "text/html", href: @hcard_url}
|
doc.links << {rel: REL_HCARD, type: "text/html", href: hcard_url}
|
||||||
doc.links << {rel: REL_SEED, type: "text/html", href: @seed_url}
|
doc.links << {rel: REL_SEED, type: "text/html", href: seed_url}
|
||||||
|
|
||||||
doc.links << {rel: REL_PROFILE, type: "text/html", href: @profile_url}
|
add_optional_links_to(doc)
|
||||||
doc.links << {rel: REL_ATOM, type: "application/atom+xml", href: @atom_url}
|
end
|
||||||
doc.links << {rel: REL_SALMON, href: @salmon_url}
|
|
||||||
|
|
||||||
doc.links << {rel: REL_SUBSCRIBE, template: @subscribe_url}
|
def add_optional_links_to(doc)
|
||||||
|
doc.links << {rel: REL_PROFILE, type: "text/html", href: profile_url} if profile_url
|
||||||
|
doc.links << {rel: REL_ATOM, type: "application/atom+xml", href: atom_url} if atom_url
|
||||||
|
doc.links << {rel: REL_SALMON, href: salmon_url} if salmon_url
|
||||||
|
|
||||||
|
doc.links << {rel: REL_SUBSCRIBE, template: subscribe_url} if subscribe_url
|
||||||
end
|
end
|
||||||
|
|
||||||
private_class_method def self.find_link(links, rel)
|
private_class_method def self.find_link(links, rel)
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,15 @@ module DiasporaFederation
|
||||||
<Link rel="salmon" href="#{person.salmon_url}"/>
|
<Link rel="salmon" href="#{person.salmon_url}"/>
|
||||||
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="#{person.subscribe_url}"/>
|
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="#{person.subscribe_url}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
|
XML
|
||||||
|
|
||||||
|
let(:minimal_xml) { <<-XML }
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
|
<Subject>#{acct}</Subject>
|
||||||
|
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="#{person.hcard_url}"/>
|
||||||
|
<Link rel="http://joindiaspora.com/seed_location" type="text/html" href="#{person.url}"/>
|
||||||
|
</XRD>
|
||||||
XML
|
XML
|
||||||
|
|
||||||
let(:string) { "WebFinger:#{data[:acct_uri]}" }
|
let(:string) { "WebFinger:#{data[:acct_uri]}" }
|
||||||
|
|
@ -40,6 +49,15 @@ XML
|
||||||
wf = Discovery::WebFinger.new(data)
|
wf = Discovery::WebFinger.new(data)
|
||||||
expect(wf.to_xml).to eq(xml)
|
expect(wf.to_xml).to eq(xml)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates minimal XML document" do
|
||||||
|
wf = Discovery::WebFinger.new(
|
||||||
|
acct_uri: "acct:#{person.diaspora_id}",
|
||||||
|
hcard_url: person.hcard_url,
|
||||||
|
seed_url: person.url
|
||||||
|
)
|
||||||
|
expect(wf.to_xml).to eq(minimal_xml)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "parsing" do
|
context "parsing" do
|
||||||
|
|
@ -56,14 +74,6 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reads minimal xml" do
|
it "reads minimal xml" do
|
||||||
minimal_xml = <<-XML
|
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
|
||||||
<Subject>#{acct}</Subject>
|
|
||||||
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="#{person.hcard_url}"/>
|
|
||||||
<Link rel="http://joindiaspora.com/seed_location" type="text/html" href="#{person.url}"/>
|
|
||||||
</XRD>
|
|
||||||
XML
|
|
||||||
wf = Discovery::WebFinger.from_xml(minimal_xml)
|
wf = Discovery::WebFinger.from_xml(minimal_xml)
|
||||||
expect(wf.acct_uri).to eq(acct)
|
expect(wf.acct_uri).to eq(acct)
|
||||||
expect(wf.hcard_url).to eq(person.hcard_url)
|
expect(wf.hcard_url).to eq(person.hcard_url)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue