make alias and salmon-url optional to support redmatrix
This commit is contained in:
parent
b114973785
commit
c3e290465f
4 changed files with 90 additions and 8 deletions
|
|
@ -41,6 +41,7 @@ module DiasporaFederation
|
|||
property :acct_uri
|
||||
|
||||
# @!attribute [r] alias_url
|
||||
# @note could be nil
|
||||
# @return [String] link to the users profile
|
||||
property :alias_url
|
||||
|
||||
|
|
@ -68,6 +69,7 @@ module DiasporaFederation
|
|||
property :atom_url
|
||||
|
||||
# @!attribute [r] salmon_url
|
||||
# @note could be nil
|
||||
# @return [String] salmon endpoint url
|
||||
# @see http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-salmon-00.html#SMLR
|
||||
# Panzer draft for Salmon, paragraph 3.3
|
||||
|
|
@ -154,7 +156,7 @@ module DiasporaFederation
|
|||
|
||||
new(
|
||||
acct_uri: data[:subject],
|
||||
alias_url: clean_alias(data[:aliases].first),
|
||||
alias_url: parse_alias(data[:aliases]),
|
||||
hcard_url: parse_link(links, REL_HCARD),
|
||||
seed_url: parse_link(links, REL_SEED),
|
||||
profile_url: parse_link(links, REL_PROFILE),
|
||||
|
|
@ -176,7 +178,7 @@ module DiasporaFederation
|
|||
# @raise [InvalidData] if the given XML string is invalid or incomplete
|
||||
def self.parse_xml_and_validate(webfinger_xml)
|
||||
XrdDocument.xml_data(webfinger_xml).tap do |data|
|
||||
valid = data.key?(:subject) && data.key?(:aliases) && data.key?(:links)
|
||||
valid = data.key?(:subject) && data.key?(:links)
|
||||
raise InvalidData, "webfinger xml is incomplete" unless valid
|
||||
end
|
||||
end
|
||||
|
|
@ -218,11 +220,13 @@ module DiasporaFederation
|
|||
end
|
||||
private_class_method :parse_link
|
||||
|
||||
# @deprecated remove this, when all pods use this gem for generation
|
||||
def self.clean_alias(alias_string)
|
||||
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/, "")
|
||||
end
|
||||
private_class_method :parse_link
|
||||
private_class_method :parse_alias
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,12 +9,12 @@ module DiasporaFederation
|
|||
|
||||
rule :acct_uri, :not_empty
|
||||
|
||||
rule :alias_url, [:not_nil, URI: %i(host path)]
|
||||
rule :alias_url, URI: %i(host path)
|
||||
rule :hcard_url, [:not_nil, URI: %i(host path)]
|
||||
rule :seed_url, %i(not_nil URI)
|
||||
rule :profile_url, [:not_nil, URI: %i(host path)]
|
||||
rule :atom_url, [:not_nil, URI: %i(host path)]
|
||||
rule :salmon_url, [:not_nil, URI: %i(host path)]
|
||||
rule :salmon_url, URI: %i(host path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -96,6 +96,51 @@ XML
|
|||
expect(wf.public_key).to eq(person.serialized_public_key)
|
||||
end
|
||||
|
||||
it "reads redmatrix XML" do
|
||||
redmatrix_xml = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
|
||||
<Subject>#{person.diaspora_id}</Subject>
|
||||
|
||||
<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://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://microformats.org/profile/hcard"
|
||||
type="text/html"
|
||||
href="#{person.hcard_url}" />
|
||||
|
||||
<Link rel="magic-public-key"
|
||||
href="data:application/magic-public-key,RSA.abcdef1234567890" />
|
||||
|
||||
<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}" />
|
||||
|
||||
</XRD>
|
||||
XML
|
||||
|
||||
wf = Discovery::WebFinger.from_xml(redmatrix_xml)
|
||||
expect(wf.acct_uri).to eq(person.diaspora_id)
|
||||
expect(wf.alias_url).to be_nil
|
||||
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 be_nil
|
||||
|
||||
expect(wf.guid).to eq(person.guid)
|
||||
expect(wf.public_key).to eq(person.serialized_public_key)
|
||||
end
|
||||
|
||||
it "reads future XML without guid and public key" do
|
||||
future_xml = <<-XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
%i(alias_url hcard_url profile_url atom_url salmon_url).each do |prop|
|
||||
%i(hcard_url profile_url atom_url).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it_behaves_like "a url validator without path" do
|
||||
let(:property) { prop }
|
||||
|
|
@ -36,6 +36,39 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
# optional urls
|
||||
%i(alias_url salmon_url).each do |prop|
|
||||
describe "##{prop}" do
|
||||
it "is allowed to be nil" do
|
||||
validator = described_class.new(webfinger_stub(prop => nil))
|
||||
|
||||
expect(validator).to be_valid
|
||||
expect(validator.errors).to be_empty
|
||||
end
|
||||
|
||||
it "must not be empty" do
|
||||
validator = described_class.new(webfinger_stub(prop => ""))
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(prop)
|
||||
end
|
||||
|
||||
it "fails for url with special chars" do
|
||||
validator = described_class.new(webfinger_stub(prop => "https://asdf$%.com"))
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(prop)
|
||||
end
|
||||
|
||||
it "fails for url without scheme" do
|
||||
validator = described_class.new(webfinger_stub(prop => "example.com"))
|
||||
|
||||
expect(validator).not_to be_valid
|
||||
expect(validator.errors).to include(prop)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#seed_url" do
|
||||
it_behaves_like "a url validator without path" do
|
||||
let(:property) { :seed_url }
|
||||
|
|
|
|||
Loading…
Reference in a new issue