Skip to content

Commit

Permalink
stages(kickstart): add test for schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Nov 6, 2023
1 parent 322bf3e commit 75bfbca
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions stages/test/test_kickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest

import osbuild.meta
from osbuild.testutil.imports import import_module_from_path


Expand All @@ -30,3 +31,30 @@ 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"


def test_schema_validation():
ks_stage_path = os.path.join(os.path.dirname(__file__), "../org.osbuild.kickstart")
ks_stage = import_module_from_path("ks_stage", ks_stage_path)

name = "org.osbuild.kickstart"
version = "1"
import json
json_schema = json.loads("{"+ks_stage.SCHEMA+"}")
schema = osbuild.meta.Schema(json_schema, name)
print(schema)
test_input = {
"path": "some-path",
"users": {
"foo;rm -rf": {
"uid": 1000,
}
}
}
res = schema.validate(test_input)
assert res.valid == False
assert len(res.errors) == 1
for err in res.errors:
err_msg = err.as_dict()["message"]
assert "'foo;rm -rf' does not match any of the regexes:" in err_msg

0 comments on commit 75bfbca

Please sign in to comment.