From 9c918b3b8a3e709dc89d84081345f852057c8084 Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Tue, 7 Feb 2023 10:49:01 -0800 Subject: [PATCH] tests/test_openpgp: fix WKD testing Signed-off-by: Robin H. Johnson --- tests/test_openpgp.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_openpgp.py b/tests/test_openpgp.py index 0da45f1..fbbab27 100644 --- a/tests/test_openpgp.py +++ b/tests/test_openpgp.py @@ -35,6 +35,7 @@ IsolatedGPGEnvironment, PGPyEnvironment, get_wkd_url, + has_advanced_wkd, OpenPGPSignatureList, OpenPGPSignatureData, OpenPGPSignatureStatus, @@ -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: @@ -969,15 +970,16 @@ def test_refresh_wkd_fallback_to_hkp(openpgp_env_with_refresh, @pytest.mark.parametrize( - 'email,expected', - [('gemato@example.com', + 'email,has_advanced_wkd,expected', + [('gemato@example.com', False, 'https://example.com/.well-known/openpgpkey/hu/' '5x66h616iaskmnadrm86ndo6xnxbxjxb?l=gemato'), - ('Joe.Doe@Example.ORG', - 'https://example.org/.well-known/openpgpkey/hu/' + ('Joe.Doe@Example.ORG', 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