From a246de8bd1b37f1b9881b38036a736305e3e4052 Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Sat, 5 May 2018 00:40:13 +0200 Subject: unit tests: Fix them and reenable them. --- debian/rules | 2 ++ src/pam-x2go-private.h | 32 +++++++++++++++++++++++++++++ tests/Makefile.am | 51 +++++++++++++++++++++++++++++++++++++++------- tests/mock_pam.c | 15 +++++++------- tests/mock_pam.h | 8 ++++++-- tests/test-x2go-wrapper.cc | 3 ++- 6 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 src/pam-x2go-private.h diff --git a/debian/rules b/debian/rules index ed32ace..20ad848 100755 --- a/debian/rules +++ b/debian/rules @@ -9,6 +9,8 @@ include /usr/share/cdbs/1/rules/autoreconf.mk include /usr/share/cdbs/1/class/autotools.mk include /usr/share/cdbs/1/rules/utils.mk +DEB_MAKE_CHECK_TARGET = check + # Remove .a and .la files from /lib/security binary-post-install/libpam-x2go:: find $(DEB_DESTDIR)/lib/security -type f \ diff --git a/src/pam-x2go-private.h b/src/pam-x2go-private.h new file mode 100644 index 0000000..ad366d2 --- /dev/null +++ b/src/pam-x2go-private.h @@ -0,0 +1,32 @@ +/* + * Copyright © 2018 Mike Gabriel + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, 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 . + * + * Author: Mike Gabriel + * Author libpam-freerdp (where we forked from): Ted Gould + */ + +#ifndef _PAM_X2GO_PRIVATE_H_ +#define _PAM_X2GO_PRIVATE_H_ + +PAM_EXTERN int +pam_sm_authenticate (pam_handle_t *pamh, int flags, int argc, const char **argv); +PAM_EXTERN int +pam_sm_open_session (pam_handle_t *pamh, int flags, int argc, const char ** argv); +PAM_EXTERN int +pam_sm_close_session (pam_handle_t *pamh, int flags, int argc, const char **argv); +PAM_EXTERN int +pam_sm_setcred (pam_handle_t *pamh, int flags, int argc, const char ** argv); + +#endif //_PAM_X2GO_PRIVATE_H_ \ No newline at end of file diff --git a/tests/Makefile.am b/tests/Makefile.am index a88cea8..34ba425 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -13,6 +13,11 @@ check_PROGRAMS = \ $(TESTS) \ $(NULL) +CLEANFILES += \ + test-x2go-auth \ + $(TESTS) \ + $(NULL) + AM_CPPFLAGS = $(GTEST_CPPFLAGS) \ $(REMOTE_APPS_MANAGER_CFLAGS) \ -I${top_srcdir}/src -Wall -Werror \ @@ -31,20 +36,41 @@ AM_CFLAGS = \ # Google Test Test Suite # ########################## -check_LIBRARIES = libgtest.a +check_LIBRARIES = libgtest.a libgtest_main.a + +gtest-all.cc: + cp $(GTEST_SOURCE)/src/gtest-all.cc . + +gtest_main.cc: + cp $(GTEST_SOURCE)/src/gtest_main.cc . + +CLEANFILES += \ + gtest-all.cc \ + gtest_main.cc \ + $(NULL) nodist_libgtest_a_SOURCES = \ - $(GTEST_SOURCE)/src/gtest-all.cc \ - $(GTEST_SOURCE)/src/gtest_main.cc \ + gtest-all.cc \ + $(NULL) +nodist_libgtest_main_a_SOURCES = \ + gtest_main.cc \ $(NULL) libgtest_a_CPPFLAGS = \ $(GTEST_CPPFLAGS) -w \ $(AM_CPPFLAGS) \ $(NULL) +libgtest_main_a_CPPFLAGS = \ + $(GTEST_CPPFLAGS) -w \ + $(AM_CPPFLAGS) \ + $(NULL) + libgtest_a_CXXFLAGS = \ $(AM_CXXFLAGS) \ $(NULL) +libgtest_main_a_CXXFLAGS = \ + $(AM_CXXFLAGS) \ + $(NULL) ########################## # Wrapper @@ -59,17 +85,29 @@ test_x2go_wrapper_SOURCES = \ $(NULL) test_x2go_wrapper_LDADD = \ - $(top_builddir)/src/libssh.la \ - libgtest.a \ + libgtest.a libgtest_main.a \ + ${top_srcdir}/src/pam_x2go.la \ + $(LIBSSH_LIBS) \ + $(NULL) + +test_x2go_wrapper_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -I${top_srcdir}/include \ + -I${top_srcdir}/src \ + $(GTEST_CPPFLAGS) \ + $(LIBSSH_CPPFLAGS) \ $(NULL) test_x2go_wrapper_CXXFLAGS = \ $(AM_CXXFLAGS) \ -DAUTH_CHECK="\"$(abs_builddir)/test-x2go-auth\"" \ - -I${top_srcdir}/src \ + $(GTEST_CXXFLAGS) \ + $(LIBSSH_CXXFLAGS) \ $(NULL) test_x2go_wrapper_LDFLAGS = \ + $(GTEST_LDFLAGS) \ + $(LIBSSH_LDFLAGS) \ -pthread \ $(NULL) @@ -80,4 +118,3 @@ test_x2go_wrapper_LDFLAGS = \ test_x2go_auth_SOURCES = \ test-x2go-auth.c \ $(NULL) - diff --git a/tests/mock_pam.c b/tests/mock_pam.c index a07c9af..8b8e2f5 100644 --- a/tests/mock_pam.c +++ b/tests/mock_pam.c @@ -11,6 +11,7 @@ #include #include "mock_pam.h" +#include "pam-x2go.h" struct pam_handle { void *item[PAM_NUM_ITEMS]; @@ -31,15 +32,15 @@ int fake_conv (int num_msg, const struct pam_message **msg, response->resp_retcode = 0; - if (strcmp((*msg)->msg, "login:") == 0) + if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_GUESTLOGIN) == 0) response->resp = strdup ("guest"); /* IMPORTANT: this needs to be in /etc/passwd */ - else if (strcmp((*msg)->msg, "remote login:") == 0) + else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_USER) == 0) response->resp = strdup ("ruser"); - else if (strcmp((*msg)->msg, "remote host:") == 0) + else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_HOST) == 0) response->resp = strdup ("protocol://rhost/dummy"); - else if (strcmp((*msg)->msg, "password:") == 0) + else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_PASSWORD) == 0) response->resp = strdup ("password"); - else if (strcmp((*msg)->msg, "remote command:") == 0) + else if (strcmp((*msg)->msg, PAM_X2GO_PROMPT_COMMAND) == 0) response->resp = strdup ("rcommand"); else return PAM_SYMBOL_ERR; /* leaks... */ @@ -63,7 +64,7 @@ pam_handle_t *pam_handle_new (void) return newh; } -int pam_get_item (const pam_handle_t *pamh, int type, const void **value) +int PAM_NONNULL((1)) pam_get_item (const pam_handle_t *pamh, int type, const void **value) { if (pamh == NULL) return PAM_SYSTEM_ERR; @@ -78,7 +79,7 @@ int pam_get_item (const pam_handle_t *pamh, int type, const void **value) return PAM_SUCCESS; } -int pam_set_item (pam_handle_t *pamh, int type, const void *value) +int PAM_NONNULL((1)) pam_set_item (pam_handle_t *pamh, int type, const void *value) { if (pamh == NULL) return PAM_SYSTEM_ERR; diff --git a/tests/mock_pam.h b/tests/mock_pam.h index c335e49..01bea3f 100644 --- a/tests/mock_pam.h +++ b/tests/mock_pam.h @@ -10,6 +10,7 @@ #ifndef __MOCK_PAM_H__ #define __MOCK_PAM_H__ +#define LIBPAM_COMPILE #include #include #include @@ -19,7 +20,10 @@ typedef struct pam_handle pam_handle_t; pam_handle_t *pam_handle_new (void); -int pam_get_item (const pam_handle_t *pamh, int type, const void **value); -int pam_set_item (pam_handle_t *pamh, int type, const void *value); + +int PAM_NONNULL((1)) +pam_get_item (const pam_handle_t *pamh, int type, const void **value); +int PAM_NONNULL((1)) +pam_set_item (pam_handle_t *pamh, int type, const void *value); #endif diff --git a/tests/test-x2go-wrapper.cc b/tests/test-x2go-wrapper.cc index a792d3e..f514f0f 100644 --- a/tests/test-x2go-wrapper.cc +++ b/tests/test-x2go-wrapper.cc @@ -13,10 +13,11 @@ extern "C" { #include "mock_pam.h" #include "mock_guest.h" +#include "pam-x2go-private.h" int x2goclient_wrapper (int argc, char * argv[]); -const char * auth_check_path = AUTH_CHECK; + const char * auth_check_path = AUTH_CHECK; } -- cgit v1.2.3