mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-17 06:25:07 +00:00
fix: drop null vault keys, cap snapshot restore size, isolate test globals
Vaults.add_keys and kv add skip null content keys instead of failing the batch; is_null_key moves to core.vault. A manifest snapshot restore has one 32 MiB inflate budget. Tests reset the speed limiter and config between runs.
This commit is contained in:
@@ -17,7 +17,8 @@ from uuid import UUID
|
||||
|
||||
import pytest
|
||||
|
||||
from unshackle.core.vault import Vault
|
||||
from unshackle.core.vault import Vault, is_null_key
|
||||
from unshackle.core.vaults import Vaults
|
||||
from unshackle.vaults.SQLite import SQLite
|
||||
|
||||
LOG = logging.getLogger("kv-test")
|
||||
@@ -119,10 +120,29 @@ def test_synced_lowercase_table_survives_the_service_being_added_later(tmp_path:
|
||||
assert len(list(v.get_keys("SVCC"))) == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("key", "expected"),
|
||||
[
|
||||
(None, True),
|
||||
("", True),
|
||||
("0" * 32, True),
|
||||
("00", True),
|
||||
("00112233445566778899aabbccddeeff", False),
|
||||
("00112233445566778899AABBCCDDEEFF", False),
|
||||
],
|
||||
)
|
||||
def test_is_null_key(key: Optional[str], expected: bool) -> None:
|
||||
assert is_null_key(key) is expected
|
||||
|
||||
|
||||
def test_null_keys_are_rejected_and_filtered(tmp_path: Path) -> None:
|
||||
v = SQLite("test", tmp_path / "kv.db")
|
||||
with pytest.raises(ValueError):
|
||||
v.add_keys("SVCA", {KID: "0" * 32})
|
||||
null_key_error = r"^You cannot add a NULL Content Key to a Vault\.$"
|
||||
for key in ("0" * 32, ""):
|
||||
with pytest.raises(ValueError, match=null_key_error):
|
||||
v.add_keys("SVCA", {KID: key})
|
||||
with pytest.raises(ValueError, match=null_key_error):
|
||||
v.add_key("SVCA", KID, key)
|
||||
|
||||
v.create_table("svca")
|
||||
conn = sqlite3.connect(v.path)
|
||||
@@ -134,6 +154,15 @@ def test_null_keys_are_rejected_and_filtered(tmp_path: Path) -> None:
|
||||
assert list(v.get_keys("SVCA")) == []
|
||||
|
||||
|
||||
def test_vaults_push_drops_null_keys_and_keeps_the_rest(tmp_path: Path) -> None:
|
||||
vaults = Vaults("SVCA")
|
||||
vaults.vaults = [SQLite("test", tmp_path / "kv.db")]
|
||||
other_kid = "0" * 31 + "2"
|
||||
assert vaults.add_keys({KID: KEY, other_kid: "0" * 32}) == 1
|
||||
assert vaults.vaults[0].get_key(KID, "SVCA") == KEY
|
||||
assert vaults.vaults[0].get_key(other_kid, "SVCA") is None
|
||||
|
||||
|
||||
def test_get_services_yields_stored_table_names(vault: SQLite, aliased_service: str) -> None:
|
||||
"""Names are yielded verbatim. Normalising the `svcdalias` table to the installed SVCD
|
||||
tag would hand back a name that addresses no table at all."""
|
||||
|
||||
Reference in New Issue
Block a user