Skip to content

Commit

Permalink
chore: add azurelinux 3 namespace to validation list
Browse files Browse the repository at this point in the history
Signed-off-by: Weston Steimel <[email protected]>
  • Loading branch information
westonsteimel committed Oct 3, 2024
1 parent 35f176c commit 975aba7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
16 changes: 12 additions & 4 deletions manager/src/grype_db_manager/grypedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
# however, its important to use the file for the same version of vunnel used by grype-db to build the DB, which
# isn't always possible to know. Ideally this version info would be captured in the vunnel data directory directly.
# For the meantime this is a snapshot of the expected namespaces for vunnel 0.17.2 in Oct 2023 (boo! 👻).
expected_namespaces = [
v5_additional_namespaces = [
"mariner:distro:azurelinux:3.0",
]

v4_expected_namespaces = [
"alpine:distro:alpine:3.10",
"alpine:distro:alpine:3.11",
"alpine:distro:alpine:3.12",
Expand Down Expand Up @@ -228,6 +232,12 @@
"wolfi:rolling",
]

def expected_namespaces(schema_version: int) -> list[str]:
if schema_version <= 3:
return v3_expected_namespaces
if schema_version == 4:
return v4_expected_namespaces
return v4_expected_namespaces + v5_additional_namespaces

@dataclasses.dataclass
class DBInfo:
Expand Down Expand Up @@ -288,9 +298,7 @@ def list_namespaces(self, db_uuid: str) -> list[str]:

def validate_namespaces(self, db_uuid: str) -> None:
db_info = self.get_db_info(db_uuid)

expected = v3_expected_namespaces if db_info.schema_version <= 3 else expected_namespaces

expected = expected_namespaces(db_info.schema_version)
missing_namespaces = set(expected) - set(self.list_namespaces(db_uuid=db_uuid))

if missing_namespaces:
Expand Down
14 changes: 7 additions & 7 deletions manager/tests/unit/test_grypedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ def test_new_session(self, tmp_path: pathlib.Path):
[
pytest.param([], 5, True, id="empty"),
pytest.param(["namespace1"], 5, True, id="too few namespaces"),
pytest.param(grypedb.expected_namespaces, 5, False, id="v5 matches"),
pytest.param(grypedb.expected_namespaces + ["extra_items"], 5, False, id="v5 with extra items"),
pytest.param(list(grypedb.expected_namespaces)[:-5], 5, True, id="v5 missing items"),
pytest.param(grypedb.v3_expected_namespaces, 3, False, id="v3 matches"),
pytest.param(grypedb.v3_expected_namespaces + ["extra_items"], 3, False, id="v3 with extra items"),
pytest.param(list(grypedb.v3_expected_namespaces)[:-5], 3, True, id="v3 missing items"),
pytest.param(grypedb.expected_namespaces(5), 5, False, id="v5 matches"),
pytest.param(grypedb.expected_namespaces(5) + ["extra_items"], 5, False, id="v5 with extra items"),
pytest.param(list(grypedb.expected_namespaces(5))[:-5], 5, True, id="v5 missing items"),
pytest.param(grypedb.expected_namespaces(3), 3, False, id="v3 matches"),
pytest.param(grypedb.expected_namespaces(3) + ["extra_items"], 3, False, id="v3 with extra items"),
pytest.param(list(grypedb.expected_namespaces(3))[:-5], 3, True, id="v3 missing items"),
],
)
def test_validate_namespaces(self, tmp_path: pathlib.Path, mocker, schema_version, listed_namespaces, expect_error):
assert len(grypedb.expected_namespaces) > 0
assert len(grypedb.expected_namespaces(schema_version)) > 0

dbm = grypedb.DBManager(root_dir=tmp_path.as_posix())
session_id = dbm.new_session()
Expand Down

0 comments on commit 975aba7

Please sign in to comment.