fix friendica parsing with acct URIs in aliases
This commit is contained in:
parent
b748b255f1
commit
2f6acc8367
2 changed files with 67 additions and 4 deletions
|
|
@ -220,11 +220,14 @@ module DiasporaFederation
|
|||
end
|
||||
private_class_method :parse_link
|
||||
|
||||
# this method is used to parse the alias_url from the XML.
|
||||
# * redmatrix has sometimes no alias, return nil
|
||||
# * old pods had quotes around the alias url, this can be removed later
|
||||
# * friendica has two aliases and the first is with "acct:": return only an URL starting with http (or https)
|
||||
def self.parse_alias(aliases)
|
||||
return nil unless aliases
|
||||
alias_string = aliases.first
|
||||
# Old pods had quotes around alias. Remove this, when all pods use this gem for generation
|
||||
alias_string.gsub(/\A"|"\Z/, "")
|
||||
# TODO: Old pods had quotes around alias. Remove the +map+ in next line, when all pods use this gem
|
||||
aliases.map {|a| a.gsub(/\A"|"\Z/, "") }.find {|a| a.start_with?("http") }
|
||||
end
|
||||
private_class_method :parse_alias
|
||||
end
|
||||
|
|
|
|||
|
|
@ -96,7 +96,67 @@ XML
|
|||
expect(wf.public_key).to eq(person.serialized_public_key)
|
||||
end
|
||||
|
||||
it "reads redmatrix XML" do
|
||||
it "reads friendica XML (two aliases, first with acct)" do
|
||||
friendica_xml = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
|
||||
<Subject>#{acct}</Subject>
|
||||
<Alias>#{acct}</Alias>
|
||||
<Alias>#{person.alias_url}</Alias>
|
||||
|
||||
<Link rel="http://purl.org/macgirvin/dfrn/1.0"
|
||||
href="#{person.profile_url}" />
|
||||
<Link rel="http://schemas.google.com/g/2010#updates-from"
|
||||
type="application/atom+xml"
|
||||
href="#{person.atom_url}" />
|
||||
<Link rel="http://webfinger.net/rel/profile-page"
|
||||
type="text/html"
|
||||
href="#{person.profile_url}" />
|
||||
<Link rel="http://microformats.org/profile/hcard"
|
||||
type="text/html"
|
||||
href="#{person.hcard_url}" />
|
||||
<Link rel="http://portablecontacts.net/spec/1.0"
|
||||
href="https://pod.example.tld/poco/trouble" />
|
||||
<Link rel="http://webfinger.net/rel/avatar"
|
||||
type="image/jpeg"
|
||||
href="http://localhost:3000/assets/user/default.png" />
|
||||
<Link rel="http://joindiaspora.com/seed_location" type="text/html" href="#{person.url}" />
|
||||
<Link rel="http://joindiaspora.com/guid" type="text/html" href="#{person.guid}" />
|
||||
<Link rel="diaspora-public-key" type="RSA" href="#{public_key_base64}" />
|
||||
|
||||
<Link rel="salmon"
|
||||
href="#{person.salmon_url}" />
|
||||
<Link rel="http://salmon-protocol.org/ns/salmon-replies"
|
||||
href="https://pod.example.tld/salmon/trouble" />
|
||||
<Link rel="http://salmon-protocol.org/ns/salmon-mention"
|
||||
href="https://pod.example.tld/salmon/trouble/mention" />
|
||||
<Link rel="http://ostatus.org/schema/1.0/subscribe"
|
||||
template="https://pod.example.tld/follow?url={uri}" />
|
||||
<Link rel="magic-public-key"
|
||||
href="data:application/magic-public-key,RSA.abcdef1234567890" />
|
||||
|
||||
<Property xmlns:mk="http://salmon-protocol.org/ns/magic-key"
|
||||
type="http://salmon-protocol.org/ns/magic-key"
|
||||
mk:key_id="1">RSA.abcdef1234567890</Property>
|
||||
|
||||
</XRD>
|
||||
XML
|
||||
|
||||
wf = Discovery::WebFinger.from_xml(friendica_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)
|
||||
expect(wf.seed_url).to eq(person.url)
|
||||
expect(wf.profile_url).to eq(person.profile_url)
|
||||
expect(wf.atom_url).to eq(person.atom_url)
|
||||
expect(wf.salmon_url).to eq(person.salmon_url)
|
||||
|
||||
expect(wf.guid).to eq(person.guid)
|
||||
expect(wf.public_key).to eq(person.serialized_public_key)
|
||||
end
|
||||
|
||||
it "reads redmatrix XML (no alias)" do
|
||||
redmatrix_xml = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
|
|
|
|||
Loading…
Reference in a new issue