Skip to content

Commit

Permalink
tests/test_openpgp: fix WKD testing
Browse files Browse the repository at this point in the history
Signed-off-by: Robin H. Johnson <[email protected]>
  • Loading branch information
antarus12345 authored and robbat2 committed Feb 7, 2023
1 parent 6b8ff71 commit 9c918b3
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/test_openpgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
IsolatedGPGEnvironment,
PGPyEnvironment,
get_wkd_url,
has_advanced_wkd,
OpenPGPSignatureList,
OpenPGPSignatureData,
OpenPGPSignatureStatus,
Expand Down Expand Up @@ -854,9 +855,9 @@ def hkp_server(global_hkp_server):
'VALID_PUBLIC_KEY', None),
])
def test_refresh_hkp(openpgp_env_with_refresh, hkp_server, manifest_var,
key_var, server_key_fpr, server_key_var, expected):
key_var, server_key_fpr, server_key_var, expected, monkeypatch):
"""Test refreshing against a HKP keyserver"""
# TODO: Need to mock socket.getaddrinfo to test this safely
monkeypatch.setattr(gemato.openpgp, 'has_advanced_wkd', lambda _: True)
try:
if key_var is not None:
with io.BytesIO(globals()[key_var]) as f:
Expand Down Expand Up @@ -969,15 +970,16 @@ def test_refresh_wkd_fallback_to_hkp(openpgp_env_with_refresh,


@pytest.mark.parametrize(
'email,expected',
[('[email protected]',
'email,has_advanced_wkd,expected',
[('[email protected]', False,
'https://example.com/.well-known/openpgpkey/hu/'
'5x66h616iaskmnadrm86ndo6xnxbxjxb?l=gemato'),
('[email protected]',
'https://example.org/.well-known/openpgpkey/hu/'
('[email protected]', True,
'https://openpgpkey.example.org/.well-known/openpgpkey/example.org/hu/'
'iy9q119eutrkn8s1mk4r39qejnbu3n5q?l=Joe.Doe'),
])
def test_get_wkd_url(email, expected):
def test_get_wkd_url(email, has_advanced_wkd, expected, monkeypatch):
monkeypatch.setattr(gemato.openpgp, 'has_advanced_wkd', lambda _: has_advanced_wkd)
assert get_wkd_url(email) == expected


Expand Down

0 comments on commit 9c918b3

Please sign in to comment.