diff options
author | Azul <azul@riseup.net> | 2016-09-21 12:48:11 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-09-21 12:48:11 +0200 |
commit | 6f507ed7b4f53054313173ce795ffd2cbcecd0b7 (patch) | |
tree | b40778b15d9ea82012d7e8330ac8dbf262f58ca2 /test/integration | |
parent | dd71240fe4f4f968b9b687917cb6d7ad5812ba48 (diff) |
feature: activate nicknym lookup
Diffstat (limited to 'test/integration')
-rw-r--r-- | test/integration/dispatcher_test.rb | 93 | ||||
-rw-r--r-- | test/integration/nickserver_test.rb | 1 |
2 files changed, 64 insertions, 30 deletions
diff --git a/test/integration/dispatcher_test.rb b/test/integration/dispatcher_test.rb index 60ad9d7..986972c 100644 --- a/test/integration/dispatcher_test.rb +++ b/test/integration/dispatcher_test.rb @@ -5,44 +5,51 @@ class Nickserver::DispatcherTest < Minitest::Test def test_empty_query handle - assert_response status: 404, content: "404 Not Found\n" + assert_response not_found end def test_invalid_query handle address: ['asdf'] - assert_response status: 500, content: "500 Not a valid address\n" + assert_response error('Not a valid address') + end + + def test_fingerprint_to_short + handle fingerprint: ['44F2F455E28'] + assert_response error("Fingerprint invalid: 44F2F455E28") + end + + def test_fingerprint_is_not_hex + handle fingerprint: ['X36E738D69173C13Z709E44F2F455E2824D18DDX'] + assert_response error("Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX") end def test_missing_domain handle address: ['valid@email.tld'] - assert_response_from_hkp + stub_nicknym_not_available + hkp_source.expect :query, success, [Nickserver::EmailAddress] + assert_response success end - def test_email_from_hkp + def test_email_via_hkp handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } - assert_response_from_hkp + stub_nicknym_not_available + hkp_source.expect :query, success, [Nickserver::EmailAddress] + assert_response success end - def test_fingerprint_to_short - handle fingerprint: ['44F2F455E28'] - assert_response status: 500, content: "500 Fingerprint invalid: 44F2F455E28\n" - end - - def test_fingerprint_is_not_hex - handle fingerprint: ['X36E738D69173C13Z709E44F2F455E2824D18DDX'] - assert_response status: 500, - content: "500 Fingerprint invalid: X36E738D69173C13Z709E44F2F455E2824D18DDX\n" + def test_email_via_nicknym + 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 end - def test_get_key_with_fingerprint_from_hkp + def test_get_key_with_fingerprint handle fingerprint: ['E36E738D69173C13D709E44F2F455E2824D18DDF'] - source = Minitest::Mock.new - source.expect :get_key_by_fingerprint, - Nickserver::Response.new(200, "fake key response"), + stub_nicknym_not_available + hkp_source.expect :get_key_by_fingerprint, success, ['E36E738D69173C13D709E44F2F455E2824D18DDF'] - Nickserver::Hkp::Source.stub :new, source do - assert_response status: 200, content: "fake key response" - end + assert_response success end protected @@ -52,20 +59,46 @@ class Nickserver::DispatcherTest < Minitest::Test @params = Hash[ params.map{ |k,v| [k.to_s, v] } ] end - def assert_response(args) - responder.expect :respond, nil, [args[:status], args[:content]] - dispatcher.respond_to @params, @headers - responder.verify + def assert_response(response) + Nickserver::Nicknym::Source.stub :new, nicknym_source do + Nickserver::Hkp::Source.stub :new, hkp_source do + responder.expect :respond, nil, [response.status, response.content] + dispatcher.respond_to @params, @headers + responder.verify + end + end + end + + def hkp_source + @hkp_source ||= Minitest::Mock.new end - def assert_response_from_hkp - source = Minitest::Mock.new - source.expect :query, Nickserver::Response.new(200, "fake content"), [Nickserver::EmailAddress] - Nickserver::Hkp::Source.stub :new, source do - assert_response status: 200, content: "fake content" + def stub_nicknym_not_available + def nicknym_source.available_for?(*_args) + false end end + def nicknym_source + @nicknym_source ||= Minitest::Mock.new + end + + def success + response status: 200, content: "fake content" + end + + def not_found + response status: 404, content: "404 Not Found\n" + end + + def error(msg) + response status: 500, content: "500 #{msg}\n" + end + + def response(options) + Nickserver::Response.new(options[:status], options[:content]) + end + def dispatcher Nickserver::Dispatcher.new responder end diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb index e367e06..a62c7f9 100644 --- a/test/integration/nickserver_test.rb +++ b/test/integration/nickserver_test.rb @@ -29,6 +29,7 @@ class NickserverTest < Minitest::Test def test_GET_key_by_email_address_served_via_SKS uid = 'cloudadmin@leap.se' key_id = 'E818C478D3141282F7590D29D041EB11B1647490' + stub_nicknym_available_response 'leap.se', status: 404 stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result)) stub_sks_get_reponse(key_id, body: file_content(:leap_public_key)) |