Skip to content

Commit

Permalink
Use runuser instead of sudo for test-suite user changes
Browse files Browse the repository at this point in the history
We don't need or want any of the sudo fanciness and privilege elevation
here: we're already root inside the container and just want to run
things as a different user. runuser is more than adequate for this
purpose.

One such peculiarity is that apparently sudo re-expands its command,
so \$PWD got evaluated to the PWD of the new shell. runuser does no such
thing, but we can just as well hardcode a directory, $PWD is nothing
special in this case.

Consolidate the lone runuser rpmdb export test to use runroot_user too
now that it can.
  • Loading branch information
pmatilai committed Jan 31, 2025
1 parent efae07c commit b83cd12
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ as well as the existing tests. Below are the specifics of RPM's test-suite:
* Use `RPMTEST_USER` to create a regular UNIX user in a mutable snapshot
* The username is stored in the `$RPMUSER` environment variable
* To run a binary as `$RPMUSER` inside the snapshot, use `runroot_user`
(this calls `sudo(8)` underneath)
(this calls `runuser(1)` underneath)
* You can create a custom user (or users) by supplying a list of usernames
to the macro, e.g. `RPMTEST_USER([user1, user2])`. Then, use
`runroot_user -n <name>` to run a binary as a specific user
Expand Down
2 changes: 1 addition & 1 deletion tests/atlocal.in
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ runroot_user()
shift 2
;;
esac
runroot --new-session sudo -iu $RPMUSER "$@"
runroot --new-session /sbin/runuser -u $RPMUSER -- "$@"
}

snapshot prune rpmtests.dir/*/tree
4 changes: 1 addition & 3 deletions tests/rpmdb.at
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ runroot rpm -U /data/RPMS/hlinktest-1.0-1.noarch.rpm
[])

RPMTEST_CHECK([
# Need to pass the dbpath explicitly since we're not going through run/runroot
dbpath=$(rpm --eval "%_dbpath")
runroot /sbin/runuser -u nobody -- rpmdb --dbpath ${dbpath} --exportdb > hdr.list
runroot_user -n nobody rpmdb --exportdb > hdr.list
],
[0],
[],
Expand Down
8 changes: 5 additions & 3 deletions tests/rpmi.at
Original file line number Diff line number Diff line change
Expand Up @@ -1175,18 +1175,20 @@ RPMTEST_USER

runroot rpmbuild --quiet -bb /data/SPECS/rootfs.spec

USERDIR=/tmp/mydir

RPMTEST_CHECK([
runroot_user \
rpm -U --prefix \$PWD/root --dbpath \$PWD/rpmdb \
rpm -U --prefix ${USERDIR}/root --dbpath ${USERDIR}/rpmdb \
/build/RPMS/noarch/rootfs-1.0-1.noarch.rpm
],
[0],
[],
[])

RPMTEST_CHECK([
runroot_user rpm -e --dbpath \$PWD/rpmdb rootfs
runroot_user test ! -d \$PWD/root
runroot_user rpm -e --dbpath ${USERDIR}/rpmdb rootfs
runroot_user test ! -d ${USERDIR}/root
],
[0],
[],
Expand Down

0 comments on commit b83cd12

Please # to comment.