Skip to content

Commit 2473f4e

Browse files
committed
tuf: wrap constructor in try-except as well
This way issues with initial root will also lead to TUFError Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent 58f82b8 commit 2473f4e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

sigstore/_internal/tuf.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,17 @@ def __init__(
113113
# or local metadata exists already (after "sigstore trust-instance")
114114
root_json = bootstrap_root.read_bytes() if bootstrap_root else None
115115

116-
self._updater = Updater(
117-
metadata_dir=str(self._metadata_dir),
118-
metadata_base_url=url,
119-
target_base_url=parse.urljoin(f"{url}/", "targets/"),
120-
target_dir=str(self._targets_dir),
121-
config=UpdaterConfig(app_user_agent=f"sigstore-python/{__version__}"),
122-
bootstrap=root_json,
123-
)
124-
125116
try:
117+
self._updater = Updater(
118+
metadata_dir=str(self._metadata_dir),
119+
metadata_base_url=url,
120+
target_base_url=parse.urljoin(f"{url}/", "targets/"),
121+
target_dir=str(self._targets_dir),
122+
config=UpdaterConfig(
123+
app_user_agent=f"sigstore-python/{__version__}"
124+
),
125+
bootstrap=root_json,
126+
)
126127
self._updater.refresh()
127128
except Exception as e:
128129
raise TUFError("Failed to refresh TUF metadata") from e

test/unit/internal/test_trust.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
KeyringPurpose,
3434
)
3535
from sigstore._utils import is_timerange_valid
36-
from sigstore.errors import Error
36+
from sigstore.errors import Error, TUFError
3737
from sigstore.models import (
3838
ClientTrustConfig,
3939
SigningConfig,
@@ -294,9 +294,8 @@ def range_from(offset_lower=0, offset_upper=0):
294294

295295

296296
def test_trust_root_tuf_instance_error():
297-
# Expect file not found since embedded root.json is not found and
298-
# no local metadata is found
299-
with pytest.raises(FileNotFoundError):
297+
# embedded root.json is not found and no local metadata is found
298+
with pytest.raises(TUFError):
300299
ClientTrustConfig.from_tuf("foo.bar")
301300

302301

0 commit comments

Comments
 (0)