summaryrefslogtreecommitdiff
path: root/test/support
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-08-29 12:51:00 +0200
committerAzul <azul@riseup.net>2016-08-30 08:25:16 +0200
commitcd1bbe970ca17034b0e380ff2996542e3af81e31 (patch)
tree6090adda14bee5443d164a13f8f499ae92c3ed73 /test/support
parent6e2d31e3f7c515f65d92533bcdb035438461a00c (diff)
feature: keep trying if no Host header given
So far we would error out if no host was specified in the config or the request. It's true that we can't do local lookup if we don't know our own domain. However we can still use HKP. In the future we will query leaps own API for other providers. If the host was not set in the initial request we might even proxy a request to ourselves. Providing the Host header will prevent an infinite loop in that case.
Diffstat (limited to 'test/support')
-rw-r--r--test/support/request_handler_test_helper.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/support/request_handler_test_helper.rb b/test/support/request_handler_test_helper.rb
new file mode 100644
index 0000000..3ca89ba
--- /dev/null
+++ b/test/support/request_handler_test_helper.rb
@@ -0,0 +1,39 @@
+module RequestHandlerTestHelper
+
+ protected
+
+ def assert_refuses(opts = {})
+ assert_nil handle(request(opts))
+ end
+
+ def assert_handles(opts = {})
+ assert handle(request(opts))
+ end
+
+ def assert_queries_for(*query_args, &block)
+ source_class.stub :new, source_expecting_query_for(*query_args), &block
+ end
+
+ def source_expecting_query_for(*query_args)
+ source = Minitest::Mock.new
+ source.expect :query, 'response', query_args
+ source
+ 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 handle(request)
+ handler.call(request)
+ end
+
+ def request(opts = {})
+ params = {'address' => [opts[:email]]}
+ headers = {'Host' => opts[:domain]}
+ Nickserver::Request.new params, headers
+ end
+
+end