From 2f6acc8367beecccdbc176dc56591106f7be512d Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Thu, 17 Sep 2015 01:49:03 +0200 Subject: [PATCH] fix friendica parsing with acct URIs in aliases --- .../discovery/web_finger.rb | 9 ++- .../discovery/web_finger_spec.rb | 62 ++++++++++++++++++- 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/lib/diaspora_federation/discovery/web_finger.rb b/lib/diaspora_federation/discovery/web_finger.rb index 9a6729c..06721cf 100644 --- a/lib/diaspora_federation/discovery/web_finger.rb +++ b/lib/diaspora_federation/discovery/web_finger.rb @@ -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 diff --git a/spec/lib/diaspora_federation/discovery/web_finger_spec.rb b/spec/lib/diaspora_federation/discovery/web_finger_spec.rb index 9ee48dd..9613f92 100644 --- a/spec/lib/diaspora_federation/discovery/web_finger_spec.rb +++ b/spec/lib/diaspora_federation/discovery/web_finger_spec.rb @@ -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 + + + + #{acct} + #{acct} + #{person.alias_url} + + + + + + + + + + + + + + + + + + RSA.abcdef1234567890 + + + 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