diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/dispatcher.rb | 4 | ||||
-rw-r--r-- | lib/nickserver/request_handlers/wkd_email_handler.rb | 22 | ||||
-rw-r--r-- | lib/nickserver/wkd/source.rb | 3 | ||||
-rw-r--r-- | lib/nickserver/wkd/url.rb | 5 |
4 files changed, 33 insertions, 1 deletions
diff --git a/lib/nickserver/dispatcher.rb b/lib/nickserver/dispatcher.rb index 99f06c3..420f631 100644 --- a/lib/nickserver/dispatcher.rb +++ b/lib/nickserver/dispatcher.rb @@ -13,11 +13,14 @@ # handler_chain function. # +require 'http' + require 'nickserver/request' require 'nickserver/handler_chain' require 'nickserver/request_handlers/invalid_email_handler' require 'nickserver/request_handlers/local_email_handler' require 'nickserver/request_handlers/leap_email_handler' +require 'nickserver/request_handlers/wkd_email_handler' require 'nickserver/request_handlers/hkp_email_handler' require 'nickserver/request_handlers/fingerprint_handler' @@ -50,6 +53,7 @@ module Nickserver chain = HandlerChain.new RequestHandlers::InvalidEmailHandler, RequestHandlers::LocalEmailHandler, RequestHandlers::LeapEmailHandler, + RequestHandlers::WkdEmailHandler, RequestHandlers::HkpEmailHandler, RequestHandlers::FingerprintHandler, proc { proxy_error_response }, diff --git a/lib/nickserver/request_handlers/wkd_email_handler.rb b/lib/nickserver/request_handlers/wkd_email_handler.rb new file mode 100644 index 0000000..034c843 --- /dev/null +++ b/lib/nickserver/request_handlers/wkd_email_handler.rb @@ -0,0 +1,22 @@ +require 'nickserver/email_address' +require 'nickserver/wkd/source' + +module Nickserver + module RequestHandlers + class WkdEmailHandler < Base + def handle + source.query(email) if request.email + end + + protected + + def email + @email ||= EmailAddress.new(request.email) + end + + def source + Nickserver::Wkd::Source.new adapter + end + end + end +end diff --git a/lib/nickserver/wkd/source.rb b/lib/nickserver/wkd/source.rb index bf30c94..da7abb8 100644 --- a/lib/nickserver/wkd/source.rb +++ b/lib/nickserver/wkd/source.rb @@ -8,7 +8,8 @@ module Nickserver::Wkd class Source < Nickserver::Source def query(email) url = Url.new(email) - status, blob = adapter.get url + status, blob = adapter.get url, + rescue: 'failed to connect: getaddrinfo' if status == 200 Nickserver::KeyResponse.new(email.to_s, armor_key(blob)) end diff --git a/lib/nickserver/wkd/url.rb b/lib/nickserver/wkd/url.rb index 0ccff38..759222d 100644 --- a/lib/nickserver/wkd/url.rb +++ b/lib/nickserver/wkd/url.rb @@ -13,6 +13,11 @@ module Nickserver::Wkd "https://#{domain}/.well-known/openpgpkey/hu/#{encoded_digest}" end + # needed to compare when used as an arg calling a test mock + def ==(other) + self.to_s == other.to_s + end + protected attr_reader :domain, :local_part |