Skip to content

Commit 4e0c108

Browse files
committed
Log settings used for feeds with own settings
1 parent 90075d3 commit 4e0c108

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

src/manage/urlutils.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -683,9 +683,29 @@ def urlopen_index(self, url):
683683
)
684684
raise
685685

686-
def verify(self, previous_verified, url, data, params):
687-
if previous_verified is not None or not params or not params.get("requires_signature"):
688-
return previous_verified
686+
def verify(self, url, data, params, show_settings=False):
687+
if not params or not params.get("requires_signature"):
688+
return None
689+
690+
if show_settings:
691+
relevant_params = {k: params[k] for k in [
692+
"requires_signature",
693+
"required_root_subject",
694+
"required_publisher_subject",
695+
"required_publisher_eku",
696+
] if k in params}
697+
if relevant_params:
698+
LOGGER.info("Using verification settings from the index.")
699+
LOGGER.info(
700+
"Check the log file or verbose output for the settings "
701+
"being used. Copying these into your configuration "
702+
"file's !G!'source_settings'!W! section to detect "
703+
"changes."
704+
)
705+
LOGGER.verbose(
706+
"Verifying with the below settings.\n%r",
707+
{sanitise_url(url): relevant_params}
708+
)
689709

690710
try:
691711
cat = self._cache[url + ".cat"]
@@ -767,12 +787,13 @@ def __next__(self):
767787
)
768788
raise
769789

770-
source_settings = (self.cmd.source_settings if self.cmd else None) or {}
771-
verified = self.verify(verified, url, data, source_settings.get(s_url))
790+
source_settings = self.cmd.source_settings.get(s_url) if self.cmd else None
791+
verified = self.verify(url, data, source_settings)
772792
parsed = json.loads(data)
773793

774794
# The parsed index may also have its own verification parameters
775-
verified = self.verify(verified, url, data, parsed)
795+
if not source_settings and not verified:
796+
verified = self.verify(url, data, parsed, show_settings=True)
776797

777798
if verified is True:
778799
LOGGER.info("!G!The signature for %s was successfully verified.!W!", s_url)

tests/data/index-require-sig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{"versions": [], "requires_signature": true}
1+
{
2+
"versions": [],
3+
"requires_signature": true,
4+
"required_publisher_subject": "CN=King Arthur, O=Knights of the Round Table, C=Camelot"
5+
}

tests/test_verify.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,38 @@ def test_verify_index_selfsigned(verify_with, expect_fail, tmp_path, assert_log)
249249
def test_verify_index_later(assert_log):
250250
# Signature not required until reading the index file
251251
cmd = MockConfig()
252-
idx = IndexDownloader(cmd, (TESTDATA / "index-require-sig.json").as_uri(), MockIndex)
252+
u = (TESTDATA / "index-require-sig.json").as_uri()
253+
expect_settings = {
254+
u: {
255+
"requires_signature": True,
256+
"required_publisher_subject": "CN=King Arthur, O=Knights of the Round Table, C=Camelot",
257+
}
258+
}
259+
idx = IndexDownloader(cmd, u, MockIndex)
253260
with pytest.raises(InvalidFeedError):
254261
indexes = list(idx)
255262
assert_log(
256263
"Fetching.+",
264+
"Using verification settings from the index.",
265+
"Check the log file.+",
266+
("Verifying with the below settings.+", [expect_settings]),
257267
"The signature for %s could not be loaded.",
258268
)
259269

260270

271+
def test_verify_index_overridden_later(assert_log):
272+
# Signature not required until reading the index file
273+
cmd = MockConfig()
274+
u = (TESTDATA / "index-require-sig.json").as_uri()
275+
cmd.source_settings[u] = {"requires_signature": False}
276+
idx = IndexDownloader(cmd, u, MockIndex)
277+
indexes = list(idx)
278+
assert_log(
279+
"Fetching.+",
280+
"No signature to verify for %s",
281+
)
282+
283+
261284
def test_verify_index_not_later(assert_log):
262285
# Signature not required until reading the index file
263286
cmd = MockConfig()

0 commit comments

Comments
 (0)