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

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