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

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