states(users): move to schema_2 to allow adding mounts/devices
This is a preparation to allow adding mounts/devices to the users stage so that we can eventually support bootc install to-filesystem. It also adds some smoke tests for the schema to ensure it's still valid.
This commit is contained in:
parent
35fbf6a377
commit
72a2334fbe
2 changed files with 81 additions and 54 deletions
|
|
@ -9,62 +9,64 @@
|
|||
"inside a chroot to ensure that a home dir exists for the user, as `usermod`",
|
||||
"does not create it (it will move existing dirs though)."
|
||||
],
|
||||
"schema": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"users": {
|
||||
"additionalProperties": false,
|
||||
"type": "object",
|
||||
"description": "Keys are usernames, values are objects giving user info.",
|
||||
"patternProperties": {
|
||||
"^[A-Za-z0-9_.][A-Za-z0-9_.-]{0,31}$": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uid": {
|
||||
"description": "User UID",
|
||||
"type": "number"
|
||||
},
|
||||
"gid": {
|
||||
"description": "User GID",
|
||||
"type": "number"
|
||||
},
|
||||
"groups": {
|
||||
"description": "Array of group names for this user",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"schema_2": {
|
||||
"options": {
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"users": {
|
||||
"additionalProperties": false,
|
||||
"type": "object",
|
||||
"description": "Keys are usernames, values are objects giving user info.",
|
||||
"patternProperties": {
|
||||
"^[A-Za-z0-9_.][A-Za-z0-9_.-]{0,31}$": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uid": {
|
||||
"description": "User UID",
|
||||
"type": "number"
|
||||
},
|
||||
"gid": {
|
||||
"description": "User GID",
|
||||
"type": "number"
|
||||
},
|
||||
"groups": {
|
||||
"description": "Array of group names for this user",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"description": "User account description (or full name)",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"description": {
|
||||
"description": "User account description (or full name)",
|
||||
"type": "string"
|
||||
},
|
||||
"home": {
|
||||
"description": "Path to user's home directory",
|
||||
"type": "string"
|
||||
},
|
||||
"shell": {
|
||||
"description": "User's login shell",
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"description": "User's encrypted password, as returned by crypt(3)",
|
||||
"type": "string"
|
||||
},
|
||||
"key": {
|
||||
"description": "SSH Public Key to add to ~/.ssh/authorized_keys",
|
||||
"type": "string"
|
||||
},
|
||||
"keys": {
|
||||
"description": "Array of SSH Public Keys to add to ~/.ssh/authorized_keys",
|
||||
"type": "array",
|
||||
"items": {
|
||||
},
|
||||
"home": {
|
||||
"description": "Path to user's home directory",
|
||||
"type": "string"
|
||||
},
|
||||
"shell": {
|
||||
"description": "User's login shell",
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"description": "User's encrypted password, as returned by crypt(3)",
|
||||
"type": "string"
|
||||
},
|
||||
"key": {
|
||||
"description": "SSH Public Key to add to ~/.ssh/authorized_keys",
|
||||
"type": "string"
|
||||
},
|
||||
"keys": {
|
||||
"description": "Array of SSH Public Keys to add to ~/.ssh/authorized_keys",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"expiredate": {
|
||||
"description": "The date on which the user account will be disabled. This date is represented as a number of days since January 1st, 1970.",
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"expiredate": {
|
||||
"description": "The date on which the user account will be disabled. This date is represented as a number of days since January 1st, 1970.",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,35 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
from osbuild.testutil import make_fake_tree, mock_command
|
||||
from osbuild.testutil import assert_jsonschema_error_contains, make_fake_tree, mock_command
|
||||
|
||||
|
||||
STAGE_NAME = "org.osbuild.users"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("test_data,expected_err", [
|
||||
# bad
|
||||
({"users": {"!invalid-name": {}}}, "'!invalid-name' does not match any of the regex"),
|
||||
({"users": {"foo": {"home": 0}}}, "0 is not of type 'string'"),
|
||||
# good
|
||||
({}, ""),
|
||||
({"users": {"foo": {}}}, ""),
|
||||
])
|
||||
def test_schema_validation(stage_schema, test_data, expected_err):
|
||||
test_input = {
|
||||
"type": STAGE_NAME,
|
||||
"options": {},
|
||||
}
|
||||
test_input["options"].update(test_data)
|
||||
res = stage_schema.validate(test_input)
|
||||
|
||||
if expected_err == "":
|
||||
assert res.valid is True, f"err: {[e.as_dict() for e in res.errors]}"
|
||||
else:
|
||||
assert res.valid is False
|
||||
assert_jsonschema_error_contains(res, expected_err, expected_num_errs=1)
|
||||
|
||||
|
||||
TEST_CASES = [
|
||||
# user_opts,expected commandline args
|
||||
({}, []),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue