move errors to exceptions.rb
This commit is contained in:
parent
82eb5415ab
commit
32be6257f3
5 changed files with 24 additions and 14 deletions
|
|
@ -7,5 +7,6 @@ module DiasporaFederation
|
|||
end
|
||||
end
|
||||
|
||||
require "diaspora_federation/webfinger/exceptions"
|
||||
require "diaspora_federation/webfinger/xrd_document"
|
||||
require "diaspora_federation/webfinger/host_meta"
|
||||
|
|
|
|||
17
lib/diaspora_federation/webfinger/exceptions.rb
Normal file
17
lib/diaspora_federation/webfinger/exceptions.rb
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
module DiasporaFederation
|
||||
module WebFinger
|
||||
##
|
||||
# Raised, if the XML structure is invalid
|
||||
class InvalidDocument < RuntimeError
|
||||
end
|
||||
|
||||
##
|
||||
# Raised, if something is wrong with the webfinger data
|
||||
#
|
||||
# * if the +webfinger_url+ is missing or malformed in {HostMeta.from_base_url} or {HostMeta.from_xml}
|
||||
# * if the +data+ given to {WebFinger.from_account} is an invalid type or doesn't contain all required entries
|
||||
# * if the parsed XML from {WebFinger.from_xml} is incomplete
|
||||
class InvalidData < RuntimeError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -77,6 +77,8 @@ module DiasporaFederation
|
|||
hm
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
##
|
||||
# Applies some basic sanity-checking to the given URL
|
||||
# @param [String] url validation subject
|
||||
|
|
@ -84,7 +86,6 @@ module DiasporaFederation
|
|||
def self.webfinger_url_valid?(url)
|
||||
!url.nil? && url.instance_of?(String) && url =~ %r{^https?:\/\/.*\{uri\}}i
|
||||
end
|
||||
private_class_method :webfinger_url_valid?
|
||||
|
||||
##
|
||||
# Gets the webfinger url from an XRD data structure
|
||||
|
|
@ -94,11 +95,6 @@ module DiasporaFederation
|
|||
link = data[:links].find {|l| (l[:rel] == "lrdd" && l[:type] == "application/xrd+xml") }
|
||||
return link[:template] unless link.nil?
|
||||
end
|
||||
private_class_method :webfinger_url_from_xrd
|
||||
|
||||
# Raised, if the +webfinger_url+ is missing or malformed
|
||||
class InvalidData < RuntimeError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -165,10 +165,6 @@ module DiasporaFederation
|
|||
end
|
||||
data[:links] = links unless links.empty?
|
||||
end
|
||||
|
||||
# Raised, if the XML structure is invalid
|
||||
class InvalidDocument < RuntimeError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ XML
|
|||
end
|
||||
|
||||
it "fails if the base_url was omitted" do
|
||||
expect { WebFinger::HostMeta.from_base_url("") }.to raise_error(WebFinger::HostMeta::InvalidData)
|
||||
expect { WebFinger::HostMeta.from_base_url("") }.to raise_error(WebFinger::InvalidData)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ XML
|
|||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
</XRD>
|
||||
XML
|
||||
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error(WebFinger::HostMeta::InvalidData)
|
||||
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error(WebFinger::InvalidData)
|
||||
end
|
||||
|
||||
it "fails if the document contains a malformed webfinger url" do
|
||||
|
|
@ -67,11 +67,11 @@ XML
|
|||
<Link rel="lrdd" type="application/xrd+xml" template="#{base_url}webfinger?q="/>
|
||||
</XRD>
|
||||
XML
|
||||
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error(WebFinger::HostMeta::InvalidData)
|
||||
expect { WebFinger::HostMeta.from_xml(invalid_xml) }.to raise_error(WebFinger::InvalidData)
|
||||
end
|
||||
|
||||
it "fails if the document is invalid" do
|
||||
expect { WebFinger::HostMeta.from_xml("") }.to raise_error(WebFinger::XrdDocument::InvalidDocument)
|
||||
expect { WebFinger::HostMeta.from_xml("") }.to raise_error(WebFinger::InvalidDocument)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue