summaryrefslogtreecommitdiff
path: root/test
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
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')
-rw-r--r--test/integration/dispatcher_test.rb (renamed from test/unit/dispatcher_test.rb)0
-rw-r--r--test/unit/request_handlers/local_email_handler_test.rb65
2 files changed, 65 insertions, 0 deletions
diff --git a/test/unit/dispatcher_test.rb b/test/integration/dispatcher_test.rb
index 60d252b..60d252b 100644
--- a/test/unit/dispatcher_test.rb
+++ b/test/integration/dispatcher_test.rb
diff --git a/test/unit/request_handlers/local_email_handler_test.rb b/test/unit/request_handlers/local_email_handler_test.rb
new file mode 100644
index 0000000..8f303ec
--- /dev/null
+++ b/test/unit/request_handlers/local_email_handler_test.rb
@@ -0,0 +1,65 @@
+require 'test_helper'
+require 'nickserver/request_handlers/local_email_handler'
+
+class LocalEmailHandlerTest < MiniTest::Test
+
+ def test_no_email
+ assert_refuses
+ end
+
+ def test_remote_email
+ assert_refuses email: 'me@remote.tld', domain: 'local.tld'
+ end
+
+ def test_local_email
+ assert_handles email: 'me@local.tld', domain: 'local.tld'
+ end
+
+ def test_missing_host_header
+ Nickserver::Config.stub :domain, nil do
+ assert_responds_with_error "HTTP request must include a Host header.",
+ email: 'me@local.tld'
+ end
+ end
+
+ protected
+
+ def handler
+ Nickserver::RequestHandlers::LocalEmailHandler.new
+ end
+
+ def source
+ source = Minitest::Mock.new
+ source.expect :query,
+ 'response',
+ [Nickserver::EmailAddress]
+ source
+ end
+
+ def assert_handles(opts)
+ Nickserver::CouchDB::Source.stub :new, source do
+ assert_equal 'response', handle(request(opts))
+ end
+ end
+
+ def assert_responds_with_error(msg, opts)
+ response = handle(request(opts))
+ assert_equal 500, response.status
+ assert_equal "500 #{msg}\n", response.content
+ end
+
+ def assert_refuses(opts = {})
+ assert_nil handle(request(opts))
+ end
+
+ def handle(request)
+ handler.call(request)
+ end
+
+ def request(opts = {})
+ params = {'address' => [opts[:email]]}
+ headers = {'Host' => opts[:domain]}
+ Nickserver::Request.new params, headers
+ end
+
+end