QTZPOC-20
QTZPOC-20: Simplify base64 decoding error handling and improve run name derivation test specificity
This commit is contained in:
@@ -16,7 +16,6 @@ used as a metric label or written to the import record.
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
from typing import Final
|
||||
|
||||
from cryptography.exceptions import InvalidTag
|
||||
@@ -55,7 +54,7 @@ def load_envelope_key(raw_key: str | None) -> bytes:
|
||||
raise EnvelopeError('the import password key is not configured')
|
||||
try:
|
||||
key = base64.b64decode(raw_key, validate=True)
|
||||
except (binascii.Error, ValueError) as error:
|
||||
except ValueError as error:
|
||||
raise EnvelopeError('the import password key is not valid base64') from error
|
||||
if len(key) != KEY_SIZE:
|
||||
raise EnvelopeError(f'the import password key must be {KEY_SIZE} bytes')
|
||||
@@ -80,7 +79,7 @@ def decrypt_password_envelope(envelope: str, key: bytes) -> str:
|
||||
raise EnvelopeError('the import request carries no password envelope')
|
||||
try:
|
||||
payload = base64.b64decode(envelope, validate=True)
|
||||
except (binascii.Error, ValueError) as error:
|
||||
except ValueError as error:
|
||||
raise EnvelopeError('the password envelope is not valid base64') from error
|
||||
if len(payload) < MIN_ENVELOPE_SIZE:
|
||||
raise EnvelopeError('the password envelope is too short to hold a nonce and a tag')
|
||||
|
||||
@@ -193,7 +193,7 @@ def test_run_name_survives_a_version_that_leaves_no_room():
|
||||
|
||||
|
||||
def test_run_name_is_deterministic():
|
||||
assert derive_run_name('model', '4') == derive_run_name('model', '4')
|
||||
assert derive_run_name('model', '4') == 'import-model-v4'
|
||||
|
||||
|
||||
def test_run_name_is_never_shorter_than_the_column_floor():
|
||||
|
||||
Reference in New Issue
Block a user