Blame SOURCES/0177-testsuite-add-test-for-uid_in_group.patch

28bab8
From eed8e1ded537327132a7cec7dec7af75ddea5656 Mon Sep 17 00:00:00 2001
28bab8
From: Matej Habrnal <mhabrnal@redhat.com>
28bab8
Date: Wed, 16 Dec 2015 10:54:25 +0100
28bab8
Subject: [PATCH] testsuite: add test for uid_in_group()
28bab8
28bab8
Signed-off-by: Matej Habrnal <mhabrnal@redhat.com>
28bab8
---
28bab8
 tests/dump_dir.at | 33 +++++++++++++++++++++++++++++++++
28bab8
 1 file changed, 33 insertions(+)
28bab8
28bab8
diff --git a/tests/dump_dir.at b/tests/dump_dir.at
28bab8
index fb8c7ce..70a97e6 100644
28bab8
--- a/tests/dump_dir.at
28bab8
+++ b/tests/dump_dir.at
28bab8
@@ -322,3 +322,36 @@ int main(void)
28bab8
     return 0;
28bab8
 }
28bab8
 ]])
28bab8
+
28bab8
+## ------------ ##
28bab8
+## uid_in_group ##
28bab8
+## ------------ ##
28bab8
+
28bab8
+AT_TESTFUN([uid_in_group],
28bab8
+[[
28bab8
+#include "internal_libreport.h"
28bab8
+#include <libtar.h>
28bab8
+#include <assert.h>
28bab8
+
28bab8
+int main(void)
28bab8
+{
28bab8
+    // not existing user id
28bab8
+    assert(uid_in_group((uid_t)-1, 0) == false);
28bab8
+
28bab8
+    // root user is member of root group
28bab8
+    assert(uid_in_group(0, 0) == true);
28bab8
+
28bab8
+    // user root isn't member of not existing group
28bab8
+    assert(uid_in_group(0, (gid_t)-1) == false);
28bab8
+
28bab8
+    // user root isn't member of nobody group
28bab8
+    gid_t nobody_gid = (gid_t)-1;
28bab8
+    struct group *gr = getgrnam("nobody");
28bab8
+    if (gr)
28bab8
+        nobody_gid = gr->gr_gid;
28bab8
+
28bab8
+    assert(uid_in_group(0, nobody_gid) == false);
28bab8
+
28bab8
+    return 0;
28bab8
+}
28bab8
+]])
28bab8
-- 
28bab8
1.8.3.1
28bab8