refactor webfinger
- add salmon private url for user - rename upates_url to atom_url
This commit is contained in:
parent
5ac7a14b1e
commit
5792afb427
2 changed files with 45 additions and 25 deletions
|
|
@ -16,7 +16,8 @@ module DiasporaFederation
|
||||||
# hcard_url: "https://server.example/hcard/users/user",
|
# hcard_url: "https://server.example/hcard/users/user",
|
||||||
# seed_url: "https://server.example/",
|
# seed_url: "https://server.example/",
|
||||||
# profile_url: "https://server.example/u/user",
|
# profile_url: "https://server.example/u/user",
|
||||||
# updates_url: "https://server.example/public/user.atom",
|
# atom_url: "https://server.example/public/user.atom",
|
||||||
|
# salmon_url: "https://server.example/receive/users/0123456789abcdef",
|
||||||
# guid: "0123456789abcdef",
|
# guid: "0123456789abcdef",
|
||||||
# pubkey: "ABCDEF=="
|
# pubkey: "ABCDEF=="
|
||||||
# })
|
# })
|
||||||
|
|
@ -36,7 +37,7 @@ module DiasporaFederation
|
||||||
class WebFinger
|
class WebFinger
|
||||||
private_class_method :new
|
private_class_method :new
|
||||||
|
|
||||||
attr_reader :acct_uri, :alias_url, :hcard_url, :seed_url, :profile_url, :updates_url
|
attr_reader :acct_uri, :alias_url, :hcard_url, :seed_url, :profile_url, :atom_url, :salmon_url
|
||||||
|
|
||||||
# @deprecated Either convert these to +Property+ elements or move to the
|
# @deprecated Either convert these to +Property+ elements or move to the
|
||||||
# +hCard+, which actually has fields for an +UID+ and +KEY+ defined in
|
# +hCard+, which actually has fields for an +UID+ and +KEY+ defined in
|
||||||
|
|
@ -60,7 +61,10 @@ module DiasporaFederation
|
||||||
REL_PROFILE = "http://webfinger.net/rel/profile-page"
|
REL_PROFILE = "http://webfinger.net/rel/profile-page"
|
||||||
|
|
||||||
# Atom feed link relation
|
# Atom feed link relation
|
||||||
REL_UPDATES = "http://schemas.google.com/g/2010#updates-from"
|
REL_ATOM = "http://schemas.google.com/g/2010#updates-from"
|
||||||
|
|
||||||
|
# +salmon+ endpoint link relation
|
||||||
|
REL_SALMON = "salmon"
|
||||||
|
|
||||||
# @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+
|
# @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+
|
||||||
# is inappropriate according to the specification (will affect older
|
# is inappropriate according to the specification (will affect older
|
||||||
|
|
@ -85,7 +89,7 @@ module DiasporaFederation
|
||||||
# @return [WebFinger] WebFinger instance
|
# @return [WebFinger] WebFinger instance
|
||||||
# @raise [InvalidData] if the given data Hash is invalid or incomplete
|
# @raise [InvalidData] if the given data Hash is invalid or incomplete
|
||||||
def self.from_account(data)
|
def self.from_account(data)
|
||||||
raise InvalidData unless account_data_complete?(data)
|
raise InvalidData, "account data incomplete" unless account_data_complete?(data)
|
||||||
|
|
||||||
wf = allocate
|
wf = allocate
|
||||||
wf.instance_eval {
|
wf.instance_eval {
|
||||||
|
|
@ -94,7 +98,8 @@ module DiasporaFederation
|
||||||
@hcard_url = data[:hcard_url]
|
@hcard_url = data[:hcard_url]
|
||||||
@seed_url = data[:seed_url]
|
@seed_url = data[:seed_url]
|
||||||
@profile_url = data[:profile_url]
|
@profile_url = data[:profile_url]
|
||||||
@updates_url = data[:updates_url]
|
@atom_url = data[:atom_url]
|
||||||
|
@salmon_url = data[:salmon_url]
|
||||||
|
|
||||||
# TODO: change me! #########
|
# TODO: change me! #########
|
||||||
@guid = data[:guid]
|
@guid = data[:guid]
|
||||||
|
|
@ -111,7 +116,7 @@ module DiasporaFederation
|
||||||
def self.from_xml(webfinger_xml)
|
def self.from_xml(webfinger_xml)
|
||||||
data = parse_xml_and_validate(webfinger_xml)
|
data = parse_xml_and_validate(webfinger_xml)
|
||||||
|
|
||||||
hcard_url, seed_url, guid, profile_url, updates_url, pubkey = parse_links(data)
|
hcard_url, seed_url, guid, profile_url, atom_url, salmon_url, pubkey = parse_links(data)
|
||||||
|
|
||||||
wf = allocate
|
wf = allocate
|
||||||
wf.instance_eval {
|
wf.instance_eval {
|
||||||
|
|
@ -120,7 +125,8 @@ module DiasporaFederation
|
||||||
@hcard_url = hcard_url
|
@hcard_url = hcard_url
|
||||||
@seed_url = seed_url
|
@seed_url = seed_url
|
||||||
@profile_url = profile_url
|
@profile_url = profile_url
|
||||||
@updates_url = updates_url
|
@atom_url = atom_url
|
||||||
|
@salmon_url = salmon_url
|
||||||
|
|
||||||
# TODO: change me! ##########
|
# TODO: change me! ##########
|
||||||
@guid = guid
|
@guid = guid
|
||||||
|
|
@ -136,11 +142,11 @@ module DiasporaFederation
|
||||||
# @param [Hash] data account data
|
# @param [Hash] data account data
|
||||||
# @return [Boolean] validation result
|
# @return [Boolean] validation result
|
||||||
def self.account_data_complete?(data)
|
def self.account_data_complete?(data)
|
||||||
!data.nil? && data.instance_of?(Hash) &&
|
data.instance_of?(Hash) && data.key?(:acct_uri) &&
|
||||||
data.key?(:acct_uri) && data.key?(:alias_url) &&
|
data.key?(:alias_url) && data.key?(:hcard_url) &&
|
||||||
data.key?(:hcard_url) && data.key?(:seed_url) &&
|
data.key?(:seed_url) && data.key?(:guid) &&
|
||||||
data.key?(:guid) && data.key?(:profile_url) &&
|
data.key?(:profile_url) && data.key?(:atom_url) &&
|
||||||
data.key?(:updates_url) && data.key?(:pubkey)
|
data.key?(:salmon_url) && data.key?(:pubkey)
|
||||||
end
|
end
|
||||||
private_class_method :account_data_complete?
|
private_class_method :account_data_complete?
|
||||||
|
|
||||||
|
|
@ -151,7 +157,8 @@ module DiasporaFederation
|
||||||
# @raise [InvalidData] if the given XML string is invalid or incomplete
|
# @raise [InvalidData] if the given XML string is invalid or incomplete
|
||||||
def self.parse_xml_and_validate(webfinger_xml)
|
def self.parse_xml_and_validate(webfinger_xml)
|
||||||
data = XrdDocument.xml_data(webfinger_xml)
|
data = XrdDocument.xml_data(webfinger_xml)
|
||||||
raise InvalidData unless data.key?(:subject) && data.key?(:aliases) && data.key?(:links)
|
valid = data.key?(:subject) && data.key?(:aliases) && data.key?(:links)
|
||||||
|
raise InvalidData, "webfinger xml is incomplete" unless valid
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
private_class_method :parse_xml_and_validate
|
private_class_method :parse_xml_and_validate
|
||||||
|
|
@ -173,9 +180,11 @@ module DiasporaFederation
|
||||||
doc.links << {rel: REL_PROFILE,
|
doc.links << {rel: REL_PROFILE,
|
||||||
type: "text/html",
|
type: "text/html",
|
||||||
href: @profile_url}
|
href: @profile_url}
|
||||||
doc.links << {rel: REL_UPDATES,
|
doc.links << {rel: REL_ATOM,
|
||||||
type: "application/atom+xml",
|
type: "application/atom+xml",
|
||||||
href: @updates_url}
|
href: @atom_url}
|
||||||
|
doc.links << {rel: REL_SALMON,
|
||||||
|
href: @salmon_url}
|
||||||
|
|
||||||
# TODO: change me! ##############
|
# TODO: change me! ##############
|
||||||
doc.links << {rel: REL_PUBKEY,
|
doc.links << {rel: REL_PUBKEY,
|
||||||
|
|
@ -190,10 +199,11 @@ module DiasporaFederation
|
||||||
seed = parse_link(links, REL_SEED)
|
seed = parse_link(links, REL_SEED)
|
||||||
guid = parse_link(links, REL_GUID)
|
guid = parse_link(links, REL_GUID)
|
||||||
profile = parse_link(links, REL_PROFILE)
|
profile = parse_link(links, REL_PROFILE)
|
||||||
updates = parse_link(links, REL_UPDATES)
|
atom = parse_link(links, REL_ATOM)
|
||||||
|
salmon = parse_link(links, REL_SALMON)
|
||||||
pubkey = parse_link(links, REL_PUBKEY)
|
pubkey = parse_link(links, REL_PUBKEY)
|
||||||
raise InvalidData unless [hcard, seed, guid, profile, updates, pubkey].all?
|
raise InvalidData, "webfinger xml is incomplete" unless [hcard, seed, guid, profile, atom, salmon, pubkey].all?
|
||||||
[hcard[:href], seed[:href], guid[:href], profile[:href], updates[:href], pubkey[:href]]
|
[hcard[:href], seed[:href], guid[:href], profile[:href], atom[:href], salmon[:href], pubkey[:href]]
|
||||||
end
|
end
|
||||||
private_class_method :parse_links
|
private_class_method :parse_links
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@ module DiasporaFederation
|
||||||
seed_url = "https://pod.geraspora.de/"
|
seed_url = "https://pod.geraspora.de/"
|
||||||
guid = "abcdef0123456789"
|
guid = "abcdef0123456789"
|
||||||
profile_url = "https://pod.example.tld/u/user"
|
profile_url = "https://pod.example.tld/u/user"
|
||||||
updates_url = "https://pod.example.tld/public/user.atom"
|
atom_url = "https://pod.example.tld/public/user.atom"
|
||||||
|
salmon_url = "https://pod.example.tld/receive/users/abcdef0123456789"
|
||||||
pubkey = "AAAAAA=="
|
pubkey = "AAAAAA=="
|
||||||
|
|
||||||
xml = <<-XML
|
xml = <<-XML
|
||||||
|
|
@ -18,7 +19,8 @@ module DiasporaFederation
|
||||||
<Link rel="http://joindiaspora.com/seed_location" type="text/html" href="#{seed_url}"/>
|
<Link rel="http://joindiaspora.com/seed_location" type="text/html" href="#{seed_url}"/>
|
||||||
<Link rel="http://joindiaspora.com/guid" type="text/html" href="#{guid}"/>
|
<Link rel="http://joindiaspora.com/guid" type="text/html" href="#{guid}"/>
|
||||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{profile_url}"/>
|
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{profile_url}"/>
|
||||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{updates_url}"/>
|
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{atom_url}"/>
|
||||||
|
<Link rel="salmon" href="#{salmon_url}"/>
|
||||||
<Link rel="diaspora-public-key" type="RSA" href="#{pubkey}"/>
|
<Link rel="diaspora-public-key" type="RSA" href="#{pubkey}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
|
|
@ -35,7 +37,8 @@ XML
|
||||||
hcard_url: hcard_url,
|
hcard_url: hcard_url,
|
||||||
seed_url: seed_url,
|
seed_url: seed_url,
|
||||||
profile_url: profile_url,
|
profile_url: profile_url,
|
||||||
updates_url: updates_url,
|
atom_url: atom_url,
|
||||||
|
salmon_url: salmon_url,
|
||||||
guid: guid,
|
guid: guid,
|
||||||
pubkey: pubkey
|
pubkey: pubkey
|
||||||
)
|
)
|
||||||
|
|
@ -52,9 +55,13 @@ XML
|
||||||
}.to raise_error(WebFinger::InvalidData)
|
}.to raise_error(WebFinger::InvalidData)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if nothing was given" do
|
it "fails if empty was given" do
|
||||||
expect { WebFinger::WebFinger.from_account({}) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::WebFinger.from_account({}) }.to raise_error(WebFinger::InvalidData)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "fails if nil was given" do
|
||||||
|
expect { WebFinger::WebFinger.from_account(nil) }.to raise_error(WebFinger::InvalidData)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "parsing" do
|
context "parsing" do
|
||||||
|
|
@ -65,7 +72,8 @@ XML
|
||||||
expect(wf.hcard_url).to eq(hcard_url)
|
expect(wf.hcard_url).to eq(hcard_url)
|
||||||
expect(wf.seed_url).to eq(seed_url)
|
expect(wf.seed_url).to eq(seed_url)
|
||||||
expect(wf.profile_url).to eq(profile_url)
|
expect(wf.profile_url).to eq(profile_url)
|
||||||
expect(wf.updates_url).to eq(updates_url)
|
expect(wf.atom_url).to eq(atom_url)
|
||||||
|
expect(wf.salmon_url).to eq(salmon_url)
|
||||||
|
|
||||||
expect(wf.guid).to eq(guid)
|
expect(wf.guid).to eq(guid)
|
||||||
expect(wf.pubkey).to eq(pubkey)
|
expect(wf.pubkey).to eq(pubkey)
|
||||||
|
|
@ -82,7 +90,8 @@ XML
|
||||||
<Link rel="http://joindiaspora.com/guid" type = "text/html" href="#{guid}"/>
|
<Link rel="http://joindiaspora.com/guid" type = "text/html" href="#{guid}"/>
|
||||||
|
|
||||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{profile_url}"/>
|
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{profile_url}"/>
|
||||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{updates_url}"/>
|
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{atom_url}"/>
|
||||||
|
<Link rel="salmon" href="#{salmon_url}"/>
|
||||||
|
|
||||||
<Link rel="diaspora-public-key" type = "RSA" href="#{pubkey}"/>
|
<Link rel="diaspora-public-key" type = "RSA" href="#{pubkey}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
|
|
@ -94,7 +103,8 @@ XML
|
||||||
expect(wf.hcard_url).to eq(hcard_url)
|
expect(wf.hcard_url).to eq(hcard_url)
|
||||||
expect(wf.seed_url).to eq(seed_url)
|
expect(wf.seed_url).to eq(seed_url)
|
||||||
expect(wf.profile_url).to eq(profile_url)
|
expect(wf.profile_url).to eq(profile_url)
|
||||||
expect(wf.updates_url).to eq(updates_url)
|
expect(wf.atom_url).to eq(atom_url)
|
||||||
|
expect(wf.salmon_url).to eq(salmon_url)
|
||||||
|
|
||||||
expect(wf.guid).to eq(guid)
|
expect(wf.guid).to eq(guid)
|
||||||
expect(wf.pubkey).to eq(pubkey)
|
expect(wf.pubkey).to eq(pubkey)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue