Skip to content

Commit ec07331

Browse files
committed
#775964: skip YP/NIS entries instead of failing the test
Also includes doc updates mentioning that these entries may not be retrievable via getgrnam and getgrgid. Patch by Bobby Impollonia.
1 parent a80f4fb commit ec07331

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

Doc/library/grp.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ correspond to the members of the ``group`` structure (Attribute field below, see
3030
The gid is an integer, name and password are strings, and the member list is a
3131
list of strings. (Note that most users are not explicitly listed as members of
3232
the group they are in according to the password database. Check both databases
33-
to get complete membership information.)
33+
to get complete membership information. Also note that a ``gr_name`` that
34+
starts with a ``+`` or ``-`` is likely to be a YP/NIS reference and may not be
35+
accessible via :func:`getgrnam` or :func:`getgrgid`.)
3436

3537
It defines the following items:
3638

Lib/test/test_grp.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ def test_values(self):
3333
e2 = grp.getgrgid(e.gr_gid)
3434
self.check_value(e2)
3535
self.assertEqual(e2.gr_gid, e.gr_gid)
36-
e2 = grp.getgrnam(e.gr_name)
36+
name = e.gr_name
37+
if name.startswith('+') or name.startswith('-'):
38+
# NIS-related entry
39+
continue
40+
e2 = grp.getgrnam(name)
3741
self.check_value(e2)
3842
# There are instances where getgrall() returns group names in
3943
# lowercase while getgrgid() returns proper casing.
4044
# Discovered on Ubuntu 5.04 (custom).
41-
self.assertEqual(e2.gr_name.lower(), e.gr_name.lower())
45+
self.assertEqual(e2.gr_name.lower(), name.lower())
4246

4347
def test_errors(self):
4448
self.assertRaises(TypeError, grp.getgrgid)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ Gerhard Häring
398398
Fredrik Håård
399399
Mihai Ibanescu
400400
Lars Immisch
401+
Bobby Impollonia
401402
Meador Inge
402403
Tony Ingraldi
403404
John Interrante

Misc/NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Library
3838
or otherwise not wait for exiting child processes.
3939

4040

41+
Tests
42+
-----
43+
44+
- Issue #775964: test_grp now skips YP/NIS entries instead of failing when
45+
encountering them.
46+
47+
4148
What's New in Python 3.2 Beta 1?
4249
================================
4350

Modules/grpmodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ Return the group database entry for the given group name. If\n\
159159
name is not valid, raise KeyError."},
160160
{"getgrall", grp_getgrall, METH_NOARGS,
161161
"getgrall() -> list of tuples\n\
162-
Return a list of all available group entries, in arbitrary order."},
162+
Return a list of all available group entries, in arbitrary order.\n\
163+
An entry whose name starts with '+' or '-' represents an instruction\n\
164+
to use YP/NIS and may not be accessible via getgrnam or getgrgid."},
163165
{NULL, NULL} /* sentinel */
164166
};
165167

0 commit comments

Comments
 (0)