about summary refs log tree commit diff
path: root/nss/tst-nss-test3.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2017-07-17 15:50:43 -0400
committerDJ Delorie <dj@delorie.com>2017-07-17 15:52:44 -0400
commitae5c498d93d049d9574d3f8f18e62cac64cbdf5c (patch)
tree986e51e120bd42c02fe2ee5a4b04ca13951600e3 /nss/tst-nss-test3.c
parent48145e1c7dabaeab7ad8346d14f910cdeb6bc910 (diff)
downloadglibc-ae5c498d93d049d9574d3f8f18e62cac64cbdf5c.tar.gz
glibc-ae5c498d93d049d9574d3f8f18e62cac64cbdf5c.tar.xz
glibc-ae5c498d93d049d9574d3f8f18e62cac64cbdf5c.zip
Extend NSS test suite
* nss/nss_test.h: New.
* nss/nss_test1.h: Rewrite to use test-provided data.  Add group
tests.  Parameterize to allow multiple instances.
* nss/nss_test2.h: New.  Second instance.
* nss/nss_test.ver: New.
* nss/nss_test1.c: Update to use new framework.
* nss/nss_test2.c: New.
* nss/nss_test3.c: New.
* nss/nss_test4.c: New.
* nss/nss_test5.c: New.
* nss/Makefile: Build new tests.
* shlib-versions: Add libnss_test2.
Diffstat (limited to 'nss/tst-nss-test3.c')
-rw-r--r--nss/tst-nss-test3.c150
1 files changed, 150 insertions, 0 deletions
diff --git a/nss/tst-nss-test3.c b/nss/tst-nss-test3.c
new file mode 100644
index 0000000000..308708f387
--- /dev/null
+++ b/nss/tst-nss-test3.c
@@ -0,0 +1,150 @@
+/* Test error checking for group entries.
+   Copyright (C) 2017 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <nss.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/signal.h>
+
+#include "nss_test.h"
+
+/* The names here are arbitrary, but the *lengths* of the arrays is
+   not, and groups 6 and 7 test for partial matches.  */
+
+static const char *group_2[] = {
+  "foo", "bar", NULL
+};
+
+static const char *group_3[] = {
+  "tom", "dick", "harry", NULL
+};
+
+static const char *group_4[] = {
+  "alpha", "beta", "gamma", "fred", NULL
+};
+
+static const char *group_6[] = {
+  "larry", "curly", "moe", NULL
+};
+
+static const char *group_7[] = {
+  "larry", "curly", "darryl", NULL
+};
+
+static const char *group_14[] = {
+  "huey", "dewey", "louis", NULL
+};
+
+/* Note that we're intentionally causing mis-matches here; the purpose
+   of this test case is to test each error check and make sure they
+   detect the errors they check for, and to ensure that the harness
+   can process all the error cases properly (i.e. a NULL gr_name
+   field).  We check for the correct number of mismatches at the
+   end.  */
+
+/* This is the data we're giving the service.  */
+static struct group group_table_data[] = {
+  GRP(4), /* match */
+  GRP_N(8, "name6", group_6), /* wrong gid */
+  GRP_N(14, NULL, group_14), /* missing name */
+  GRP(14), /* unexpected name */
+  GRP_N(7, "name7_wrong", group_7), /* wrong name */
+  { .gr_name =  (char *)"name5", .gr_passwd =  (char *)"wilma", .gr_gid = 5, .gr_mem = NULL }, /* unexpected passwd */
+  { .gr_name =  (char *)"name5", .gr_passwd = NULL, .gr_gid = 5, .gr_mem = NULL }, /* missing passwd */
+  { .gr_name =  (char *)"name5", .gr_passwd = (char *)"wilma", .gr_gid = 5, .gr_mem = NULL }, /* wrong passwd */
+  GRP_N(3, "name3a", NULL),   /* missing member list */
+  GRP_N(3, "name3b", group_3), /* unexpected member list */
+  GRP_N(3, "name3c", group_3), /* wrong/short member list */
+  GRP_N(3, "name3d", group_4), /* wrong/long member list */
+  GRP_LAST ()
+};
+
+/* This is the data we compare against.  */
+static struct group group_table[] = {
+  GRP(4),
+  GRP(6),
+  GRP(14),
+  GRP_N(14, NULL, group_14),
+  GRP(7),
+  { .gr_name =  (char *)"name5", .gr_passwd = NULL, .gr_gid = 5, .gr_mem = NULL },
+  { .gr_name =  (char *)"name5", .gr_passwd =  (char *)"fred", .gr_gid = 5, .gr_mem = NULL },
+  { .gr_name =  (char *)"name5", .gr_passwd =  (char *)"fred", .gr_gid = 5, .gr_mem = NULL },
+  GRP_N(3, "name3a", group_3),
+  GRP_N(3, "name3b", NULL),
+  GRP_N(3, "name3c", group_4),
+  GRP_N(3, "name3d", group_3),
+  GRP(2),
+  GRP_LAST ()
+};
+
+void
+_nss_test1_init_hook(test_tables *t)
+{
+  t->grp_table = group_table_data;
+}
+
+static int
+do_test (void)
+{
+  int retval = 0;
+  int i;
+  struct group *g = NULL;
+
+  __nss_configure_lookup ("group", "test1");
+
+  setgrent ();
+
+  i = 0;
+  for (g = getgrent () ;
+       g != NULL && ! GRP_ISLAST(&group_table[i]);
+       ++i, g = getgrent ())
+    {
+      retval += compare_groups (i, g, & group_table[i]);
+    }
+
+  endgrent ();
+
+  if (g)
+    {
+      printf ("FAIL: [?] group entry %u.%s unexpected\n", g->gr_gid, g->gr_name);
+      ++retval;
+    }
+  if (group_table[i].gr_name || group_table[i].gr_gid)
+    {
+      printf ("FAIL: [%d] group entry %u.%s missing\n", i,
+	      group_table[i].gr_gid, group_table[i].gr_name);
+      ++retval;
+    }
+
+#define EXPECTED 18
+  if (retval == EXPECTED)
+    {
+      if (retval > 0)
+	printf ("PASS: Found %d expected errors\n", retval);
+      return 0;
+    }
+  else
+    {
+      printf ("FAIL: Found %d errors, expected %d\n", retval, EXPECTED);
+      return 1;
+    }
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"