Skip to content

Commit

Permalink
fixup! WIP for schema exclusion of pbkdf-iterations/pbkdf-time
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 8, 2023
1 parent c4afe19 commit 6f86dea
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
30 changes: 22 additions & 8 deletions stages/org.osbuild.kickstart
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,30 @@ SCHEMA = r"""
"pbkdf-memory": {
"description": "Sets the memory cost for PBKDF",
"type": "integer"
}
},
"oneOf": [
{
"required": ["pbkdf-time"],
"not": {"required": ["pbkdf-iterations"]},
"properties": {
"pbkdf-time": {
"description": "Sets the number of milliseconds to spend with PBKDF passphrase processing",
"type": "integer"
}
}
},
"pbkdf-time": {
"description": "Sets the number of milliseconds to spend with PBKDF passphrase processing",
"type": "integer"
},
"pbkdf-iterations": {
"description": "Sets the number of iterations for passphrase processing directly",
"type": "integer"
{
"required": ["pbkdf-iterations"],
"not": {"required": ["pbkdf-time"]},
"properties": {
"pbkdf-iterations": {
"description": "Sets the number of iterations for passphrase processing directly",
"type": "integer"
}
}
}
}
]
}
}
"""
Expand Down
34 changes: 33 additions & 1 deletion stages/test/test_kickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from osbuild.testutil.imports import import_module_from_path

import osbuild.meta

@pytest.mark.parametrize("test_input,expected", [
({"lang": "en_US.UTF-8"}, "lang en_US.UTF-8"),
Expand Down Expand Up @@ -34,3 +34,35 @@ def test_kickstart(tmp_path, test_input, expected):
with open(os.path.join(tmp_path, ks_path), encoding="utf-8") as fp:
ks_content = fp.read()
assert ks_content == expected + "\n"


@pytest.mark.parametrize("test_data,expected_err", [
({"autopart": {"pkdf-time": 1xb}}, ""),
({"autopart": {"pkdf-iterations": 1}}, ""),
({"autopart": {"pkdf-time": 1, "pdf-iterations": 2}}, " is not valid "),
])
def test_schema_validation_smoke(test_data, expected_err):
name = "org.osbuild.kickstart"
root = os.path.join(os.path.dirname(__file__), "../..")
mod_info = osbuild.meta.ModuleInfo.load(root, "Stage", name)
schema = osbuild.meta.Schema(mod_info.get_schema(), name)

test_input = {
"name": "org.osbuild.kickstart",
"options": {
"path": "some-path",
}
}
test_input["options"].update(test_data)
res = schema.validate(test_input)

if expected_err == "":
# debug
if not res.valid:
print([e.as_dict() for e in res.errors])
assert res.valid is True
else:
assert res.valid is False
assert len(res.errors) == 1
err_msgs = [e.as_dict()["message"] for e in res.errors]
assert expected_err in err_msgs[0]

0 comments on commit 6f86dea

Please sign in to comment.