Skip to content
Snippets Groups Projects
Unverified Commit ec996134 authored by azul's avatar azul
Browse files

fix: no expiration date means not outdated

We were using Time.at(expirationdate) even if it was nil which
led to using the Time.at(0). Instead an unset expirationdate
is meant to not expire the key at all.

Our tests did not catch this because the assertions were in
blocks that did not get run at all. (at least in the HKP
integration test).
parent 61ebd290
Branches
No related tags found
1 merge request!20Refactor/clarify response
...@@ -49,7 +49,7 @@ module Nickserver::Hkp ...@@ -49,7 +49,7 @@ module Nickserver::Hkp
def expirationdate def expirationdate
expires = properties[4] expires = properties[4]
Time.at(expires.to_i) expires && Time.at(expires.to_i)
end end
def flags def flags
......
...@@ -33,7 +33,7 @@ class HkpTest < Minitest::Test ...@@ -33,7 +33,7 @@ class HkpTest < Minitest::Test
stubbing_http do stubbing_http do
uid = 'leaping_lemur@leap.se' uid = 'leaping_lemur@leap.se'
stub_sks_vindex_reponse(uid, status: 404) stub_sks_vindex_reponse(uid, status: 404)
assert_response_status_for_uid uid, 404 assert_nil response_for_uid(uid)
end end
end end
...@@ -41,7 +41,7 @@ class HkpTest < Minitest::Test ...@@ -41,7 +41,7 @@ class HkpTest < Minitest::Test
stubbing_http do stubbing_http do
uid = 'leaping_lemur@leap.se' uid = 'leaping_lemur@leap.se'
stub_sks_vindex_reponse(uid, status: 200) stub_sks_vindex_reponse(uid, status: 200)
assert_response_status_for_uid uid, 404 assert_nil response_for_uid(uid)
end end
end end
...@@ -51,12 +51,11 @@ class HkpTest < Minitest::Test ...@@ -51,12 +51,11 @@ class HkpTest < Minitest::Test
stubbing_http do stubbing_http do
stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result)) stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result))
stub_sks_get_reponse(key_id, body: file_content(:leap_public_key)) stub_sks_get_reponse(key_id, body: file_content(:leap_public_key))
assert_response_for_uid(uid) do |response| response = response_for_uid(uid)
content = JSON.parse response.content content = JSON.parse response.content
assert_equal file_content(:leap_public_key), content['openpgp'] assert_equal file_content(:leap_public_key), content['openpgp']
end end
end end
end
def test_fetch_key_not_found def test_fetch_key_not_found
uid = 'cloudadmin@leap.se' uid = 'cloudadmin@leap.se'
...@@ -65,7 +64,7 @@ class HkpTest < Minitest::Test ...@@ -65,7 +64,7 @@ class HkpTest < Minitest::Test
stubbing_http do stubbing_http do
stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result)) stub_sks_vindex_reponse(uid, body: file_content(:leap_vindex_result))
stub_sks_get_reponse(key_id, status: 404) 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
end end
...@@ -74,30 +73,21 @@ class HkpTest < Minitest::Test ...@@ -74,30 +73,21 @@ class HkpTest < Minitest::Test
stubbing_http do stubbing_http do
stub_sks_vindex_reponse(uid, body: file_content(:short_key_vindex_result)) 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
end end
protected protected
def assert_response_status_for_uid(uid, status) def response_for_uid(uid)
assert_response_for_uid(uid) do |response| Nickserver::Hkp::Source.new(adapter).query uid
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
end end
def assert_key_info_for_uid(uid) def assert_key_info_for_uid(uid)
Nickserver::Hkp::Source.new(adapter).search uid do |status, keys| status, keys = Nickserver::Hkp::Source.new(adapter).search uid
assert_equal 200, status assert_equal 200, status
yield keys yield keys
end end
end
def fetch_key_info(body_source, uid, &block) def fetch_key_info(body_source, uid, &block)
stubbing_http do stubbing_http do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment