summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorZara Gebru <zgebru@thoughtworks.com>2016-07-13 20:20:52 +0200
committerZara Gebru <zgebru@thoughtworks.com>2016-07-13 20:35:55 +0200
commit59263baee9fc04524c8a69af1f7293fa4315d3ff (patch)
treeb01cf32a0a95a11b3ea9bd279c2b251a1fb5b58e /test
parenta96a8f552074e8a624f1420d2f58db4e90c3762c (diff)
[FEATURE] fetch key by fingerprint
- add fingerprint unit tests - add integration test - implement by_fingerprint
Diffstat (limited to 'test')
-rw-r--r--test/integration/nickserver_test.rb14
-rw-r--r--test/unit/request_handler_test.rb22
2 files changed, 28 insertions, 8 deletions
diff --git a/test/integration/nickserver_test.rb b/test/integration/nickserver_test.rb
index 710c3a1..9aac6b4 100644
--- a/test/integration/nickserver_test.rb
+++ b/test/integration/nickserver_test.rb
@@ -26,7 +26,7 @@ class NickserverTest < Minitest::Test
super
end
- def test_GET_served_via_SKS
+ def test_GET_key_by_email_address_served_via_SKS
uid = 'cloudadmin@leap.se'
key_id = 'E818C478D3141282F7590D29D041EB11B1647490'
stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result))
@@ -40,15 +40,13 @@ class NickserverTest < Minitest::Test
end
end
- def test_POST_served_via_SKS
- 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))
+ def test_GET_key_by_fingerprint_served_via_SKS
+ fingerprint = 'E818C478D3141282F7590D29D041EB11B1647490'
+ stub_sks_get_reponse(fingerprint, body: file_content(:leap_public_key))
start do
- params = {body: {"address" => uid}}
- post(params) do |response|
+ params = {query: {"fingerprint" => fingerprint}}
+ get(params) do |response|
assert_equal file_content(:leap_public_key), JSON.parse(response.to_s)["openpgp"]
end
end
diff --git a/test/unit/request_handler_test.rb b/test/unit/request_handler_test.rb
index 11cc59b..420e74b 100644
--- a/test/unit/request_handler_test.rb
+++ b/test/unit/request_handler_test.rb
@@ -27,6 +27,28 @@ class Nickserver::RequestHandlerTest < Minitest::Test
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 = {})