From 964cd0b049e67ca10bd37b67c4b14ccd37064511 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 16 Sep 2016 14:32:55 +0200 Subject: deal with network issues in nicknym source This is a first step. In case the suspected nicknym server cannot be reached we will now move on and try other sources. It's robably not what we want in the long run. In order to know wether no key exists or we just failed to connect to some servers a different http response code would be nice if network errors occured. This simplifies testing such scenarios in the unit test and makes the remote tests skip on network failure. --- lib/nickserver/nicknym/source.rb | 2 ++ test/remote/nicknym_source_test.rb | 11 +++++--- test/unit/nicknym/source_test.rb | 58 +++++++++++++++++++++++++++----------- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/lib/nickserver/nicknym/source.rb b/lib/nickserver/nicknym/source.rb index 45daeaf..0638869 100644 --- a/lib/nickserver/nicknym/source.rb +++ b/lib/nickserver/nicknym/source.rb @@ -8,6 +8,8 @@ module Nickserver def available_for?(domain) status, body = adapter.get "https://#{domain}/provider.json" status == 200 && provider_with_mx?(body) + rescue HTTP::ConnectionError + return false end def query(email) diff --git a/test/remote/nicknym_source_test.rb b/test/remote/nicknym_source_test.rb index 2be7251..c95c820 100644 --- a/test/remote/nicknym_source_test.rb +++ b/test/remote/nicknym_source_test.rb @@ -2,6 +2,9 @@ require 'test_helper' require 'nickserver/nicknym/source' require 'nickserver/email_address' +# +# Please note the Readme.md file in this directory +# class RemoteNicknymSourceTest < Minitest::Test def setup @@ -15,22 +18,22 @@ class RemoteNicknymSourceTest < Minitest::Test end def test_availablility_check - assert source.available_for? 'mail.bitmask.net' + skip unless source.available_for? 'mail.bitmask.net' refute source.available_for? 'dl.bitmask.net' # not a provider - refute source.available_for? 'demo.bitmask.net' # provider without mx end def test_successful_query response = source.query(email_with_key) + skip if response.status == 404 json = JSON.parse response.content - assert_equal 200, response.status assert_equal email_with_key.to_s, json["address"] refute_empty json["openpgp"] end def test_not_found response = source.query(email_without_key) - assert_equal 404, response.status + skip if response.status == 200 + assert response.status == 404 end protected diff --git a/test/unit/nicknym/source_test.rb b/test/unit/nicknym/source_test.rb index 76337d4..cddb7c2 100644 --- a/test/unit/nicknym/source_test.rb +++ b/test/unit/nicknym/source_test.rb @@ -8,31 +8,55 @@ class NicknymSourceTest < Minitest::Test assert source end - def test_available_for_domain - adapter.expect :get, [200, '{"services": ["mx"]}'], - ['https://leap_powered.tld/provider.json'] - assert source.available_for?('leap_powered.tld') - adapter.verify + def test_available_for_domain_with_service_mx + assert available_on?(200, '{"services": ["mx"]}') end - def test_not_available_for_domain - adapter.expect :get, [404, nil], - ['https://remote.tld/provider.json'] - assert !source.available_for?('remote.tld') - adapter.verify + def test_no_provider_json_means_no_nicknym + refute available_on?(404, 'blablabla') + end + + def test_invalid_provider_json_means_no_nicknym + refute available_on?(200, 'blablabla') end - def test_successful_query - adapter.expect :get, [200, 'dummy body'], - ['https://nicknym.leap_powered.tld:6425', - {query: {address: email_stub.to_s}}] + def test_failing_network_means_no_nicknym + failing_network + refute source.available_for?('remote.tld') + end + + def test_proxy_successful_query + assert proxies_query_response?(200, 'dummy body') + end + + def test_proxy_query_not_found + assert proxies_query_response?(404, 'dummy body') + end + + protected + + def proxies_query_response?(status = 0, body = nil) + adapter.expect :get, [status, body], + ['https://nicknym.leap_powered.tld:6425', query: {address: email_stub.to_s}] response = source.query(email_stub) - assert_equal 200, response.status - assert_equal 'dummy body', response.content + assert_equal status, response.status + assert_equal body, response.content adapter.verify end - protected + def available_on?(status = 0, body = nil) + adapter.expect :get, [status, body], + ['https://remote.tld/provider.json'] + available = source.available_for?('remote.tld') + adapter.verify + return available + end + + def failing_network + def adapter.get(*args) + raise HTTP::ConnectionError + end + end def source Nickserver::Nicknym::Source.new(adapter) -- cgit v1.2.3 From d3c9ec2c815a4cd79cfaf40d1de0365fdec90cb2 Mon Sep 17 00:00:00 2001 From: Azul Date: Fri, 16 Sep 2016 15:29:06 +0200 Subject: gitignore: vendor --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6dfed3c..22d0d82 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -pkg -Gemfile.lock -NOTES \ No newline at end of file +vendor -- cgit v1.2.3 From a1c7d68b05f142322a190b450971d27c076310a9 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 19 Sep 2016 09:51:38 +0200 Subject: refactor: separate handler chain from dispatcher Handler Chain is of handlers that respond to call. Invoking handle(*args) on the chain will call the handlers with the given args until one of them returns a result that is truethy (i.e. not false or nil). Extracted from the dispatcher so we can also handle exceptions there in the future. (So that if one of the network connections to the request_handlers fails we can continue while still tracking the failed exception.) --- lib/nickserver/dispatcher.rb | 9 ++------- lib/nickserver/handler_chain.rb | 26 ++++++++++++++++++++++++ test/unit/handler_chain_test.rb | 45 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 lib/nickserver/handler_chain.rb create mode 100644 test/unit/handler_chain_test.rb diff --git a/lib/nickserver/dispatcher.rb b/lib/nickserver/dispatcher.rb index 7a584e5..9968e95 100644 --- a/lib/nickserver/dispatcher.rb +++ b/lib/nickserver/dispatcher.rb @@ -35,10 +35,7 @@ module Nickserver protected def handle(request) - handler_chain.each do |handler| - response = handler.call request - return response if response - end + handler_chain.handle request rescue RuntimeError => exc puts "Error: #{exc}" puts exc.backtrace @@ -46,13 +43,11 @@ module Nickserver end def handler_chain - [ - RequestHandlers::InvalidEmailHandler, + HandlerChain.new RequestHandlers::InvalidEmailHandler, RequestHandlers::LocalEmailHandler, RequestHandlers::HkpEmailHandler, RequestHandlers::FingerprintHandler, Proc.new { Nickserver::Response.new(404, "404 Not Found\n") } - ] end def send_response(response) diff --git a/lib/nickserver/handler_chain.rb b/lib/nickserver/handler_chain.rb new file mode 100644 index 0000000..a0eba4d --- /dev/null +++ b/lib/nickserver/handler_chain.rb @@ -0,0 +1,26 @@ +# +# Handler Chain +# +# A chain of handlers that respond to call. Invoking handle(*args) on the chain +# will call the handlers with the given args until one of them returns a result +# that is truethy (i.e. not false or nil). +# +# Extracted from the dispatcher so we can also handle exceptions here in the +# future. +# + +module Nickserver + class HandlerChain + + def initialize(*handlers) + @handlers = handlers + end + + def handle(*args) + result = nil + _handled_by = @handlers.find{|h| result = h.call(*args)} + result + end + + end +end diff --git a/test/unit/handler_chain_test.rb b/test/unit/handler_chain_test.rb new file mode 100644 index 0000000..067f11e --- /dev/null +++ b/test/unit/handler_chain_test.rb @@ -0,0 +1,45 @@ +require 'test_helper' +require 'nickserver/handler_chain' + +class HandlerChainTest < Minitest::Test + + def test_initialization + assert chain + end + + def test_noop + assert_nil chain.handle + end + + def test_triggering_handlers + handler_mock.expect :call, nil, [:a, :b] + chain handler_mock + chain.handle :a, :b + handler_mock.verify + end + + def test_returns_handler_result + chain handler_with_nil, handler_with_result + assert_equal :result, chain.handle + end + + + protected + + def chain(*handlers) + @chain ||= Nickserver::HandlerChain.new(*handlers) + end + + def handler_mock + @handler ||= Minitest::Mock.new + end + + def handler_with_nil + Proc.new {} + end + + def handler_with_result + Proc.new { :result } + end + +end -- cgit v1.2.3 From dd71240fe4f4f968b9b687917cb6d7ad5812ba48 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 20 Sep 2016 09:14:43 +0200 Subject: rescue and track exceptions in handler chain --- lib/nickserver/handler_chain.rb | 28 +++++++++++++++++++++++++--- test/unit/handler_chain_test.rb | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/lib/nickserver/handler_chain.rb b/lib/nickserver/handler_chain.rb index a0eba4d..afc24a5 100644 --- a/lib/nickserver/handler_chain.rb +++ b/lib/nickserver/handler_chain.rb @@ -5,8 +5,11 @@ # will call the handlers with the given args until one of them returns a result # that is truethy (i.e. not false or nil). # -# Extracted from the dispatcher so we can also handle exceptions here in the -# future. +# You can specify exception classes to rescue with +# handler_chain.continue_on ErrorClass1, ErrorClass2 +# These exceptions will be rescued and tracked. The chain will proceed even if +# one handler raised the given exception. Afterwards you can inspect them with +# handler_chain.rescued_exceptions # module Nickserver @@ -14,13 +17,32 @@ module Nickserver def initialize(*handlers) @handlers = handlers + @exceptions_to_rescue = [] + @rescued_exceptions = [] + end + + def continue_on(*exceptions) + self.exceptions_to_rescue += exceptions end def handle(*args) result = nil - _handled_by = @handlers.find{|h| result = h.call(*args)} + _handled_by = @handlers.find{|h| result = try_handler(h, *args)} result end + attr_reader :rescued_exceptions + + protected + + attr_writer :rescued_exceptions + attr_accessor :exceptions_to_rescue + + def try_handler(handler, *args) + result = handler.call(*args) + rescue *exceptions_to_rescue + self.rescued_exceptions << $! + result = false + end end end diff --git a/test/unit/handler_chain_test.rb b/test/unit/handler_chain_test.rb index 067f11e..fae0418 100644 --- a/test/unit/handler_chain_test.rb +++ b/test/unit/handler_chain_test.rb @@ -23,6 +23,26 @@ class HandlerChainTest < Minitest::Test assert_equal :result, chain.handle end + def test_raise_exception + chain handler_raising, handler_with_result + assert_raises RuntimeError do + chain.handle + end + end + + def test_continue_on_exception + chain handler_raising, handler_with_result + chain.continue_on(RuntimeError) + assert_equal :result, chain.handle + assert_equal [RuntimeError], chain.rescued_exceptions.map(&:class) + end + + def test_continue_on_exception_with_nil + chain handler_raising, handler_with_nil + chain.continue_on(RuntimeError) + assert_nil chain.handle + assert_equal [RuntimeError], chain.rescued_exceptions.map(&:class) + end protected @@ -42,4 +62,7 @@ class HandlerChainTest < Minitest::Test Proc.new { :result } end + def handler_raising(exception = RuntimeError) + Proc.new { raise exception } + end end -- cgit v1.2.3 From 6f507ed7b4f53054313173ce795ffd2cbcecd0b7 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 21 Sep 2016 12:48:11 +0200 Subject: feature: activate nicknym lookup --- lib/nickserver/dispatcher.rb | 3 ++ test/integration/dispatcher_test.rb | 93 +++++++++++++++++++++++++------------ test/integration/nickserver_test.rb | 1 + test/support/http_stub_helper.rb | 8 +++- 4 files changed, 74 insertions(+), 31 deletions(-) diff --git a/lib/nickserver/dispatcher.rb b/lib/nickserver/dispatcher.rb index 9968e95..75f6083 100644 --- a/lib/nickserver/dispatcher.rb +++ b/lib/nickserver/dispatcher.rb @@ -14,8 +14,10 @@ # 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/hkp_email_handler' require 'nickserver/request_handlers/fingerprint_handler' @@ -45,6 +47,7 @@ module Nickserver def handler_chain HandlerChain.new RequestHandlers::InvalidEmailHandler, RequestHandlers::LocalEmailHandler, + RequestHandlers::LeapEmailHandler, RequestHandlers::HkpEmailHandler, RequestHandlers::FingerprintHandler, Proc.new { Nickserver::Response.new(404, "404 Not Found\n") } diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb index 60ad9d7..986972c 100644 --- a/test/integration/dispatcher_test.rb +++ b/test/integration/dispatcher_test.rb @@ -5,44 +5,51 @@ class Nickserver::DispatcherTest < Minitest::Test def test_empty_query handle - assert_response status: 404, content: "404 Not Found\n" + assert_response not_found end def test_invalid_query handle address: ['asdf'] - assert_response status: 500, content: "500 Not a valid address\n" + assert_response error('Not a valid address') + end + + def test_fingerprint_to_short + handle fingerprint: ['44F2F455E28'] + assert_response error("Fingerprint invalid: 44F2F455E28") + end + + def test_fingerprint_is_not_hex + handle fingerprint: ['X36E738D69173C13Z709E44F2F455E2824D18DDX'] + assert_response error("Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX") end def test_missing_domain handle address: ['valid@email.tld'] - assert_response_from_hkp + stub_nicknym_not_available + hkp_source.expect :query, success, [Nickserver::EmailAddress] + assert_response success end - def test_email_from_hkp + def test_email_via_hkp handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } - assert_response_from_hkp + stub_nicknym_not_available + hkp_source.expect :query, success, [Nickserver::EmailAddress] + assert_response success end - def test_fingerprint_to_short - handle fingerprint: ['44F2F455E28'] - assert_response status: 500, content: "500 Fingerprint invalid: 44F2F455E28\n" - end - - def test_fingerprint_is_not_hex - handle fingerprint: ['X36E738D69173C13Z709E44F2F455E2824D18DDX'] - assert_response status: 500, - content: "500 Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX\n" + def test_email_via_nicknym + handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + nicknym_source.expect :available_for?, true, [String] + nicknym_source.expect :query, success, [Nickserver::EmailAddress] + assert_response success end - def test_get_key_with_fingerprint_from_hkp + def test_get_key_with_fingerprint handle fingerprint: ['E36E738D69173C13D709E44F2F455E2824D18DDF'] - source = Minitest::Mock.new - source.expect :get_key_by_fingerprint, - Nickserver::Response.new(200, "fake key response"), + stub_nicknym_not_available + hkp_source.expect :get_key_by_fingerprint, success, ['E36E738D69173C13D709E44F2F455E2824D18DDF'] - Nickserver::Hkp::Source.stub :new, source do - assert_response status: 200, content: "fake key response" - end + assert_response success end protected @@ -52,20 +59,46 @@ class Nickserver::DispatcherTest < Minitest::Test @params = Hash[ params.map{ |k,v| [k.to_s, v] } ] end - def assert_response(args) - responder.expect :respond, nil, [args[:status], args[:content]] - dispatcher.respond_to @params, @headers - responder.verify + 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 + end + end + end + + def hkp_source + @hkp_source ||= Minitest::Mock.new end - def assert_response_from_hkp - source = Minitest::Mock.new - source.expect :query, Nickserver::Response.new(200, "fake content"), [Nickserver::EmailAddress] - Nickserver::Hkp::Source.stub :new, source do - assert_response status: 200, content: "fake content" + def stub_nicknym_not_available + def nicknym_source.available_for?(*_args) + false end end + def nicknym_source + @nicknym_source ||= Minitest::Mock.new + end + + def success + response status: 200, content: "fake content" + end + + def not_found + response status: 404, content: "404 Not Found\n" + end + + def error(msg) + response status: 500, content: "500 #{msg}\n" + end + + def response(options) + Nickserver::Response.new(options[:status], options[:content]) + end + def dispatcher Nickserver::Dispatcher.new responder end diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb index e367e06..a62c7f9 100644 --- a/test/integration/nickserver_test.rb +++ b/test/integration/nickserver_test.rb @@ -29,6 +29,7 @@ class NickserverTest < Minitest::Test def test_GET_key_by_email_address_served_via_SKS uid = 'cloudadmin@leap.se' key_id = 'E818C478D3141282F7590D29D041EB11B1647490' + stub_nicknym_available_response 'leap.se', 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 6b05f98..cb9b578 100644 --- a/test/support/http_stub_helper.rb +++ b/test/support/http_stub_helper.rb @@ -7,6 +7,11 @@ module HttpStubHelper adapter.verify end + def stub_nicknym_available_response(domain, response = {}) + stub_http_request :get, "https://#{domain}/provider.json", + response: response + end + def stub_sks_vindex_reponse(uid, response = {}) stub_http_request :get, config.hkp_url, query: {op: 'vindex', search: uid, exact: 'on', options: 'mr', fingerprint: 'on'}, @@ -28,8 +33,9 @@ module HttpStubHelper def stub_http_request(verb, url, options = {}) response = {status: 200, body: ""}.merge(options.delete(:response) || {}) + options = nil if options == {} adapter.expect :get, [response[:status], response[:body]], - [url, options] + [url, options].compact end def adapter -- cgit v1.2.3 From e1a78d46298d556b09bfcac0fa797b8e32b965d4 Mon Sep 17 00:00:00 2001 From: Azul Date: Wed, 21 Sep 2016 13:05:50 +0200 Subject: doc: explain the purpose of different integration tests --- test/integration/dispatcher_test.rb | 11 +++++++++++ test/integration/nickserver_test.rb | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb index 986972c..b3a50a0 100644 --- a/test/integration/dispatcher_test.rb +++ b/test/integration/dispatcher_test.rb @@ -1,6 +1,17 @@ require 'test_helper' require 'nickserver/dispatcher' +# +# Test integration between the Dispatcher and the RequestHandlers +# +# Starting from a given request we test the interaction between the dispatcher +# and the different RequestHandlers. There's a lot of combinations possible +# and we only test a couple of them to ensure the parts work together well. +# +# This does not test the server. We stub and mock the sources. The nickserver +# integration test covers these as well. +# + class Nickserver::DispatcherTest < Minitest::Test def test_empty_query diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb index a62c7f9..06d6e29 100644 --- a/test/integration/nickserver_test.rb +++ b/test/integration/nickserver_test.rb @@ -3,6 +3,13 @@ require 'support/http_stub_helper' require 'nickserver/server' require 'json' +# Integration Test for the whole nickserver without network dependecy. +# +# These tests are meant to test the integration between the different +# components of the nickserver from the ReelServer all the way down to +# the different sources. +# These tests do not test the low level network adapter, the daemonization +# or the startup script. # # Some important notes to understanding these tests: # -- cgit v1.2.3 From 48cdd4b1ee0685674aa998d4daa295656d80ead3 Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 Sep 2016 11:07:47 +0200 Subject: feature: 502 on ConnectionErrors If one source raises a 502 and no other handler has any result we'll respond with a 502 - bad gateway. --- lib/nickserver/dispatcher.rb | 17 ++++++++++++++++- test/integration/dispatcher_test.rb | 20 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/nickserver/dispatcher.rb b/lib/nickserver/dispatcher.rb index 75f6083..869f721 100644 --- a/lib/nickserver/dispatcher.rb +++ b/lib/nickserver/dispatcher.rb @@ -24,6 +24,7 @@ require 'nickserver/request_handlers/fingerprint_handler' module Nickserver class Dispatcher + def initialize(responder) @responder = responder end @@ -45,12 +46,26 @@ module Nickserver end def handler_chain - HandlerChain.new RequestHandlers::InvalidEmailHandler, + @handler_chain ||= init_handler_chain + end + + def init_handler_chain + chain = HandlerChain.new RequestHandlers::InvalidEmailHandler, RequestHandlers::LocalEmailHandler, RequestHandlers::LeapEmailHandler, RequestHandlers::HkpEmailHandler, RequestHandlers::FingerprintHandler, + Proc.new {|_req| proxy_error_response }, Proc.new { Nickserver::Response.new(404, "404 Not Found\n") } + chain.continue_on HTTP::ConnectionError + return chain + end + + def proxy_error_response + exception = handler_chain.rescued_exceptions.first + if exception + Nickserver::Response.new(502, exception.to_s) + end end def send_response(response) diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb index b3a50a0..4f13e6b 100644 --- a/test/integration/dispatcher_test.rb +++ b/test/integration/dispatcher_test.rb @@ -48,6 +48,20 @@ class Nickserver::DispatcherTest < Minitest::Test assert_response success end + def test_email_via_hkp_nicknym_unreachable + handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + stub_nicknym_raises + hkp_source.expect :query, success, [Nickserver::EmailAddress] + assert_response success + end + + def test_email_via_hkp_nicknym_unreachable + handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + stub_nicknym_raises + hkp_source.expect :query, nil, [Nickserver::EmailAddress] + assert_response response(status: 502, content: "HTTP::ConnectionError") + end + def test_email_via_nicknym handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } nicknym_source.expect :available_for?, true, [String] @@ -90,6 +104,12 @@ class Nickserver::DispatcherTest < Minitest::Test end end + def stub_nicknym_raises + def nicknym_source.available_for?(*_args) + raise HTTP::ConnectionError + end + end + def nicknym_source @nicknym_source ||= Minitest::Mock.new end -- cgit v1.2.3 From 1202e3b03c3bb88cd3a63dae3866167564f1d25d Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 Sep 2016 11:31:01 +0200 Subject: hand on connection errors to dispatcher so it can handle it --- lib/nickserver/nicknym/source.rb | 2 -- test/remote/nicknym_source_test.rb | 8 +++++++- test/unit/nicknym/source_test.rb | 11 ----------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/nickserver/nicknym/source.rb b/lib/nickserver/nicknym/source.rb index 0638869..45daeaf 100644 --- a/lib/nickserver/nicknym/source.rb +++ b/lib/nickserver/nicknym/source.rb @@ -8,8 +8,6 @@ module Nickserver def available_for?(domain) status, body = adapter.get "https://#{domain}/provider.json" status == 200 && provider_with_mx?(body) - rescue HTTP::ConnectionError - return false end def query(email) diff --git a/test/remote/nicknym_source_test.rb b/test/remote/nicknym_source_test.rb index c95c820..b38a991 100644 --- a/test/remote/nicknym_source_test.rb +++ b/test/remote/nicknym_source_test.rb @@ -18,8 +18,10 @@ class RemoteNicknymSourceTest < Minitest::Test end def test_availablility_check - skip unless source.available_for? 'mail.bitmask.net' + source.available_for? 'mail.bitmask.net' refute source.available_for? 'dl.bitmask.net' # not a provider + rescue HTTP::ConnectionError => e + skip e.to_s end def test_successful_query @@ -28,12 +30,16 @@ class RemoteNicknymSourceTest < Minitest::Test json = JSON.parse response.content assert_equal email_with_key.to_s, json["address"] refute_empty json["openpgp"] + rescue HTTP::ConnectionError => e + skip e.to_s end def test_not_found response = source.query(email_without_key) skip if response.status == 200 assert response.status == 404 + rescue HTTP::ConnectionError => e + skip e.to_s end protected diff --git a/test/unit/nicknym/source_test.rb b/test/unit/nicknym/source_test.rb index cddb7c2..f8c9b60 100644 --- a/test/unit/nicknym/source_test.rb +++ b/test/unit/nicknym/source_test.rb @@ -20,11 +20,6 @@ class NicknymSourceTest < Minitest::Test refute available_on?(200, 'blablabla') end - def test_failing_network_means_no_nicknym - failing_network - refute source.available_for?('remote.tld') - end - def test_proxy_successful_query assert proxies_query_response?(200, 'dummy body') end @@ -52,12 +47,6 @@ class NicknymSourceTest < Minitest::Test return available end - def failing_network - def adapter.get(*args) - raise HTTP::ConnectionError - end - end - def source Nickserver::Nicknym::Source.new(adapter) end -- cgit v1.2.3 From 68ffe9928620d3e5e3b96152ed4d37da90f6a89b Mon Sep 17 00:00:00 2001 From: Azul Date: Thu, 22 Sep 2016 12:27:53 +0200 Subject: return nil on 404 in hkp source This way the other RequestHandlers can give it a try. If none handles it we'll get a 404 anyway. But maybe there's been an exception before so a 502 should be send. --- lib/nickserver/hkp/source.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nickserver/hkp/source.rb b/lib/nickserver/hkp/source.rb index e104aa8..82c94a0 100644 --- a/lib/nickserver/hkp/source.rb +++ b/lib/nickserver/hkp/source.rb @@ -19,7 +19,7 @@ module Nickserver; module Hkp if status == 200 best = pick_best_key(response) get_key_by_fingerprint(best.keyid, nick) - else + elsif status != 404 # 404 means no key found and we proceed Nickserver::Response.new(status, response) end end -- cgit v1.2.3