Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F24929151
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/_tests/pillar/core/test_users.py b/_tests/pillar/core/test_users.py
index 72bb3d9..1454143 100755
--- a/_tests/pillar/core/test_users.py
+++ b/_tests/pillar/core/test_users.py
@@ -1,40 +1,78 @@
#!/usr/bin/env python3
import unittest
import yaml
PILLAR_FILE = "../pillar/core/users.sls"
-USER_PROPERTIES_MANDATORY = set(["fullname", "ssh_keys", "uid"])
-USER_PROPERTIES_OPTIONAL = set(["class", "shell", "yubico_keys", "devserver_tasks"])
+USER_PROPERTIES_MANDATORY = set(
+ [
+ "fullname",
+ "uid",
+ ]
+)
+USER_PROPERTIES_OPTIONAL = set(
+ [
+ "class",
+ "devserver_tasks",
+ "everywhere_tasks",
+ "shell",
+ "yubico_keys",
+ ]
+)
+
+USER_PROPERTIES_AT_LEAST_ONE_OF_MANDATORY = [
+ set(
+ [
+ "ssh_keys",
+ "ssh_keys_by_forest",
+ ]
+ ),
+]
+
+for keys in USER_PROPERTIES_AT_LEAST_ONE_OF_MANDATORY:
+ USER_PROPERTIES_OPTIONAL.update(keys)
class Testinstance(unittest.TestCase):
def setUp(self):
with open(PILLAR_FILE, "r") as fd:
self.pillar = yaml.safe_load(fd)
# users must have a username, an UID and SSH keys
def test_users_properties(self):
is_valid = True
errors = []
for user, properties in self.pillar["shellusers"].items():
missing_properties = USER_PROPERTIES_MANDATORY - set(properties)
if missing_properties:
errors.append(f" Missing properties for {user}: {missing_properties}")
is_valid = False
invalid_properties = (
set(properties) - USER_PROPERTIES_MANDATORY - USER_PROPERTIES_OPTIONAL
)
if invalid_properties:
errors.append(f" Invalid properties for {user}: {invalid_properties}")
is_valid = False
+ for keys_group in USER_PROPERTIES_AT_LEAST_ONE_OF_MANDATORY:
+ key_found = False
+ for key in keys_group:
+ if key in properties:
+ key_found = True
+ break
+
+ if not key_found:
+ errors.append(
+ f" Missing properties for {user}: at least one of {keys_group}"
+ )
+ is_valid = False
+
self.assertTrue(is_valid, "\n" + "\n".join(errors))
if __name__ == "__main__":
unittest.main()
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Mar 21, 07:28 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3545974
Default Alt Text
(2 KB)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment