134 Commits

Author SHA1 Message Date
Alejandro Colomar
d2d89a8e0a tests/unit/test_xasprintf.c: Fix sign-mismatch diagnostic
Add a signed wrapper around mock() which returns a signed integer.
This makes it possible to compare the return value with literal -1.

Acked-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-03-04 00:08:15 +01:00
Alejandro Colomar
224848ebb6 lib/search/cmp/, lib/, tests/: CMP(), cmp_*(): Add macro and functions
These macros are for use with bsearch(3),lfind(3),qsort(3).

Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2025-01-24 07:58:13 -06: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
Chris Hofstaedtler
04592e4cc7 Remove references to cppw, cpgr
cppw, cpgr were Debian-only tools, which I've dropped in a recent upload.

Upstream should have never had tests for them.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2024-08-12 10:08:45 +02:00
Chris Hofstaedtler
11e9627658 tests/libsubid/04_nss: fix setting basedir
Align on variable name BUILD_BASE_DIR for overriding the toplevel
directory. This is the same name as accepted by tests/common/config.sh.

Without this, the test libsubid/04_nss fails in Debian's autopkgtests.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2024-07-18 08:52:35 -05:00
Alejandro Colomar
63297e836d lib/atoi/strtoi/, tests/: strto[iu]_(): 1 is an invalid base
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-11 22:42:58 -05:00
Alejandro Colomar
745281f295 lib/atoi/, *: Split files 2024-07-11 22:42:58 -05:00
Alejandro Colomar
59e5eef38f contrib, lib/, src/, tests/: Use stpcpy(3) instead of its pattern
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-03 10:03:12 -05:00
Alejandro Colomar
3049bef9c3 lib/alloc/, lib/, src/, tests/: Organize the allocation APIs in a new subdirectory
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
2cf73c99a6 lib/string/strcpy/zustr2stp.[ch], tests/: Remove ZUSTR2STP()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
40ab806066 lib/string/strcpy/, lib/, src/, tests/: Move all copying APIs to a subdirectory
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
22272347b6 lib/string/sprintf/, lib/, src/, tests/: Move all sprintf(3)-like APIs to a subdirectory
And have a separate file for each pair of APIs.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-07-01 21:40:11 -05:00
Alejandro Colomar
24695e6f38 tests/unit/test_typetraits.c: Add tests for typetraits.h macros
Suggested-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-29 20:00:18 +02:00
Serge Hallyn
2457fc7c6b tests/run_some: make sure unshared root user can descend build dir
This was causing errors in my local testing in vms.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-28 14:45:25 -05:00
Serge Hallyn
81b5b26925 libsubid test makefile: fix a typo
Fix a missing space after the -I path

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2024-06-28 16:16:33 +02:00
Alejandro Colomar
6e57238bf9 tests/unit/test_xasprintf.c: Fix use of volatile pointer
volatile needs to be casted away behind a [[gnu::noipa]] function, to
make that invisible to the compiler.  Otherwise, the compiler can see
that it is being discarded, and is free to abuse Undefined Behavior.

Closes: <https://github.com/shadow-maint/shadow/issues/1028>
Reported-by: Chris Hofstaedtler <zeha@debian.org>
Tested-by: Chris Hofstaedtler <zeha@debian.org>
Reviewed-by: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-28 08:57:01 -05:00
Alejandro Colomar
3307a8f4f0 tests/unit/test_xasprintf.c: Cosmetic
This is in preparation for the following commit.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-28 08:57:01 -05:00
Serge Hallyn
d55367bb16 tests/: Support run_some from exported tarball
common/config.sh currently tries to find the top directory by looking
for .git.  There are also many places under tests/ where we use
hard-coded ../../.. to find things like ${TOP_DIR}/lib.

We don't actually ship the tests with 'make dist'.  So we will
be exporting tests/ as a separate tarball.  In particular, I want
to then import this in the debian package.  However, there it will
be under shadow.git/debian/tests, not shadow.git/tests.

To support this, accept the environment variable BUILD_BASE_DIR,
which should point to shadow.git.

An alternative would be to move the tests to their own git
tree.  However, keeping tests in separate git tree tends to
lead to repos getting out of sync.  And we'd still need to accept
something like BUILD_BASE_DIR.

Note there are a lot of tests under run-all, which I'm not converting
as they currently are not being run in CI, so I'm more likely to
break something.

Changelog:
  2024 05 26: Incorporate feedback from alejandro-colomar

Link: <https://salsa.debian.org/debian/shadow/-/merge_requests/21>
Link: <https://salsa.debian.org/debian/shadow/-/merge_requests/22>
Cc: Chris Hofstaedtler <zeha@debian.org>
Signed-off-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-26 23:59:07 +02:00
Alejandro Colomar
ca046af5d9 Remove support for rlogind in login(1), that is, remove the '-r' flag
The "quick hack" finally disappeared.  Probably nobody noticed.  ;)
(See the changes in <configure.ac> for the context of this pun.)

Probably everybody uses SSH these days for remote login.  Let's remove
this insecure method.

