diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/request_handler_test.rb | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/test/unit/request_handler_test.rb b/test/unit/request_handler_test.rb index ef656f9..420e74b 100644 --- a/test/unit/request_handler_test.rb +++ b/test/unit/request_handler_test.rb @@ -18,11 +18,42 @@ class Nickserver::RequestHandlerTest < Minitest::Test assert_response status: 500, content: "500 HTTP request must include a Host header.\n" end + def test_email_from_hkp + handle address: ['valid@email.tld'], headers: { "Host" => "http://nickserver.me" } + 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: "200 fake content" + end + 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" + end + + def test_get_key_with_fingerprint_from_hkp + handle fingerprint: ['E36E738D69173C13D709E44F2F455E2824D18DDF'] + source = Minitest::Mock.new + source.expect :get_key_by_fingerprint, + Nickserver::Response.new(200, "fake fingerprint"), + ['E36E738D69173C13D709E44F2F455E2824D18DDF'] + Nickserver::Hkp::Source.stub :new, source do + assert_response status: 200, content: "200 fake fingerprint" + end + end + protected - def handle(params = {}, headers = {}) + def handle(params = {}) + @headers = params.delete(:headers) || {} @params = Hash[ params.map{ |k,v| [k.to_s, v] } ] - @headers = headers end def assert_response(args) |