Skip to content

Commit 90075d3

Browse files
committed
Add tests for signature settings inside the feed
1 parent f7ca4b7 commit 90075d3

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"versions": [], "requires_signature": false}

tests/data/index-require-sig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"versions": [], "requires_signature": true}

tests/test_verify.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import shutil
33
from pathlib import Path
44

5+
from manage.urlutils import IndexDownloader
6+
from manage.exceptions import InvalidFeedError
57
from _native import verify_trust
68

79
TESTDATA = Path(__file__).absolute().parent / "data"
@@ -127,7 +129,6 @@ def __init__(self, url, data):
127129
])
128130
def 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
])
147148
def 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
])
173172
def 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
])
201198
def 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
])
232228
def 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

Comments
 (0)