Skip to content

Commit b079e79

Browse files
committed
fix: address PR #9057 review feedback
- tests/bundle/test_bundle_download.py: assert the advisory-specific warning message (GHSA-873f-pvrv-4x83) instead of any UserWarning in test_default_warns_and_executes_config and test_run_warns_on_config_execution - tests/bundle/test_bundle_download.py: fail test_explicit_model_skips_config_parsing if load() emits a UserWarning, enforcing that the explicit-model path never parses the bundle config
1 parent 6b5fa64 commit b079e79

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

tests/bundle/test_bundle_download.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import os
1616
import tempfile
1717
import unittest
18+
import warnings
1819
from unittest.case import skipIf, skipUnless
1920
from unittest.mock import patch
2021

@@ -515,7 +516,7 @@ def test_default_warns_and_executes_config(self):
515516
with tempfile.TemporaryDirectory() as tempdir:
516517
marker = os.path.join(tempdir, "PWNED")
517518
name = self._stage_malicious_bundle(tempdir, marker)
518-
with self.assertWarns(UserWarning):
519+
with self.assertWarnsRegex(UserWarning, r"GHSA-873f-pvrv-4x83"):
519520
with self.assertRaises(AttributeError):
520521
# the malicious config is missing metadata.json and returns a plain `int` for
521522
# `network_def`, so the workflow construction fails after the payload has already
@@ -528,7 +529,9 @@ def test_explicit_model_skips_config_parsing(self):
528529
marker = os.path.join(tempdir, "PWNED")
529530
name = self._stage_malicious_bundle(tempdir, marker)
530531
model = nets.UNet(spatial_dims=2, in_channels=1, out_channels=1, channels=(4, 8), strides=(2,))
531-
load(name=name, model=model, bundle_dir=tempdir, source="github", repo="attacker/repo")
532+
with warnings.catch_warnings():
533+
warnings.simplefilter("error", UserWarning)
534+
load(name=name, model=model, bundle_dir=tempdir, source="github", repo="attacker/repo")
532535
self.assertFalse(os.path.exists(marker))
533536

534537
def test_run_warns_on_config_execution(self):
@@ -538,7 +541,7 @@ def test_run_warns_on_config_execution(self):
538541
with open(config_file, "w") as f:
539542
payload = f"$__import__('os').system({('echo pwned > ' + marker)!r})"
540543
json.dump({"initialize": [payload]}, f)
541-
with self.assertWarns(UserWarning):
544+
with self.assertWarnsRegex(UserWarning, r"GHSA-873f-pvrv-4x83"):
542545
with self.assertRaises(ValueError):
543546
# no "run" ID is defined, so `workflow.run()` fails after `initialize()` has
544547
# already evaluated the payload above.

0 commit comments

Comments
 (0)