Skip to content

Commit

Permalink
Add test for userproxy mode
Browse files Browse the repository at this point in the history
This is a very basic test that checks the gssproxy can start,
and that socket activation works.

Signed-off-by: Simo Sorce <[email protected]>
  • Loading branch information
simo5 committed May 23, 2022
1 parent b8f5f4a commit 6cdb629
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ cli_srv_conn
cli_srv_comm
gssproxy.spec
interposetest
userproxytest
gssproxy.service
gssuserproxy.service
gssuserproxy.socket
Expand Down
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,10 @@ CLEANFILES = *.X */*.X */*/*.X \

check: all $(check_PROGRAMS)
$(srcdir)/tests/runtests.py $(CHECKARGS)
if HAVE_SYSTEMD_DAEMON
mkdir -p testdir
tests/userproxytest
endif

tests: check

Expand Down
2 changes: 2 additions & 0 deletions external/systemd.m4
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ AC_DEFUN([AM_CHECK_SYSTEMD],
[AC_MSG_NOTICE([Build without $daemon_lib_name support])])],
[AC_MSG_NOTICE([Build without $daemon_lib_name support])])
AM_CONDITIONAL([HAVE_SYSTEMD_DAEMON], [test x"$daemon_lib_name" != x])
AC_MSG_NOTICE([Will enable systemd socket activation])
])
7 changes: 7 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ check_PROGRAMS = \
t_setcredopt \
$(NULL)

if HAVE_SYSTEMD_DAEMON
userproxytest_SOURCES = \
userproxytest.c

check_PROGRAMS += userproxytest
endif

noinst_PROGRAMS = $(check_PROGRAMS)

noinst_HEADERS = \
Expand Down
90 changes: 90 additions & 0 deletions tests/userproxytest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* Copyright (C) 2022 the GSS-PROXY contributors, see COPYING for license */

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <unistd.h>

char *srv_args[] = {
"./gssproxy",
"-u", "-i",
"-s", "./testdir/userproxytest.sock",
"--idle-timeout=3"
};

int mock_activation_sockets(void)
{
struct sockaddr_un addr = {
.sun_family = AF_UNIX,
.sun_path = "./testdir/userproxytest.sock",
};
int fd;
int ret;

unlink(addr.sun_path);

fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) return -1;

ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
if (ret == -1) return -1;

ret = listen(fd, 1);
if (ret == -1) return -1;

return 0;
}

int mock_activation_environment(void)
{
char *onestr = "1";
char *pidstr;
int ret;

ret = asprintf(&pidstr, "%u", (unsigned)getpid());
if (ret == -1) return -1;

setenv("LISTEN_PID", pidstr, 1);
setenv("LISTEN_FDS", onestr, 1);

free(pidstr);
return 0;
}

int main(int argc, const char *main_argv[])
{
pid_t proxy, w;
int ret;

fprintf(stderr, "Test userproxy mode: ");

ret = mock_activation_sockets();
if (ret) return -1;

proxy = fork();
if (proxy == -1) return -1;

if (proxy == 0) {
ret = mock_activation_environment();
if (ret) return -1;

execv("./gssproxy", srv_args);
return -1;
}

sleep(6);

w = waitpid(-1, &ret, WNOHANG);
if (w != proxy || ret != 0) {
fprintf(stderr, "FAIL\n");
fflush(stderr);
return -1;
}

fprintf(stderr, "SUCCESS\n");
fflush(stderr);
return 0;
}

0 comments on commit 6cdb629

Please sign in to comment.