188 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
Tobias Stoeckmann
bbdfa2d66b tests: Fix typos in comments
No functional change

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-12-19 16:48:08 +01:00
Tobias Stoeckmann
876e874684 Fix documentation style
Always start a sentence with lowercase letter after 'Note:', 'Warning:',
etc. This unifies all occurrences.

No functional change.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-12-19 16:48:08 +01:00
Tobias Stoeckmann
fd4a810504 newusers: Add test for creation without aging
If PASS_MAX_DAYS is not set, newusers should not set max password age.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-12-15 14:51:28 +01:00
Alejandro Colomar
0d9193dcf6 lib/: Rename XMALLOC() => xmalloc_T()
The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 21:22:45 -06:00
Alejandro Colomar
0afe216953 lib/: Rename MALLOC() => malloc_T()
The 'T' in the name notes that this API is a type-safe variant of the
API it wraps.  This makes the names more explicative.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 21:22:45 -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
Alejandro Colomar
9e711e2240 lib/, src/ tests/: Unname unused parameters in callbacks
[Serge: preference to keep the names as a comment, but ok]
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-12-05 09:21:50 -06:00
Alejandro Colomar
aee5c0f4f0 tests/unit/: Unname unused parameters in callbacks
This silences diagnostics about unused parameters.

Tested-by: Silvan Mosberger <github@infinisil.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-28 08:41:54 -06:00
Alejandro Colomar
15aa496900 tests/unit/test_xaprintf.c: Use assert_string_equal()
This produces more useful test results.

With assert_true(streq(...)), we only see the line of code that
triggered the failure, while assert_string_equal() shows the contents
of the strings.  See the following example:

	alx@devuan:~/tmp$ cat cmocka.c
	#include <string.h>

	#include <stdarg.h>
	#include <stddef.h>
	#include <setjmp.h>
	#include <stdint.h>
	#include <cmocka.h>

	#define streq(a,b)  (!strcmp(a,b))

	static void a(void **)
	{
		const char *s = "foo";

		assert_true(streq(s, "bar"));
	}

	static void b(void **)
	{
		const char *s = "foo";

		assert_string_equal(s, "bar");
	}

	int
	main(void)
	{

		const struct CMUnitTest tests[] = {
			cmocka_unit_test(a),
			cmocka_unit_test(b),
		};

		return cmocka_run_group_tests(tests, NULL, NULL);
	}
	alx@devuan:~/tmp$ gcc cmocka.c -lcmocka
	alx@devuan:~/tmp$ ./a.out
	[==========] tests: Running 2 test(s).
	[ RUN      ] a
	[  ERROR   ] --- streq(s, "bar")
	[   LINE   ] --- cmocka.c:15: error: Failure!
	[  FAILED  ] a
	[ RUN      ] b
	[  ERROR   ] --- "foo" != "bar"
	[   LINE   ] --- cmocka.c:22: error: Failure!
	[  FAILED  ] b
	[==========] tests: 2 test(s) run.
	[  PASSED  ] 0 test(s).
	[  FAILED  ] tests: 2 test(s), listed below:
	[  FAILED  ] a
	[  FAILED  ] b

	 2 FAILED TEST(S)

Tested-by: Silvan Mosberger <github@infinisil.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-28 08:41:54 -06:00
Alejandro Colomar
fb9f7f51a8 */: s/STRTCPY/strtcpy_a/
This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-27 20:50:48 -06:00
Alejandro Colomar
d13bb54184 */: s/STRNCPY/strncpy_a/
This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-27 20:50:48 -06:00
Alejandro Colomar
ce044d1791 */: s/SNPRINTF/stprintf_a/
This name better reflects that it handles arrays, and doesn't shout.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-27 20:50:48 -06:00
sgakerru
6134359b28 useradd: tests for supplements groups
For regular and system user cases
2025-11-26 17:08:14 +01:00
sgakerru
ee8264351e useradd: fix test 69_useradd_default_GROUPS_name
Missing files have been added for the test to work: `gshadow`, `passwd`, `shadow`.
Without them, the foo user was created with a different UID and thus the test failed.

And other minor improvements, such as removing extra spaces and adding empty lines.
2025-11-26 17:08:14 +01:00
Alejandro Colomar
7d4362ff9d tests/unit/test_exit_if_null.c: Test through XMALLOC() instead of xaprintf()
Both are indirect tests for exit_if_null(), but through XMALLOC() we
can test it more robustly, as we don't need to wrap vasprintf(3) to
make it fail.  It's trivial to make MALLOC(3) fail: pass a huge size.

The tests with xaprintf() were failing on Nix.  I suspect the compiler
was inlining aggressively, and as a result, the interposition of
vasprintf(3) in cmocka wasn't actually working.  The approach with
XMALLOC() seems to work on Nix, as we don't need to interpose malloc(3).
We still need to interpose exit(3), but for some reason that works fine.

Closes: <https://github.com/shadow-maint/shadow/issues/1382>
Reported-by: Silvan Mosberger <github@infinisil.com>
Tested-by: Silvan Mosberger <github@infinisil.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-06 13:31:01 +01:00
Alejandro Colomar
17ad06b379 tests/unit/: Use more generic strings and names for testing exit_if_null()
This test is actually for exit_if_null(), not xaprintf().  Rename the
test file and functions, and make strings more generic.

Tested-by: Silvan Mosberger <github@infinisil.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-11-06 13:31:01 +01:00
Alejandro Colomar
655ffcbe1b lib/, src/, tests/: Move x*() definitions to non-x* header files
Now that all of these are one-liners, they don't need a separate header
file.  Compact stuff.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-10-27 14:32:06 +01:00
Alejandro Colomar
e645cc0d28 lib/string/sprintf/, tests/: xaprintf(): Reimplement in terms of exit_if_null()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-10-27 14:32:06 +01: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
Evgeny Grin (Karlson2k)
eb71706b1c */: Fix including <config.h> as system header
"config.h" is a locally generated header. It must be included as
'#include "config.h"'.
It is already included correctly in some sources files. This commit
unifies the way how "config.h" is included.

Signed-off-by: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
2025-07-16 14:12:40 +02:00
Alejandro Colomar
36debf3ccf tests/unit/test_xaprintf.c: Fix test by using streq() instead of strcmp(3)
Fixes: 423fd652b563 (2025-06-03; "lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()")
Closes: <https://github.com/shadow-maint/shadow/issues/1279>
Reported-by: Timo Gurr <timo.gurr@gmail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-07-02 17:41:21 +02:00
Alejandro Colomar
423fd652b5 lib/string/sprintf/, tests/unit/: Transform x[v]asprintf() into x[v]aprintf()
Wrap [v]aprintf() instead of [v]asprintf(3).

Repurpose x[v]asprintf()'s tests to test x[v]aprintf().

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-06-03 23:25:02 -05:00
Alejandro Colomar
ba3456c9fd lib/, src/, tests/: Use the standard countof() instead of our NITEMS()
countof() is the name blessed by the C Committee for ISO C2y.
Use it if available, and define it if not.

countof() will be provided by GCC 16 and Clang 21.

This is mostly a scripted change:

	$ grep -rl NITEMS | xargs sed -i s/NITEMS/countof/;

Apart from the scripted changes, I've adjusted white-space alignment,
and of course the definition at "lib/sizeof.h".

Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf#subsubsection.0.6.5.4.5>
Link: <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3550.pdf#section.0.7.21>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-06-03 09:34:55 -05: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