summaryrefslogtreecommitdiff
path: root/test/integration
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration')
-rw-r--r--test/integration/dispatcher_test.rb17
-rw-r--r--test/integration/hkp_test.rb34
-rw-r--r--test/integration/nickserver_test.rb44
3 files changed, 47 insertions, 48 deletions
diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb
index 58aa972..1973e84 100644
--- a/test/integration/dispatcher_test.rb
+++ b/test/integration/dispatcher_test.rb
@@ -29,8 +29,9 @@ class Nickserver::DispatcherTest < Minitest::Test
end
def test_fingerprint_is_not_hex
- handle fingerprint: ['X36E738D69173C13Z709E44F2F455E2824D18DDX']
- assert_response error('Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX')
+ fingerprint = 'X36E738D69173C13Z709E44F2F455E2824D18DDX'
+ handle fingerprint: [fingerprint]
+ assert_response error("Fingerprint invalid: #{fingerprint}")
end
def test_missing_domain
@@ -41,28 +42,32 @@ class Nickserver::DispatcherTest < Minitest::Test
end
def test_email_via_hkp
- handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' }
+ handle address: ['valid@email.tld'],
+ headers: { 'Host' => 'http://nickserver.me' }
stub_nicknym_not_available
hkp_source.expect :query, success, [Nickserver::EmailAddress]
assert_response success
end
def test_email_via_hkp_nicknym_unreachable
- handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' }
+ 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_email_not_found_hkp_nicknym_unreachable
- handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' }
+ handle address: ['valid@email.tld'],
+ headers: { 'Host' => 'http://nickserver.me' }
stub_nicknym_raises
hkp_source.expect :query, nil, [Nickserver::EmailAddress]
assert_response http_connection_error
end
def test_email_via_nicknym
- handle address: ['valid@email.tld'], headers: { 'Host' => 'http://nickserver.me' }
+ 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
diff --git a/test/integration/hkp_test.rb b/test/integration/hkp_test.rb
index c12588c..f6675e9 100644
--- a/test/integration/hkp_test.rb
+++ b/test/integration/hkp_test.rb
@@ -33,7 +33,7 @@ class HkpTest < Minitest::Test
stubbing_http do
uid = 'leaping_lemur@leap.se'
stub_sks_vindex_reponse(uid, status: 404)
- assert_response_status_for_uid uid, 404
+ assert_nil response_for_uid(uid)
end
end
@@ -41,7 +41,7 @@ class HkpTest < Minitest::Test
stubbing_http do
uid = 'leaping_lemur@leap.se'
stub_sks_vindex_reponse(uid, status: 200)
- assert_response_status_for_uid uid, 404
+ assert_nil response_for_uid(uid)
end
end
@@ -51,10 +51,9 @@ class HkpTest < Minitest::Test
stubbing_http do
stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result))
stub_sks_get_reponse(key_id, body: file_content(:leap_public_key))
- assert_response_for_uid(uid) do |response|
- content = JSON.parse response.content
- assert_equal file_content(:leap_public_key), content['openpgp']
- end
+ response = response_for_uid(uid)
+ content = JSON.parse response.content
+ assert_equal file_content(:leap_public_key), content['openpgp']
end
end
@@ -65,7 +64,7 @@ class HkpTest < Minitest::Test
stubbing_http do
stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result))
stub_sks_get_reponse(key_id, status: 404)
- assert_response_status_for_uid uid, 404
+ assert_equal 404, response_for_uid(uid).status
end
end
@@ -74,29 +73,20 @@ class HkpTest < Minitest::Test
stubbing_http do
stub_sks_vindex_reponse(uid, body: file_content(:short_key_vindex_result))
- assert_response_status_for_uid uid, 500
+ assert_equal 500, response_for_uid(uid).status
end
end
protected
- def assert_response_status_for_uid(uid, status)
- assert_response_for_uid(uid) do |response|
- assert_equal status, response.status
- end
- end
-
- def assert_response_for_uid(uid)
- Nickserver::Hkp::Source.new(adapter).query uid do |response|
- yield response
- end
+ def response_for_uid(uid)
+ Nickserver::Hkp::Source.new(adapter).query uid
end
def assert_key_info_for_uid(uid)
- Nickserver::Hkp::Source.new(adapter).search uid do |status, keys|
- assert_equal 200, status
- yield keys
- end
+ status, keys = Nickserver::Hkp::Source.new(adapter).search uid
+ assert_equal 200, status
+ yield keys
end
def fetch_key_info(body_source, uid, &block)
diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb
index fb9b952..832a68c 100644
--- a/test/integration/nickserver_test.rb
+++ b/test/integration/nickserver_test.rb
@@ -19,13 +19,14 @@ require 'json'
# (2) We actually start the Reelserver on 127.0.0.1 and talk to it via http.
# In order to run the Reelserver properly this is a celluloid test.
#
-# (3) the "Host" header for requests to nickserver must be set (or Config.domain set)
+# (3) the "Host" header for requests to nickserver must be set
+# (or Config.domain set)
#
class NickserverTest < CelluloidTest
include HttpStubHelper
- def test_GET_key_by_email_address_served_via_SKS
+ def test_key_by_email_address_from_sks
uid = 'cloudadmin@leap.se'
key_id = 'E818C478D3141282F7590D29D041EB11B1647490'
stub_nicknym_available_response 'leap.se', status: 404
@@ -34,51 +35,43 @@ class NickserverTest < CelluloidTest
start do
params = { query: { 'address' => uid } }
- get(params) do |response|
- assert_equal file_content(:leap_public_key), JSON.parse(response.to_s)['openpgp']
- end
+ assert_responds_to params, key: :leap_public_key
end
end
- def test_GET_key_by_fingerprint_served_via_SKS
+ def test_key_by_fingerprint_from_sks
fingerprint = 'E818C478D3141282F7590D29D041EB11B1647490'
stub_sks_get_reponse(fingerprint, body: file_content(:leap_public_key))
start do
params = { query: { 'fingerprint' => fingerprint } }
- get(params) do |response|
- assert_equal file_content(:leap_public_key), JSON.parse(response.to_s)['openpgp']
- end
+ assert_responds_to params, key: :leap_public_key
end
end
- def test_GET_served_via_couch_not_found
+ def test_couch_user_not_found
domain = 'example.org'
uid = 'bananas@' + domain
stub_couch_response(uid, status: 404) do
start do
params = { query: { 'address' => uid }, head: { 'Host' => domain } }
- get(params) do |response|
- assert_equal 404, response.code
- end
+ assert_responds_to params, code: 404
end
end
end
- def test_GET_served_via_couch_empty_results
+ def test_couch_empty_results
domain = 'example.org'
uid = 'stompy@' + domain
stub_couch_response(uid, body: file_content(:empty_couchdb_result)) do
start do
params = { query: { 'address' => uid }, head: { host: domain } }
- get(params) do |response|
- assert_equal 404, response.code
- end
+ assert_responds_to params, code: 404
end
end
end
- def test_GET_served_via_couch_success
+ def test_couch_success_response
domain = 'example.org'
uid = 'blue@' + domain
stub_couch_response(uid, body: file_content(:blue_couchdb_result)) do
@@ -91,7 +84,7 @@ class NickserverTest < CelluloidTest
end
end
- def test_GET_empty
+ def test_empty_get
start do
get({}) do |response|
assert_equal "404 Not Found\n", response.to_s
@@ -113,6 +106,16 @@ class NickserverTest < CelluloidTest
server.terminate if server && server.alive?
end
+ def assert_responds_to(params, key: nil, code: nil)
+ get(params) do |response|
+ assert_equal code, response.code if code
+ if key
+ assert_equal file_content(key),
+ JSON.parse(response.to_s)['openpgp']
+ end
+ end
+ end
+
#
# http GET requests to nickserver
#
@@ -130,7 +133,8 @@ class NickserverTest < CelluloidTest
#
# http request to nickserver
#
- # this works because http requests to 127.0.0.1 are not stubbed, but requests to other domains are.
+ # this works because http requests to 127.0.0.1 are not stubbed, but
+ # requests to other domains are.
#
def request(method, options = {})
response = HTTP