diff options
author | Azul <azul@riseup.net> | 2016-06-30 13:17:08 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-06-30 13:17:08 +0200 |
commit | 7802da3d9684c5c78d34e0154f827221803b207b (patch) | |
tree | 097be5feb7bf1f2c57bed4c46fff7c0fff1c1281 | |
parent | 0491e79c4e5f16d38cf87e53290394e1eccfa2e9 (diff) |
fix host header handling and tests
-rw-r--r-- | lib/nickserver/request_handler.rb | 2 | ||||
-rw-r--r-- | test/integration/nickserver_test.rb | 21 |
2 files changed, 12 insertions, 11 deletions
diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb index a54653a..f6954f1 100644 --- a/lib/nickserver/request_handler.rb +++ b/lib/nickserver/request_handler.rb @@ -61,7 +61,7 @@ module Nickserver if host_header.nil? send_error("HTTP request must include a Host header.") else - host = host_header.split(':')[1].strip.sub(/^nicknym\./, '') + host = host_header.split(':')[0].strip.sub(/^nicknym\./, '') return uid_domain == host end end diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb index 00b2642..f30d2ba 100644 --- a/test/integration/nickserver_test.rb +++ b/test/integration/nickserver_test.rb @@ -55,7 +55,7 @@ class NickserverTest < Minitest::Test uid = "bananas@" + domain stub_couch_response(uid, status: 404) do start do - params = {query: {"address" => uid}, head: {host: domain}} + params = {query: {"address" => uid}, head: {"Host" => domain}} get(params) do |response| assert_equal 404, response.code end @@ -81,7 +81,7 @@ class NickserverTest < Minitest::Test uid = "blue@" + domain stub_couch_response(uid, body: file_content(:blue_couchdb_result)) do start do - params = {query: {"address" => uid}, head: {host: domain}} + params = {query: {"address" => uid}, head: {"Host" => domain}} get(params) do |response| assert_equal file_content(:blue_nickserver_result), response.to_s end @@ -112,15 +112,15 @@ class NickserverTest < Minitest::Test # # http GET requests to nickserver # - def get(params, &block) - request(:get, params[:query], &block) + def get(options = {}, &block) + request(:get, params: options[:query], head: options[:head], &block) end # # http POST requests to nickserver # - def post(params, &block) - request(:post, params[:body], &block) + def post(options, &block) + request(:post, params: options[:body], head: options[:head], &block) end # @@ -128,10 +128,11 @@ class NickserverTest < Minitest::Test # # this works because http requests to 127.0.0.1 are not stubbed, but requests to other domains are. # - def request(method, params) - request = HTTP.request method, "http://127.0.0.1:#{config.port}/", - params: params - yield request + def request(method, options = {}) + response = HTTP. + headers(options.delete(:head)). + request method, "http://127.0.0.1:#{config.port}/", options + yield response end end |