summaryrefslogtreecommitdiff
path: root/test/integration
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2016-09-23 06:45:18 +0000
committerazul <azul@riseup.net>2016-09-23 06:45:18 +0000
commit6721f0732facd87404eecc288357fd1bd0de48cf (patch)
tree58b0f80b545987d5fc7f3dfdd4a3c1563cbc216e /test/integration
parente2aedcaade71dfe9103fdc8e705f59ece5f3a4d0 (diff)
parent68ffe9928620d3e5e3b96152ed4d37da90f6a89b (diff)
Merge branch 'feature/deal-with-network-failures' into 'master'
Feature/deal with network failures Also activates the new nicknym lookup. See merge request !5
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/dispatcher_test.rb120
-rw-r--r--test/integration/nickserver_test.rb8
2 files changed, 100 insertions, 28 deletions
diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb
index 60ad9d7..4f13e6b 100644
--- a/test/integration/dispatcher_test.rb
+++ b/test/integration/dispatcher_test.rb
@@ -1,48 +1,80 @@
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
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"
+ 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_fingerprint_is_not_hex
- handle fingerprint: ['X36E738D69173C13Z709E44F2F455E2824D18DDX']
- assert_response status: 500,
- content: "500 Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX\n"
+ 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]
+ 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 +84,52 @@ 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 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 hkp_source
+ @hkp_source ||= Minitest::Mock.new
+ end
+
+ def stub_nicknym_not_available
+ def nicknym_source.available_for?(*_args)
+ false
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
+
+ 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..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:
#
@@ -29,6 +36,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))