tests: fix group membership check in sbang tests. (#33658)
Fixes an issue on the RHEL8 UBI container where this test would fail because `gr_mem` was empty for every entry in the `grp` DB. You have to check *both* the `pwd` database (which has primary groups) and `grp` (which has other gorups) to do this correctly. - [x] update `llnl.util.filesystem.group_ids()` to do this - [x] use it in the `sbang` test
This commit is contained in:
@@ -505,8 +505,15 @@ def group_ids(uid=None):
|
||||
|
||||
if uid is None:
|
||||
uid = getuid()
|
||||
user = pwd.getpwuid(uid).pw_name
|
||||
return [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]
|
||||
|
||||
pwd_entry = pwd.getpwuid(uid)
|
||||
user = pwd_entry.pw_name
|
||||
|
||||
# user's primary group id may not be listed in grp (i.e. /etc/group)
|
||||
# you have to check pwd for that, so start the list with that
|
||||
gids = [pwd_entry.pw_gid]
|
||||
|
||||
return sorted(set(gids + [g.gr_gid for g in grp.getgrall() if user in g.gr_mem]))
|
||||
|
||||
|
||||
@system_path_filter(arg_slice=slice(1))
|
||||
|
Reference in New Issue
Block a user