summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/nickserver/dispatcher.rb4
-rw-r--r--lib/nickserver/request_handlers/wkd_email_handler.rb22
-rw-r--r--lib/nickserver/wkd/source.rb3
-rw-r--r--lib/nickserver/wkd/url.rb5
-rw-r--r--test/functional/sample_test.rb4
-rw-r--r--test/integration/dispatcher_test.rb27
-rw-r--r--test/integration/nickserver_test.rb1
-rw-r--r--test/support/http_stub_helper.rb7
8 files changed, 62 insertions, 11 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
diff --git a/test/functional/sample_test.rb b/test/functional/sample_test.rb
index 1bfe8b5..4a0d1ed 100644
--- a/test/functional/sample_test.rb
+++ b/test/functional/sample_test.rb
@@ -23,6 +23,10 @@ class SampleTest < FunctionalTest
assert_lookup_status 200, 'test@mail.bitmask.net'
end
+ def test_wkd_success
+ assert_lookup_status 200, 'info@g10code.com'
+ end
+
# Regression Tests
# #3 handle missing A records
diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb
index 1973e84..0fb395a 100644
--- a/test/integration/dispatcher_test.rb
+++ b/test/integration/dispatcher_test.rb
@@ -37,30 +37,31 @@ class Nickserver::DispatcherTest < Minitest::Test
def test_missing_domain
handle address: ['valid@email.tld']
stub_nicknym_not_available
- hkp_source.expect :query, success, [Nickserver::EmailAddress]
+ wkd_source.expect :query, success, [Nickserver::EmailAddress]
assert_response success
end
- def test_email_via_hkp
+ def test_email_via_wkd
handle address: ['valid@email.tld'],
headers: { 'Host' => 'http://nickserver.me' }
stub_nicknym_not_available
- hkp_source.expect :query, success, [Nickserver::EmailAddress]
+ wkd_source.expect :query, success, [Nickserver::EmailAddress]
assert_response success
end
- def test_email_via_hkp_nicknym_unreachable
+ def test_email_via_wkd_nicknym_unreachable
handle address: ['valid@email.tld'],
headers: { 'Host' => 'http://nickserver.me' }
stub_nicknym_raises
- hkp_source.expect :query, success, [Nickserver::EmailAddress]
+ wkd_source.expect :query, success, [Nickserver::EmailAddress]
assert_response success
end
- def test_email_not_found_hkp_nicknym_unreachable
+ def test_email_not_found_wkd_nicknym_unreachable
handle address: ['valid@email.tld'],
headers: { 'Host' => 'http://nickserver.me' }
stub_nicknym_raises
+ wkd_source.expect :query, nil, [Nickserver::EmailAddress]
hkp_source.expect :query, nil, [Nickserver::EmailAddress]
assert_response http_connection_error
end
@@ -90,14 +91,20 @@ class Nickserver::DispatcherTest < Minitest::Test
def assert_response(response)
Nickserver::Nicknym::Source.stub :new, nicknym_source do
- Nickserver::Hkp::Source.stub :new, hkp_source do
- responder.expect :respond, nil, [response.status, response.content]
- dispatcher.respond_to @params, @headers
- responder.verify
+ Nickserver::Wkd::Source.stub :new, wkd_source do
+ Nickserver::Hkp::Source.stub :new, hkp_source do
+ responder.expect :respond, nil, [response.status, response.content]
+ dispatcher.respond_to @params, @headers
+ responder.verify
+ end
end
end
end
+ def wkd_source
+ @wkd_source ||= Minitest::Mock.new
+ end
+
def hkp_source
@hkp_source ||= Minitest::Mock.new
end
diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb
index 832a68c..29a3561 100644
--- a/test/integration/nickserver_test.rb
+++ b/test/integration/nickserver_test.rb
@@ -30,6 +30,7 @@ class NickserverTest < CelluloidTest
uid = 'cloudadmin@leap.se'
key_id = 'E818C478D3141282F7590D29D041EB11B1647490'
stub_nicknym_available_response 'leap.se', status: 404
+ stub_wkd_response uid, status: 404
stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result))
stub_sks_get_reponse(key_id, body: file_content(:leap_public_key))
diff --git a/test/support/http_stub_helper.rb b/test/support/http_stub_helper.rb
index b0ec069..1710b23 100644
--- a/test/support/http_stub_helper.rb
+++ b/test/support/http_stub_helper.rb
@@ -1,4 +1,5 @@
require 'nickserver/reel_server'
+require 'nickserver/email_address'
module HttpStubHelper
protected
@@ -48,6 +49,12 @@ module HttpStubHelper
stub_http_get(/#{Regexp.escape(config.couch_url)}.*#{query}/, response)
end
+ def stub_wkd_response(uid, response = {})
+ email = Nickserver::EmailAddress.new(uid)
+ url = Nickserver::Wkd::Url.new(email)
+ stub_http_get url, response, Hash
+ end
+
def stub_http_get(url, response, options = nil)
response = { status: 200, body: '' }.merge(response || {})
adapter.expect :get, [response[:status], response[:body]],