43 Commits

Author SHA1 Message Date
Iker Pedrosa
0e167e2a02 tests/system/framework/utils/tools.py: apply style fix for tuple unpacking
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2026-01-23 15:51:42 +01:00
Iker Pedrosa
a0d5a6165d tests/system/tests/test_groupmod.py: add test for groupmod -U with user list
Add comprehensive test for the groupmod -U option when provided with a
list of users to set group membership. This test verifies:

- Setting initial group membership with multiple users
- Proper membership verification in both group and gshadow entries
- Updating group membership by modifying the user list
- Correct handling of membership changes in group databases

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2026-01-01 15:44:52 +01:00
Iker Pedrosa
ce9e598fac tests/system/framework/utils/tools.py: fix GShadowEntry
GShadowEntry administrators and members represent a list of usernames,
not a single string. Thus, set them to `list[str]`. This fixes type
safety and clarifies the expected data structure.

Fixes: 458700b5d670 (2025-09-10; "tests/system/framework/: fix Python linter issues")
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2026-01-01 15:44:52 +01:00
Iker Pedrosa
07d9c2da21 tests/system/tests/test_groupadd.py: add test for groupadd -U with empty string
Test verifies that groupadd -U '' correctly creates group with no
members.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-28 21:08:51 -06:00
Iker Pedrosa
02be30544e tests/system/tests/test_groupmod.py: add test for groupmod -U with empty string
Test verifies that groupmod -U '' correctly clears group membership.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-28 21:08:51 -06:00
Iker Pedrosa
73895aa11b tests/system/tests/test_newgrp.py: change to new group
Change to a new group using `newgrp`.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-05 16:35:36 -06:00
Iker Pedrosa
3ac5c8a320 tests/system/framework/roles/shadow.py: implement binding for newgrp
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-05 16:35:36 -06:00
Iker Pedrosa
06df19464c tests/system/tests/test_groupmems.py: add user to group as root user
This is the transformation to Python of the test located in
`tests/grouptools/groupmems/01_groupmems_root_add_user/groupmems.test`,
which checks that `groupmems` is able to add a user to a group running
as the root user.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-05 16:35:36 -06:00
Iker Pedrosa
79d1e36384 tests/system/framework/roles/shadow.py: implement binding for groupmems
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-05 16:35:36 -06:00
Iker Pedrosa
6ad9c56b0d tests/system/tests/test_newusers.py: create multiple users using file input
This is the transformation to Python of the test located in
`tests/newusers/20_multiple_users/newusers.test`, which checks that
`newusers` is able to create new users from file.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-05 16:35:36 -06:00
Iker Pedrosa
32399e9584 tests/system/tests/test_newusers.py: create multiple users from stdin
This is the transformation to Python of the test located in
`tests/newusers/35_read_from_stdin/newusers.test`, which checks that
`newusers` is able to create new users from stdin.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-05 16:35:36 -06:00
Iker Pedrosa
b3d63ebabf tests/system/framework/roles/shadow.py: implement binding for newusers
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-12-05 16:35:36 -06:00
Iker Pedrosa
f385e3d915 tests/system/tests/: fix Python linter issues
Fix issues reported by flake8, pycodestyle, isort, black and mypy.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-09-10 09:56:36 +02:00
Iker Pedrosa
458700b5d6 tests/system/framework/: fix Python linter issues
Fix issues reported by flake8, pycodestyle, isort, black and mypy.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-09-10 09:56:36 +02:00
Iker Pedrosa
08028bb1a8 tests/system/pyproject.toml: add mypy rules
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-09-10 09:56:36 +02:00
Iker Pedrosa
3f03820161 tests/: test chage last changed date
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-06-02 10:16:47 +02:00
Iker Pedrosa
4b1e3ac965 tests/: test chage expiration date
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-06-02 10:16:47 +02:00
Iker Pedrosa
c657ad7a87 tests/: implement binding for chage
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-06-02 10:16:47 +02:00
Iker Pedrosa
01cbda33f6 tests/: test useradd expiration date
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-06-02 10:16:47 +02:00
Iker Pedrosa
d9c5ee0b06 tests/: test usermod expiration date
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-06-02 10:16:47 +02:00
Iker Pedrosa
7924fdb94b tests/: extend basic groupdel tests
Add additional check for gshadow entry.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
a7aa59075b tests/: extend basic groupmod test
Add additional check for gshadow entry.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
72c42f6627 tests/: extend basic groupadd test
Add additional check for gshadow entry.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
174103cb94 tests/: extend basic userdel test
Add additional checks for shadow and gshadow entries.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
1791d8a638 tests/: extend basic usermod test
Add additional checks for shadow and gshadow entries.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
d4f5397d2c tests/: extend basic useradd test
The test framework PoC only provided basic checks. I've added additional
functionality to the framework by checking shadow and gshadow entries
and I've extended the basic useradd test to check those too.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
df8c974315 tests/: improve version detection
Alpine Linux versions also contain the revision, and this needs to be
taken into account when detecting it.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
091c91fb11 tests/: improve distribution detection
openSUSE includes comment lines in `/etc/os-release` file and this can
cause some issues during the distribution detection. Ignore those lines
as they don't cause any effect on the system.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
c30e357cae tests/: enable FORCE_SHADOW in configuration
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
b56fdc329f tests/: implement days_since_epoch()
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
8e02cff475 tests/: implement feature detection
Implement a general function to detect features in shadow host.

