[PATCH 0/2] fixes for test bugs found while building via mock

3 views
Skip to first unread message

Scott Schmit

unread,
Mar 25, 2024, 11:35:47 PMMar 25
to bup-...@googlegroups.com
I've been working on packaging bup 0.33.3 using mock
<https://rpm-software-management.github.io/mock/>, and I hit some test
failures which don't occur when building via rpmbuild directly. Looking
into the test failures, they are bugs with the tests themselves.

test/ext/test-meta | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

Some comments on the patches for context (above and beyond the comments
in the individual patches).

* [PATCH 1/2] test-meta: use grep -a on xstat/meta (even if root)

I found this by mistake while debugging the build failure fixed by the
next patch. (I didn't realize that while mock runs rpmbuild as a normal
user, `mock shell` gives you a root shell in the build environment, so I
ran the tests as root by mistake.)

So while this patch fixes some problems in the as-root tests, I didn't
go further to get test-meta to pass as root.

* [PATCH 2/2] test-meta: fix empty supplemental group list handling

I'm not sure what mock does that's so special, but os.getgroups()
returns [] in the mock environment, which breaks the "show we can change
groups correctly" test case. Of course, the mock build user has no
other groups, so the test is also useless, so I added code to detect and
skip the test in that case.

Scott Schmit

unread,
Mar 25, 2024, 11:37:18 PMMar 25
to bup-...@googlegroups.com, i.g...@comcast.net, Scott Schmit
Commit 6efdc0b0 ('test-meta: use grep -a on xstat/meta') updates a number of
test-meta tests because bup xstat and bup meta can output binary data, making
grep output useless. However, the test-meta tests are performed or skipped
based on whether the user is running as root or not, and the "running-as-root"
tests didn't get converted. Finish the necessary changes.

Signed-off-by: Scott Schmit <i.g...@comcast.net>
---
test/ext/test-meta | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/test/ext/test-meta b/test/ext/test-meta
index 4d6b86aa..82746e47 100755
--- a/test/ext/test-meta
+++ b/test/ext/test-meta
@@ -577,7 +577,7 @@ src/foo/3"
WVPASS rm -rf src
WVPASS bup meta --edit --set-user root --set-uid "$other_uid" ../src.meta \
| WVPASS bup meta -x --numeric-ids
- new_uidx=$(bup xstat src | grep -e '^uid:') || exit $?
+ new_uidx=$(bup xstat src | grep -ae '^uid:') || exit $?
WVPASSEQ "$new_uidx" "uid: $other_uid"

# Test --numeric-ids (gid). Note the name 'root' is not handled
@@ -586,7 +586,7 @@ src/foo/3"
WVPASS rm -rf src
WVPASS bup meta --edit --set-group root --set-gid "$other_gid" ../src.meta \
| WVPASS bup meta -x --numeric-ids
- new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
+ new_gidx=$(bup xstat src | grep -ae '^gid:') || exit $?
WVPASSEQ "$new_gidx" "gid: $other_gid"

# Test that restoring an unknown user works.
@@ -595,7 +595,7 @@ src/foo/3"
WVPASS bup meta --edit \
--set-uid "$other_uid" --set-user "$unknown_user" ../src.meta \
| WVPASS bup meta -x
- new_uidx=$(bup xstat src | grep -e '^uid:') || exit $?
+ new_uidx=$(bup xstat src | grep -ae '^uid:') || exit $?
WVPASSEQ "$new_uidx" "uid: $other_uid"

# Test that restoring an unknown group works.
@@ -604,7 +604,7 @@ src/foo/3"
WVPASS bup meta --edit \
--set-gid "$other_gid" --set-group "$unknown_group" ../src.meta \
| WVPASS bup meta -x
- new_gidx=$(bup xstat src | grep -e '^gid:') || exit $?
+ new_gidx=$(bup xstat src | grep -ae '^gid:') || exit $?
WVPASSEQ "$new_gidx" "gid: $other_gid"

if ! [[ $(uname) =~ CYGWIN ]]; then
@@ -720,7 +720,7 @@ if [ "$root_status" = root ]; then
WVPASS mkdir "$testfs_limited"/src-restore
WVPASS cd "$testfs_limited"/src-restore
WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
- | WVPASS grep -e '^Linux chattr:' \
+ | WVPASS grep -ae '^Linux chattr:' \
| WVPASS bup-cfg-py -c \
'import sys; exit(not len(sys.stdin.readlines()) == 3)'
) || exit $?
@@ -744,7 +744,7 @@ if [ "$root_status" = root ]; then
WVPASS cd "$testfs_limited"/src-restore
WVFAIL bup meta --extract --file "$testfs"/src.meta
WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
- | WVPASS grep -e "^xattr\.set u\?'" \
+ | WVPASS grep -ae "^xattr\.set u\?'" \
| WVPASS bup-cfg-py -c \
'import sys; exit(not len(sys.stdin.readlines()) == 2)'
) || exit $?
@@ -766,7 +766,7 @@ if [ "$root_status" = root ]; then
WVPASS mkdir "$testfs_limited"/src-restore
WVPASS cd "$testfs_limited"/src-restore
WVFAIL bup meta --extract --file "$testfs"/src.meta 2>&1 \
- | WVPASS grep -e '^POSIX1e ACL applyto:' \
+ | WVPASS grep -ae '^POSIX1e ACL applyto:' \
| WVPASS bup-cfg-py -c \
'import sys; exit(not len(sys.stdin.readlines()) == 2)'
) || exit $?
--
2.44.0

Scott Schmit

unread,
Mar 25, 2024, 11:37:40 PMMar 25
to bup-...@googlegroups.com, i.g...@comcast.net, Scott Schmit
Previously, `test-meta` would attempt to index into an empty list if the
user has no supplemental groups. Per getgroups(2):

> It is unspecified whether the effective group ID of the calling
> process is included in the returned list. (Thus, an application
> should also call getegid(2) and add or remove the resulting value.)

(This happens to occur when building in a `mock` build environment.)

Add the missing group to the list.

Further, since the user has no supplemental groups, there's no way to
switch files between multiple groups, making the whole test pointless.
Skip the test in such situations.

Signed-off-by: Scott Schmit <i.g...@comcast.net>
---
test/ext/test-meta | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/test/ext/test-meta b/test/ext/test-meta
index 82746e47..6ab3ae53 100755
--- a/test/ext/test-meta
+++ b/test/ext/test-meta
@@ -442,11 +442,16 @@ src/foo/3"

# FIXME: binary groups
first_group="$(WVPASS bup-cfg-py -c 'import os,grp; \
- print(grp.getgrgid(os.getgroups()[0])[0])')" || exit $?
+ print(grp.getgrgid(sorted(list(set(os.getgroups() + [os.getegid()])))[0])[0])')" || exit $?
last_group="$(bup-cfg-py -c 'import os,grp; \
- print(grp.getgrgid(os.getgroups()[-1])[0])')" || exit $?
+ print(grp.getgrgid(sorted(list(set(os.getgroups() + [os.getegid()])))[-1])[0])')" || exit $?
last_group_erx="$(escape-erx "$last_group")"

+ # Skip pointless test if we only have one group
+ if [ "$first_group" = "$last_group" ]; then
+ exit 0
+ fi
+
WVSTART 'metadata (restoration of ownership)'
WVPASS cd "$tmpdir"
WVPASS touch src
--
2.44.0

Reply all
Reply to author
Forward
0 new messages