22import shutil
33from pathlib import Path
44
5+ from manage .urlutils import IndexDownloader
6+ from manage .exceptions import InvalidFeedError
57from _native import verify_trust
68
79TESTDATA = Path (__file__ ).absolute ().parent / "data"
@@ -127,7 +129,6 @@ def __init__(self, url, data):
127129])
128130def test_verify_index_ok (verify_with , tmp_path , assert_log ):
129131 # All settings result in successful match
130- from manage .urlutils import IndexDownloader
131132 cmd = MockConfig ()
132133 for src , dest in [(TESTDATA / n , tmp_path / n ) for n in INDEX_NAMES ]:
133134 shutil .copy2 (src , dest )
@@ -146,8 +147,6 @@ def test_verify_index_ok(verify_with, tmp_path, assert_log):
146147])
147148def test_verify_index_wrong (verify_with , tmp_path , assert_log ):
148149 # Certs exist and verify, but don't match required settings
149- from manage .urlutils import IndexDownloader
150- from manage .exceptions import InvalidFeedError
151150 cmd = MockConfig ()
152151 for src , dest in [(TESTDATA / n , tmp_path / n ) for n in INDEX_NAMES ]:
153152 shutil .copy2 (src , dest )
@@ -172,8 +171,6 @@ def test_verify_index_wrong(verify_with, tmp_path, assert_log):
172171])
173172def test_verify_index_unsigned (verify_with , expect_fail , tmp_path , assert_log ):
174173 # No certs exist, so mostly fail due to being required
175- from manage .urlutils import IndexDownloader
176- from manage .exceptions import InvalidFeedError
177174 cmd = MockConfig ()
178175 for src , dest in [(TESTDATA / n , tmp_path / n ) for n in INDEX_NAMES ]:
179176 shutil .copy2 (src , dest )
@@ -200,7 +197,6 @@ def test_verify_index_unsigned(verify_with, expect_fail, tmp_path, assert_log):
200197])
201198def test_verify_index_selfsigned_bypass (verify_with , tmp_path , assert_log ):
202199 # Invalid cert, but user "responds" to continue
203- from manage .urlutils import IndexDownloader
204200 cmd = MockConfig ()
205201 cmd .response = False
206202 for src , dest in [(TESTDATA / n , tmp_path / n ) for n in INDEX_NAMES ]:
@@ -231,8 +227,6 @@ def test_verify_index_selfsigned_bypass(verify_with, tmp_path, assert_log):
231227])
232228def test_verify_index_selfsigned (verify_with , expect_fail , tmp_path , assert_log ):
233229 # Wrong cert returned, mostly fail due to being untrusted by OS
234- from manage .urlutils import IndexDownloader
235- from manage .exceptions import InvalidFeedError
236230 cmd = MockConfig ()
237231 for src , dest in [(TESTDATA / n , tmp_path / n ) for n in INDEX_NAMES ]:
238232 shutil .copy2 (src , dest )
@@ -250,3 +244,26 @@ def test_verify_index_selfsigned(verify_with, expect_fail, tmp_path, assert_log)
250244 else :
251245 indexes = list (idx )
252246 assert [Path (i .url ).name for i in indexes ] == INDEX_NAMES
247+
248+
249+ def test_verify_index_later (assert_log ):
250+ # Signature not required until reading the index file
251+ cmd = MockConfig ()
252+ idx = IndexDownloader (cmd , (TESTDATA / "index-require-sig.json" ).as_uri (), MockIndex )
253+ with pytest .raises (InvalidFeedError ):
254+ indexes = list (idx )
255+ assert_log (
256+ "Fetching.+" ,
257+ "The signature for %s could not be loaded." ,
258+ )
259+
260+
261+ def test_verify_index_not_later (assert_log ):
262+ # Signature not required until reading the index file
263+ cmd = MockConfig ()
264+ idx = IndexDownloader (cmd , (TESTDATA / "index-require-no-sig.json" ).as_uri (), MockIndex )
265+ indexes = list (idx )
266+ assert_log (
267+ "Fetching.+" ,
268+ "No signature to verify for %s" ,
269+ )
0 commit comments