Closes: <https://github.com/shadow-maint/shadow/issues/992>
Reviewed-by: dkwo <nicolopiazzalunga@gmail.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Michael Vetter <jubalh@iodoru.org>
Cc: Sam James <sam@gentoo.org>
Cc: Benedikt Brinkmann <datacobra@thinkbot.de>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-06-13 19:39:26 -05:00
Daniel Bershatsky
df59088641 libsubid: Fix code style issues 2024-06-12 21:45:31 +02:00
Daniel Bershatsky
b620b5d0d1 libsubid: Fail on plugin loading if no subid_free provided 2024-06-12 21:45:31 +02:00
Alejandro Colomar
71e28359d1 lib/atoi/strtou_noneg.[ch], tests/: strtoul_noneg(): Remove unused function
All call sites have been replaced by functions from "atoi/a2i.h" and
"atoi/str2i.h" recently.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-27 16:32:09 +02:00
Alejandro Colomar
fb49de61b7 lib/atoi/strtou_noneg.[ch], tests/: strtoull_noneg(): Remove unused function
All call sites were replaced by a2i() recently.

Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-05-27 16:32:09 +02:00
Alejandro Colomar
b76fc2947f tests/unit/test_zustr2stp.c: Test ZUSTR2STP()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-03-10 19:55:39 -05:00
Tobias Stoeckmann
403a2e3771 lib/chkname.c: Take NUL byte into account
The _SC_LOGIN_NAME_MAX value includes space for the NUL byte. The length
of name must smaller than this value to be valid.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2024-02-04 17:03:12 -06:00
Alejandro Colomar
f98e43ee11 tests/unit/test_atoi_strtoi.c: Test strtou_noneg()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Alejandro Colomar
f632515581 tests/unit/Makefile.am: tfix
Fix typo.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Alejandro Colomar
40355150c4 tests/unit/test_atoi_strtoi.c: Test strtoi_()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-31 22:26:19 -06:00
Alejandro Colomar
0138819b2a tests/unit/test_atoi_strtou_noneg.c: Test strtou[l]l_noneg()
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-22 17:17:15 -06:00
Alejandro Colomar
2e56af1902 lib/, tests/: addsl(): Add addsl(), a variadic macro
Add a variadic macro addsl() that accepts an arbitrary number of
addends, instead of having specific versions like addsl2() or addsl3().

It is internally implemented by the addslN() function, which itself
calls addsl2().  addsl3() is now obsolete and thus removed.

Code should just call addsl().

Link: <https://github.com/shadow-maint/shadow/pull/882#discussion_r1437155212>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-16 16:58:18 +01:00
Alejandro Colomar
2e5fc4c90b lib/, tests/: addsl2(): Rename addsl() to addsl2()
This is for consistency with addsl3(), and in preparation for the
following commit, which will unify the interface into a single addsl()
macro.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-16 16:58:18 +01:00
Alejandro Colomar
173231a8ff tests/unit/test_adds.c: Test addsl() and addsl3()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2024-01-05 15:45:08 -06:00
Alejandro Colomar
ddbd3a36c1 tests/unit/test_sprintf.c: Test SNPRINTF()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-15 16:41:47 +01:00
Alejandro Colomar
dbb37b1b31 lib/string/: Move string-related files to string/ subdir
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-12-03 12:22:11 -06:00
Alejandro Colomar
218235e9dd tests/unit/test_chkname.c: Test is_valid_user_name()
Suggested-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-28 16:57:54 +01:00
Alejandro Colomar
fe62fc48bf tests/unit/test_strncpy.c: Test STRNCPY()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-26 06:48:18 -06:00
Alejandro Colomar
751f8e055b tests/: Remove references to cracklib
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-25 21:24:38 -06:00
Alejandro Colomar
f9fb855889 src/, lib/, tests/: Rename files defining strtcpy()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
090c019ada src/, lib/, tests/: Rename STRLCPY() to STRTCPY()
It is a wrapper around STRTCPY(), so use a proper name.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
6adaa40135 lib/strlcpy.[ch]: Implement strtcpy(3) to replace strlcpy_()
There's been a very long and interesting discussion in linux-man@ and
libc-alpha@, where we've discussed all the string-copying functions,
their pros and cons, when should each be used and avoided, etc.

Paul Eggert pointed out an important problem of strlcpy(3): it is
vulnerable to DoS attacks if an attacker controls the length of the
source string.  And even if it doesn't control it, the function is dead
slow (because its API forces it to calculate strlen(src)).

We've agreed that the general solution for a truncating string-copying
function is to write a wrapper over strnlen(3)+memcpy(3), which is
limited to strnlen(src, sizeof(dst)).  This is not vulnerable to DoS,
and is very fast for all buffer sizes.  string_copying(7) has been
updated to reflect this, and provides a reference implementation for
this wrapper function.

This strtcpy(3) (t for truncation) wrapper happens to have the same API
that our strlcpy_() function had, so replace it with the better
implementation.  We don't need to update callers nor tests, since the
API is the same.

A future commit will rename STRLCPY() to STRTCPY(), and replace
remaining calls to strlcpy(3) by calls to this strtcpy(3).

Link: <https://lore.kernel.org/linux-man/ZU4SDh-Se5gjPny5@debian/T/#mfb5a3fdeb35487dec6f8d9e3d8548bd0d92c4975/>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00
Alejandro Colomar
6879f46327 tests/unit/test_strlcpy.c: Test strlcpy_() and STRLCPY()
This test fails now, due to a bug: the return type of strlcpy_() is
size_t, but it should be ssize_t.  The next commit will pass the test,
by fixing the bug.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
2023-11-22 12:55:26 +01:00