summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrediano Ziglio <freddy77@gmail.com>2020-10-20 16:38:37 +0100
committerFrediano Ziglio <freddy77@gmail.com>2020-11-03 09:45:08 +0000
commit5094d5cfe66748dffcca8529745f8b3c76195d7a (patch)
tree20a05a7e7f8bdbbfa1ea6af6396b226abac13e00 /tests
parentb7db1c20c9f80154fb54392eb44add3486d3e427 (diff)
Add a test for session_info
Test from Uri, integrated in test suite. Signed-off-by: Uri Lublin <uril@redhat.com> Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-session-info.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/test-session-info.c b/tests/test-session-info.c
new file mode 100644
index 0000000..dae3ec6
--- /dev/null
+++ b/tests/test-session-info.c
@@ -0,0 +1,58 @@
+/* test-session-info.c - test session info
+
+ Copyright 2020 Red Hat, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <config.h>
+
+#undef NDEBUG
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "session-info.h"
+
+int main(int argc, char *argv[])
+{
+ int pid, uid, ck_uid;
+
+ pid = (int)getpid();
+
+ struct session_info *session_info = session_info_create(1);
+ if (session_info == NULL) {
+ return 1;
+ }
+
+ char *session = session_info_session_for_pid(session_info, pid);
+ if (session == NULL) {
+ session_info_destroy(session_info);
+ return 2;
+ }
+ ck_uid = session_info_uid_for_session(session_info, session);
+
+ free(session);
+ session_info_destroy(session_info);
+
+ uid = getuid();
+ printf("MAIN: uid is %d, ck_uid is %d\n", uid, ck_uid);
+
+ if (uid != ck_uid) {
+ fprintf(stderr, "MAIN: uid (%d) does not match console-kit uid %d\n", uid, ck_uid);
+ return 3;
+ }
+
+ return 0;
+}