|
| 1 | +""" |
| 2 | +Test vipw |
| 3 | +""" |
| 4 | + |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from framework.roles.shadow import Shadow |
| 10 | +from framework.topology import KnownTopology |
| 11 | + |
| 12 | + |
| 13 | +@pytest.mark.topology(KnownTopology.Shadow) |
| 14 | +def test_vipw__add_user_to_passwd(shadow: Shadow): |
| 15 | + """ |
| 16 | + :title: Run vipw on passwd file and add a user |
| 17 | + :setup: |
| 18 | + :steps: |
| 19 | + 1. Run vipw and add a user entry in passwd |
| 20 | + 2. Check the user's passwd entry |
| 21 | + :expectedresults: |
| 22 | + 1. vipw runs successfully |
| 23 | + 2. User's passwd entry is correct |
| 24 | + :customerscenario: False |
| 25 | + """ |
| 26 | + editor_script = "Go\ntuser:x:1000:1000::/home/tuser:/bin/bash\n:wq" |
| 27 | + shadow.vipw(editor_script=editor_script) |
| 28 | + |
| 29 | + passwd_entry = shadow.tools.getent.passwd("tuser") |
| 30 | + assert passwd_entry is not None, "User should be found" |
| 31 | + assert passwd_entry.name == "tuser", "Incorrect username" |
| 32 | + assert passwd_entry.password == "x", "Incorrect password" |
| 33 | + assert passwd_entry.uid == 1000, "Incorrect UID" |
| 34 | + assert passwd_entry.gid == 1000, "Incorrect GID" |
| 35 | + assert passwd_entry.home == "/home/tuser", "Incorrect home" |
| 36 | + assert passwd_entry.shell == "/bin/bash", "Incorrect shell" |
| 37 | + |
| 38 | + |
| 39 | +@pytest.mark.topology(KnownTopology.Shadow) |
| 40 | +def test_vipw__add_user_to_shadow(shadow: Shadow): |
| 41 | + """ |
| 42 | + :title: Run vipw on shadow file and add a user |
| 43 | + :setup: |
| 44 | + :steps: |
| 45 | + 1. Run vipw and add a user entry in shadow |
| 46 | + 2. Check the user's shadow entry |
| 47 | + :expectedresults: |
| 48 | + 1. vipw runs successfully |
| 49 | + 2. User's shadow entry is correct |
| 50 | + :customerscenario: False |
| 51 | + """ |
| 52 | + editor_script = "Go\ntuser:!:20342:0:99999:7:::\n:wq!" |
| 53 | + shadow.vipw("-s", editor_script=editor_script) |
| 54 | + |
| 55 | + shadow_entry = shadow.tools.getent.shadow("tuser") |
| 56 | + assert shadow_entry is not None, "User should be found" |
| 57 | + assert shadow_entry.name == "tuser", "Incorrect username" |
| 58 | + assert shadow_entry.password is not None, "Password should not be None" |
| 59 | + assert shadow_entry.password == "!", "Incorrect password" |
| 60 | + assert shadow_entry.last_changed == 20342, "Incorrect last changed" |
| 61 | + assert shadow_entry.min_days == 0, "Incorrect min days" |
| 62 | + assert shadow_entry.max_days == 99999, "Incorrect max days" |
| 63 | + assert shadow_entry.warn_days == 7, "Incorrect warn days" |
| 64 | + |
| 65 | + |
| 66 | +@pytest.mark.topology(KnownTopology.Shadow) |
| 67 | +def test_vipw__add_group_to_group(shadow: Shadow): |
| 68 | + """ |
| 69 | + :title: Run vipw on group file and add a group |
| 70 | + :setup: |
| 71 | + :steps: |
| 72 | + 1. Run vipw and add a group entry in group |
| 73 | + 2. Check the group's group entry |
| 74 | + :expectedresults: |
| 75 | + 1. vipw runs successfully |
| 76 | + 2. Group's shadow group is correct |
| 77 | + :customerscenario: False |
| 78 | + """ |
| 79 | + editor_script = "Go\ntgroup:x:1000:\n:wq" |
| 80 | + shadow.vipw("-g", editor_script=editor_script) |
| 81 | + |
| 82 | + group_entry = shadow.tools.getent.group("tgroup") |
| 83 | + assert group_entry is not None, "Group should be found" |
| 84 | + assert group_entry.name == "tgroup", "Incorrect groupname" |
| 85 | + assert group_entry.gid == 1000, "Incorrect GID" |
| 86 | + |
| 87 | + |
| 88 | +@pytest.mark.topology(KnownTopology.Shadow) |
| 89 | +@pytest.mark.builtwith(shadow="gshadow") |
| 90 | +def test_vipw__add_group_to_gshadow(shadow: Shadow): |
| 91 | + """ |
| 92 | + :title: Run vipw on gshadow file and add a group |
| 93 | + :setup: |
| 94 | + :steps: |
| 95 | + 1. Run vipw and add a gshadow entry in group |
| 96 | + 2. Check the group's gshadow entry |
| 97 | + :expectedresults: |
| 98 | + 1. vipw runs successfully |
| 99 | + 2. Group's shadow gshadow is correct |
| 100 | + :customerscenario: False |
| 101 | + """ |
| 102 | + editor_script = "Go\ntgroup:!::\n:wq!" |
| 103 | + shadow.vipw("-gs", editor_script=editor_script) |
| 104 | + |
| 105 | + gshadow_entry = shadow.tools.getent.gshadow("tgroup") |
| 106 | + assert gshadow_entry is not None, "Group should be found" |
| 107 | + assert gshadow_entry.name == "tgroup", "Incorrect groupname" |
| 108 | + assert gshadow_entry.password == "!", "Incorrect password" |
0 commit comments