summaryrefslogtreecommitdiff
path: root/test/integration
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-08-29 11:59:54 +0200
committerAzul <azul@riseup.net>2016-08-29 12:03:16 +0200
commit0784391a21b75ca52892e992a614b0f927ade00e (patch)
tree4efa7445db3a0521a14d75e626d64f85434a3ea5 /test/integration
parent55006b3ce5967fde08081bfd56d56f76dbaf7c53 (diff)
refactor: split EmailHandler in 3
InvalidEmailHandler - handle emails with an invalid format LocalEmailHandler - handle emails on the local domain EmailHandler - handle all other emails by using hkp This is a preparation to add leap provider email lookup and remove hkp eventually. But for now we keep the behaviour the same and only refactor.
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/dispatcher_test.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb
new file mode 100644
index 0000000..60d252b
--- /dev/null
+++ b/test/integration/dispatcher_test.rb
@@ -0,0 +1,73 @@
+require 'test_helper'
+require 'nickserver/dispatcher'
+
+class Nickserver::DispatcherTest < Minitest::Test
+
+ def test_empty_query
+ handle
+ assert_response status: 404, content: "404 Not Found\n"
+ end
+
+ def test_invalid_query
+ handle address: ['asdf']
+ assert_response status: 500, content: "500 Not a valid address\n"
+ end
+
+ def test_missing_domain
+ handle address: ['valid@email.tld']
+ assert_response status: 500, content: "500 HTTP request must include a Host header.\n"
+ end
+
+ def test_email_from_hkp
+ handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" }
+ 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: "200 fake content"
+ end
+ 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"
+ end
+
+ def test_get_key_with_fingerprint_from_hkp
+ handle fingerprint: ['E36E738D69173C13D709E44F2F455E2824D18DDF']
+ source = Minitest::Mock.new
+ source.expect :get_key_by_fingerprint,
+ Nickserver::Response.new(200, "fake fingerprint"),
+ ['E36E738D69173C13D709E44F2F455E2824D18DDF']
+ Nickserver::Hkp::Source.stub :new, source do
+ assert_response status: 200, content: "200 fake fingerprint"
+ end
+ end
+
+ protected
+
+ def handle(params = {})
+ @headers = params.delete(:headers) || {}
+ @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
+ end
+
+ def dispatcher
+ Nickserver::Dispatcher.new responder
+ end
+
+ def responder
+ @responder ||= Minitest::Mock.new
+ end
+
+end