diff options
Diffstat (limited to 'test/integration/hkp_test.rb')
-rw-r--r-- | test/integration/hkp_test.rb | 88 |
1 files changed, 31 insertions, 57 deletions
diff --git a/test/integration/hkp_test.rb b/test/integration/hkp_test.rb index bf78bb3..7d4bb6b 100644 --- a/test/integration/hkp_test.rb +++ b/test/integration/hkp_test.rb @@ -1,7 +1,9 @@ require 'test_helper' +require 'support/http_stub_helper' require 'nickserver/hkp/source' class HkpTest < Minitest::Test + include HttpStubHelper def setup super @@ -39,26 +41,31 @@ class HkpTest < Minitest::Test end def test_key_info_not_found - uid = 'leaping_lemur@leap.se' - stub_sks_vindex_reponse(uid, status: 404) - assert_response_status_for_uid uid, 404 + stubbing_http do + uid = 'leaping_lemur@leap.se' + stub_sks_vindex_reponse(uid, status: 404) + assert_response_status_for_uid uid, 404 + end end def test_no_matching_key_found - uid = 'leaping_lemur@leap.se' - stub_sks_vindex_reponse(uid, status: 200) - assert_response_status_for_uid uid, 404 + stubbing_http do + uid = 'leaping_lemur@leap.se' + stub_sks_vindex_reponse(uid, status: 200) + assert_response_status_for_uid uid, 404 + end end def test_fetch_key uid = 'cloudadmin@leap.se' key_id = 'E818C478D3141282F7590D29D041EB11B1647490' - 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'] + 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 end end @@ -66,50 +73,19 @@ class HkpTest < Minitest::Test uid = 'cloudadmin@leap.se' key_id = 'E818C478D3141282F7590D29D041EB11B1647490' - 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 + 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 + end end def test_fetch_key_too_short uid = 'chiiph@leap.se' - stub_sks_vindex_reponse(uid, body: file_content(:short_key_vindex_result)) - assert_response_status_for_uid uid, 500 - end - - # - # real network tests - # remember: must be run with REAL_NET=true - # - - def test_key_info_real_network - real_network do - uid = 'elijah@riseup.net' - assert_key_info_for_uid uid do |keys| - assert_equal 1, keys.size - assert keys.first.keyid =~ /00440025$/ - end - end - end - - def test_tls_validation_with_real_network - hkp_url = 'https://keys.mayfirst.org/pks/lookup' - ca_file = file_path('mayfirst-ca.pem') - - real_network do - config.stub(:hkp_url, hkp_url) do - config.stub(:hkp_ca_file, ca_file) do - #config.stub(:hkp_ca_file, file_path('autistici-ca.pem')) do - assert File.exist?(Nickserver::Config.hkp_ca_file) - uid = 'elijah@riseup.net' - assert_key_info_for_uid uid do |keys| - assert_equal 1, keys.size - assert keys.first.keyid =~ /00440025$/ - end - end - end + stubbing_http do + stub_sks_vindex_reponse(uid, body: file_content(:short_key_vindex_result)) + assert_response_status_for_uid uid, 500 end end @@ -134,13 +110,11 @@ class HkpTest < Minitest::Test end end - def adapter - Nickserver::Adapters::CelluloidHttp.new - end - def fetch_key_info(body_source, uid, &block) - stub_sks_vindex_reponse(uid, body: file_content(body_source)) - assert_key_info_for_uid(uid, &block) + stubbing_http do + stub_sks_vindex_reponse uid, body: file_content(body_source) + assert_key_info_for_uid(uid, &block) + end end end |