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 ccb74d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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 ccb74d2

Please sign in to comment.