Apparently, musl doesn't provide `getent gshadow`, but shadow still needs
it to check for several group attributes. Thus, check whether it exists
in the host, and if it does run it. If not, let's just skip that part of
the test.

Link: <https://gitlab.alpinelinux.org/alpine/aports/-/issues/16979>
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
d17e1133ee tests/: implement binding for getent gshadow $name
Provide a way for the system framework to run `getent gshadow $name` and
check its output in a meaningful way.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Iker Pedrosa
fe33ae50f7 tests/: implement binding for getent shadow $name
Provide a way for the system framework to run `getent shadow $name` and
check its output in a meaningful way.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
Reviewed-by: Dan Lavu <dlavu@redhat.com>
2025-05-21 10:04:42 +02:00
Serge Hallyn
65723c3c47 add and use a login.defs.test with CREATE_HOME set
I suspect this is not a big deal, and most distributions just ship their own
version verbatim like debian/login.defs. But if there is a distro - or even a
person - using this as is from upstream, then we dont' want to break them. So
let's undo this and use an etc/login.defs.test for the testing if needed.

Changelog: 01/13: move etc/login.defs.test to tests/system/etc/login.defs per
                  suggestion.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2025-01-14 12:09:22 +01:00
Iker Pedrosa
b3547f8f55 tests: basic group deletion
This is the transformation to Python of the test located in
`tests/grouptools/groupdel/01_groupdel_delete_group/groupdel.test`,
which checks that `groupdel` is able to delete a group.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
d4b3299324 tests: change GID of a group
This is the transformation to Python of the test located in
`tests/grouptools/groupmod/01_groupmod_change_gid/groupmod.test`, which
checks that `groupmod` is able to change the GID of a group.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
55dea3c3ad tests: basic group creation
This is the transformation to Python of the test located in
`tests/grouptools/groupadd/02_groupadd_add_group_GID_MIN/groupadd.test`,
which checks that `groupadd` is able to create a new group.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
3e9293508a tests: delete user and homedir
This is the transformation to Python of the test located in
`tests/usertools/01/18_userdel_remove_homedir.test`, which checks that
`userdel` is able to delete a user and its homedir. The test checks that
the user, the group and the home folder don't exist.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
bc2f527f09 tests: rename user
This is the transformation to Python of the test located in
`tests/usertools/01/10_usermod_rename_user.test`, which checks that
`usermod` is able to rename a user. The test checks that the new user,
the group and home folder exists.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
d1c3bf3d01 tests: recreate deleted user
This is the transformation to Python of the test located in
`tests/usertools/01/02_useradd_recreate_deleted_user.test`, which checks
that `useradd` is able to create again a removed user.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
16a797467f tests: basic user creation
This is the transformation to Python of the test located in
`tests/usertools/01/01_useradd_add_user.test`, which checks that
`useradd` is able to create a new user and its corresponding group and
home folder.

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
e4610acf53 tests: basic configuration
Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00
Iker Pedrosa
128650dfd4 Tests: implement system test framework
As discussed at length, this is the implementation of the new system
tests framework for shadow. This is a proof of concept that contains the
key elements to be able to run basic user (i.e. useradd, usermod) and
group (i.e. usermod) tests. If you like the framework the rest of the
functionality will be added in the future.

Some useful facts:
* It is implemented in python
* It is based on pytest and pytest-mh
* It works on all the distributions that are part of our CI
* It can be run in the cloud (VM or container) as well as on-premises
* After the execution of each test the environment is cleaned up
* Logs and other artifacts for failed tests are collected
* It has a rich API that can be extended and extended to cover new
  functionalities

Closes: https://github.com/shadow-maint/shadow/issues/835

Signed-off-by: Iker Pedrosa <ipedrosa@redhat.com>
2025-01-10 20:21:07 -06:00