Omit privileged setgroups(2) call to test set[ug]id(2) to same user

Every user may change its user/group ID to the current one.
With an ugly hack, skip the superuser-only part of chuser()
to exercise this rest of the code path in regular tests.
This commit is contained in:
Klemens Nanni 2024-11-12 02:36:28 +03:00
parent 988cd0e207
commit 12acd710be
No known key found for this signature in database
2 changed files with 8 additions and 10 deletions

View file

@ -44,18 +44,14 @@ func TestInvalidUserid (t *testing.T) {
}
}
// Change to the current user by ID.
func TestCurrentUserid (t *testing.T) {
// Change to the current user by username and group ID.
func TestCurrentUser (t *testing.T) {
usr, err := user.Current()
if err != nil {
t.Fatal(err)
}
if usr.Uid != "0" {
t.Skip("setgroups(2): Only the superuser may set new groups.")
}
if err = chuser(usr.Uid); err != nil {
if err = chuser(usr.Username + ":" + usr.Gid, true /* skipSetGroupsForTests */); err != nil {
t.Fatal(err)
}
}