[Mono.Posix] Fix Group-lookup Tests
authorJonathan Pryor <jonpryor@vt.edu>
Thu, 31 May 2012 15:47:37 +0000 (11:47 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Thu, 31 May 2012 17:22:28 +0000 (13:22 -0400)
commitc706c851273903217e40c36de8bce60b556c6a08
treec9c9ed42bc7e77e34db42ac996693d3c1f2cd1cc
parent7f1046817a72a75d0d7eb851f9bacaf4927e0498
[Mono.Posix] Fix Group-lookup Tests

Fixes a test failure seen on OS X (and elsewhere), in which
UnixGroupTest.NonReentrantSyscalls() would fail:

#TRC: Exception constructing UnixGroupInfo: NUnit.Framework.AssertionException:
#TNRS: construct by name
Expected: <_appserverusr:*:79:>
But was:  <_appserverusr:*:79:jon>

The difference is in the group members: the expected value contains no
group members, while the actual value does. They both have the same
gorup name and group id; it's just the member list that differs.

The problem is that the _appserverusr group (and others) is returned
_twice_, once containing group members, and once without. (This is
possibly due to NIS; as per the removed comment.) This is readily
observed in a plain C program on OS X:

struct group *g;
setgrent ();
while ((g = getgrent ()) != NULL) {
printf ("local group: gr_name=%s; gr_passwd=%s; gr_gid=%i\n", g->gr_name, g->gr_passwd, g->gr_gid);
}
endgrent ();

Many groups are listed twice, and if you print out g->gr_mem it's
apparent that only the first invocation contains members, the second
does not, and looking up group info by name (getgrnam(3)) contains
group member info (yay!).

The fix here isn't a fix, it's a workaround: we track which groups
we've seen, and if we see a repeated group name we skip it. Thus, the
first time we see the _appserverusr group, we'll do the full
lookup-by-name-and-compare assertions, and the second time we see the
_appserverusr group we skip it entirely.
mcs/class/Mono.Posix/Test/Mono.Unix/UnixGroupTest.cs