diff options
author | Alberto Gonzalez Iniesta <agi@inittab.org> | 2016-12-27 18:25:47 +0100 |
---|---|---|
committer | Alberto Gonzalez Iniesta <agi@inittab.org> | 2016-12-27 18:25:47 +0100 |
commit | 3a2bbdb05ca6a6996e424c9fb225cb0d53804125 (patch) | |
tree | f29063da5bec4caf3853d49a22a09c8619eebd21 /tests | |
parent | d53dba59e78da865c4fe820386ff2f4f76925f3b (diff) |
New upstream version 2.4.0upstream/2.4.0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 2 | ||||
-rw-r--r-- | tests/Makefile.in | 4 | ||||
-rwxr-xr-x | tests/t_client.sh | 20 | ||||
-rw-r--r-- | tests/unit_tests/Makefile.in | 2 | ||||
-rw-r--r-- | tests/unit_tests/example_test/Makefile.in | 6 | ||||
-rw-r--r-- | tests/unit_tests/example_test/test.c | 40 | ||||
-rw-r--r-- | tests/unit_tests/example_test/test2.c | 6 | ||||
-rw-r--r-- | tests/unit_tests/openvpn/Makefile.am | 8 | ||||
-rw-r--r-- | tests/unit_tests/openvpn/Makefile.in | 95 | ||||
-rw-r--r-- | tests/unit_tests/openvpn/mock_msg.c | 59 | ||||
-rw-r--r-- | tests/unit_tests/openvpn/test_argv.c | 204 | ||||
-rw-r--r-- | tests/unit_tests/openvpn/test_buffer.c | 56 | ||||
-rw-r--r-- | tests/unit_tests/openvpn/test_tls_crypt.c | 206 | ||||
-rw-r--r-- | tests/unit_tests/plugins/Makefile.in | 2 | ||||
-rw-r--r-- | tests/unit_tests/plugins/auth-pam/Makefile.in | 6 | ||||
-rw-r--r-- | tests/unit_tests/plugins/auth-pam/test_search_and_replace.c | 71 |
16 files changed, 484 insertions, 303 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index e55928b..0795680 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,7 +5,7 @@ # packet encryption, packet authentication, and # packet compression. # -# Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net> +# Copyright (C) 2002-2017 OpenVPN Technologies, Inc. <sales@openvpn.net> # Copyright (C) 2006-2012 Alon Bar-Lev <alon.barlev@gmail.com> # diff --git a/tests/Makefile.in b/tests/Makefile.in index 960808d..b9e19a8 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.13.4 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -21,7 +21,7 @@ # packet encryption, packet authentication, and # packet compression. # -# Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net> +# Copyright (C) 2002-2017 OpenVPN Technologies, Inc. <sales@openvpn.net> # Copyright (C) 2006-2012 Alon Bar-Lev <alon.barlev@gmail.com> # diff --git a/tests/t_client.sh b/tests/t_client.sh index 09dd26f..b51813e 100755 --- a/tests/t_client.sh +++ b/tests/t_client.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # run OpenVPN client against ``test reference'' server # - check that ping, http, ... via tunnel works @@ -133,12 +133,12 @@ fail() get_ifconfig_route() { # linux / iproute2? (-> if configure got a path) - if [ -n "/bin/ip" ] + if [ -n "/usr/sbin/ip" ] then echo "-- linux iproute2 --" - /bin/ip addr show | grep -v valid_lft - /bin/ip route show - /bin/ip -o -6 route show | grep -v ' cache' | sed -E -e 's/ expires [0-9]*sec//' -e 's/ (mtu|hoplimit|cwnd|ssthresh) [0-9]+//g' -e 's/ (rtt|rttvar) [0-9]+ms//g' + /usr/sbin/ip addr show | grep -v valid_lft + /usr/sbin/ip route show + /usr/sbin/ip -o -6 route show | grep -v ' cache' | sed -E -e 's/ expires [0-9]*sec//' -e 's/ (mtu|hoplimit|cwnd|ssthresh) [0-9]+//g' -e 's/ (rtt|rttvar) [0-9]+ms//g' return fi @@ -146,32 +146,32 @@ get_ifconfig_route() case `uname -s` in Linux) echo "-- linux / ifconfig --" - LANG=C /sbin/ifconfig -a |egrep "( addr:|encap:)" + LANG=C /usr/sbin/ifconfig -a |egrep "( addr:|encap:)" LANG=C netstat -rn -4 -6 return ;; FreeBSD|NetBSD|Darwin) echo "-- FreeBSD/NetBSD/Darwin [MacOS X] --" - /sbin/ifconfig -a | egrep "(flags=|inet)" + /usr/sbin/ifconfig -a | egrep "(flags=|inet)" netstat -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }' return ;; OpenBSD) echo "-- OpenBSD --" - /sbin/ifconfig -a | egrep "(flags=|inet)" | \ + /usr/sbin/ifconfig -a | egrep "(flags=|inet)" | \ sed -e 's/pltime [0-9]*//' -e 's/vltime [0-9]*//' netstat -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }' return ;; SunOS) echo "-- Solaris --" - /sbin/ifconfig -a | egrep "(flags=|inet)" + /usr/sbin/ifconfig -a | egrep "(flags=|inet)" netstat -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$6 }' return ;; AIX) echo "-- AIX --" - /sbin/ifconfig -a | egrep "(flags=|inet)" + /usr/sbin/ifconfig -a | egrep "(flags=|inet)" netstat -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$6 }' return ;; diff --git a/tests/unit_tests/Makefile.in b/tests/unit_tests/Makefile.in index 0d5674c..6cc6043 100644 --- a/tests/unit_tests/Makefile.in +++ b/tests/unit_tests/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.13.4 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. diff --git a/tests/unit_tests/example_test/Makefile.in b/tests/unit_tests/example_test/Makefile.in index 6ac7504..ff4f6c4 100644 --- a/tests/unit_tests/example_test/Makefile.in +++ b/tests/unit_tests/example_test/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.13.4 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -446,14 +446,14 @@ distclean-compile: @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/tests/unit_tests/example_test/test.c b/tests/unit_tests/example_test/test.c index 9986898..d48e5f5 100644 --- a/tests/unit_tests/example_test/test.c +++ b/tests/unit_tests/example_test/test.c @@ -6,40 +6,46 @@ #include <setjmp.h> #include <cmocka.h> -static int setup(void **state) { - int *answer = malloc(sizeof(int)); +static int +setup(void **state) { + int *answer = malloc(sizeof(int)); - *answer=42; - *state=answer; + *answer = 42; + *state = answer; - return 0; + return 0; } -static int teardown(void **state) { - free(*state); +static int +teardown(void **state) { + free(*state); - return 0; + return 0; } -static void null_test_success(void **state) { +static void +null_test_success(void **state) { (void) state; } -static void int_test_success(void **state) { - int *answer = *state; - assert_int_equal(*answer, 42); +static void +int_test_success(void **state) { + int *answer = *state; + assert_int_equal(*answer, 42); } -static void failing_test(void **state) { - // This tests fails to test that make check fails - assert_int_equal(0, 42); +static void +failing_test(void **state) { + /* This tests fails to test that make check fails */ + assert_int_equal(0, 42); } -int main(void) { +int +main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(null_test_success), cmocka_unit_test_setup_teardown(int_test_success, setup, teardown), -// cmocka_unit_test(failing_test), +/* cmocka_unit_test(failing_test), */ }; return cmocka_run_group_tests_name("success_test", tests, NULL, NULL); diff --git a/tests/unit_tests/example_test/test2.c b/tests/unit_tests/example_test/test2.c index f99da9e..b5d4fa6 100644 --- a/tests/unit_tests/example_test/test2.c +++ b/tests/unit_tests/example_test/test2.c @@ -7,12 +7,14 @@ #include <cmocka.h> -static void test_true(void **state) { +static void +test_true(void **state) { (void) state; } -int main(void) { +int +main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(test_true), }; diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvpn/Makefile.am index 632ff58..fafe6b2 100644 --- a/tests/unit_tests/openvpn/Makefile.am +++ b/tests/unit_tests/openvpn/Makefile.am @@ -1,6 +1,6 @@ AUTOMAKE_OPTIONS = foreign -check_PROGRAMS = argv_testdriver +check_PROGRAMS = argv_testdriver buffer_testdriver if ENABLE_CRYPTO check_PROGRAMS += tls_crypt_testdriver @@ -21,6 +21,12 @@ argv_testdriver_SOURCES = test_argv.c mock_msg.c \ $(openvpn_srcdir)/buffer.c \ $(openvpn_srcdir)/argv.c +buffer_testdriver_CFLAGS = @TEST_CFLAGS@ -I$(openvpn_srcdir) -I$(compat_srcdir) +buffer_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(openvpn_srcdir) -Wl,--wrap=parse_line +buffer_testdriver_SOURCES = test_buffer.c mock_msg.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/platform.c + tls_crypt_testdriver_CFLAGS = @TEST_CFLAGS@ \ -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \ $(OPTIONAL_CRYPTO_CFLAGS) diff --git a/tests/unit_tests/openvpn/Makefile.in b/tests/unit_tests/openvpn/Makefile.in index 198d387..02ab3cf 100644 --- a/tests/unit_tests/openvpn/Makefile.in +++ b/tests/unit_tests/openvpn/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.13.4 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -77,7 +77,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -check_PROGRAMS = argv_testdriver$(EXEEXT) $(am__EXEEXT_1) +check_PROGRAMS = argv_testdriver$(EXEEXT) buffer_testdriver$(EXEEXT) \ + $(am__EXEEXT_1) @ENABLE_CRYPTO_TRUE@am__append_1 = tls_crypt_testdriver subdir = tests/unit_tests/openvpn DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ @@ -113,6 +114,17 @@ argv_testdriver_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ $(argv_testdriver_CFLAGS) $(CFLAGS) $(argv_testdriver_LDFLAGS) \ $(LDFLAGS) -o $@ +am_buffer_testdriver_OBJECTS = \ + buffer_testdriver-test_buffer.$(OBJEXT) \ + buffer_testdriver-mock_msg.$(OBJEXT) \ + buffer_testdriver-buffer.$(OBJEXT) \ + buffer_testdriver-platform.$(OBJEXT) +buffer_testdriver_OBJECTS = $(am_buffer_testdriver_OBJECTS) +buffer_testdriver_LDADD = $(LDADD) +buffer_testdriver_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(buffer_testdriver_CFLAGS) $(CFLAGS) \ + $(buffer_testdriver_LDFLAGS) $(LDFLAGS) -o $@ am_tls_crypt_testdriver_OBJECTS = \ tls_crypt_testdriver-test_tls_crypt.$(OBJEXT) \ tls_crypt_testdriver-mock_msg.$(OBJEXT) \ @@ -164,8 +176,9 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(argv_testdriver_SOURCES) $(tls_crypt_testdriver_SOURCES) -DIST_SOURCES = $(argv_testdriver_SOURCES) \ +SOURCES = $(argv_testdriver_SOURCES) $(buffer_testdriver_SOURCES) \ + $(tls_crypt_testdriver_SOURCES) +DIST_SOURCES = $(argv_testdriver_SOURCES) $(buffer_testdriver_SOURCES) \ $(tls_crypt_testdriver_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ @@ -403,6 +416,12 @@ argv_testdriver_SOURCES = test_argv.c mock_msg.c \ $(openvpn_srcdir)/buffer.c \ $(openvpn_srcdir)/argv.c +buffer_testdriver_CFLAGS = @TEST_CFLAGS@ -I$(openvpn_srcdir) -I$(compat_srcdir) +buffer_testdriver_LDFLAGS = @TEST_LDFLAGS@ -L$(openvpn_srcdir) -Wl,--wrap=parse_line +buffer_testdriver_SOURCES = test_buffer.c mock_msg.c \ + $(openvpn_srcdir)/buffer.c \ + $(openvpn_srcdir)/platform.c + tls_crypt_testdriver_CFLAGS = @TEST_CFLAGS@ \ -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \ $(OPTIONAL_CRYPTO_CFLAGS) @@ -468,6 +487,10 @@ argv_testdriver$(EXEEXT): $(argv_testdriver_OBJECTS) $(argv_testdriver_DEPENDENC @rm -f argv_testdriver$(EXEEXT) $(AM_V_CCLD)$(argv_testdriver_LINK) $(argv_testdriver_OBJECTS) $(argv_testdriver_LDADD) $(LIBS) +buffer_testdriver$(EXEEXT): $(buffer_testdriver_OBJECTS) $(buffer_testdriver_DEPENDENCIES) $(EXTRA_buffer_testdriver_DEPENDENCIES) + @rm -f buffer_testdriver$(EXEEXT) + $(AM_V_CCLD)$(buffer_testdriver_LINK) $(buffer_testdriver_OBJECTS) $(buffer_testdriver_LDADD) $(LIBS) + tls_crypt_testdriver$(EXEEXT): $(tls_crypt_testdriver_OBJECTS) $(tls_crypt_testdriver_DEPENDENCIES) $(EXTRA_tls_crypt_testdriver_DEPENDENCIES) @rm -f tls_crypt_testdriver$(EXEEXT) $(AM_V_CCLD)$(tls_crypt_testdriver_LINK) $(tls_crypt_testdriver_OBJECTS) $(tls_crypt_testdriver_LDADD) $(LIBS) @@ -483,6 +506,10 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/argv_testdriver-mock_msg.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/argv_testdriver-platform.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/argv_testdriver-test_argv.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer_testdriver-buffer.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer_testdriver-mock_msg.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer_testdriver-platform.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer_testdriver-test_buffer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tls_crypt_testdriver-buffer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tls_crypt_testdriver-crypto.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tls_crypt_testdriver-crypto_mbedtls.Po@am__quote@ @@ -499,14 +526,14 @@ distclean-compile: @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -585,6 +612,62 @@ argv_testdriver-argv.obj: $(openvpn_srcdir)/argv.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(argv_testdriver_CFLAGS) $(CFLAGS) -c -o argv_testdriver-argv.obj `if test -f '$(openvpn_srcdir)/argv.c'; then $(CYGPATH_W) '$(openvpn_srcdir)/argv.c'; else $(CYGPATH_W) '$(srcdir)/$(openvpn_srcdir)/argv.c'; fi` +buffer_testdriver-test_buffer.o: test_buffer.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-test_buffer.o -MD -MP -MF $(DEPDIR)/buffer_testdriver-test_buffer.Tpo -c -o buffer_testdriver-test_buffer.o `test -f 'test_buffer.c' || echo '$(srcdir)/'`test_buffer.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-test_buffer.Tpo $(DEPDIR)/buffer_testdriver-test_buffer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test_buffer.c' object='buffer_testdriver-test_buffer.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-test_buffer.o `test -f 'test_buffer.c' || echo '$(srcdir)/'`test_buffer.c + +buffer_testdriver-test_buffer.obj: test_buffer.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-test_buffer.obj -MD -MP -MF $(DEPDIR)/buffer_testdriver-test_buffer.Tpo -c -o buffer_testdriver-test_buffer.obj `if test -f 'test_buffer.c'; then $(CYGPATH_W) 'test_buffer.c'; else $(CYGPATH_W) '$(srcdir)/test_buffer.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-test_buffer.Tpo $(DEPDIR)/buffer_testdriver-test_buffer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='test_buffer.c' object='buffer_testdriver-test_buffer.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-test_buffer.obj `if test -f 'test_buffer.c'; then $(CYGPATH_W) 'test_buffer.c'; else $(CYGPATH_W) '$(srcdir)/test_buffer.c'; fi` + +buffer_testdriver-mock_msg.o: mock_msg.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-mock_msg.o -MD -MP -MF $(DEPDIR)/buffer_testdriver-mock_msg.Tpo -c -o buffer_testdriver-mock_msg.o `test -f 'mock_msg.c' || echo '$(srcdir)/'`mock_msg.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-mock_msg.Tpo $(DEPDIR)/buffer_testdriver-mock_msg.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mock_msg.c' object='buffer_testdriver-mock_msg.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-mock_msg.o `test -f 'mock_msg.c' || echo '$(srcdir)/'`mock_msg.c + +buffer_testdriver-mock_msg.obj: mock_msg.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-mock_msg.obj -MD -MP -MF $(DEPDIR)/buffer_testdriver-mock_msg.Tpo -c -o buffer_testdriver-mock_msg.obj `if test -f 'mock_msg.c'; then $(CYGPATH_W) 'mock_msg.c'; else $(CYGPATH_W) '$(srcdir)/mock_msg.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-mock_msg.Tpo $(DEPDIR)/buffer_testdriver-mock_msg.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='mock_msg.c' object='buffer_testdriver-mock_msg.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-mock_msg.obj `if test -f 'mock_msg.c'; then $(CYGPATH_W) 'mock_msg.c'; else $(CYGPATH_W) '$(srcdir)/mock_msg.c'; fi` + +buffer_testdriver-buffer.o: $(openvpn_srcdir)/buffer.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-buffer.o -MD -MP -MF $(DEPDIR)/buffer_testdriver-buffer.Tpo -c -o buffer_testdriver-buffer.o `test -f '$(openvpn_srcdir)/buffer.c' || echo '$(srcdir)/'`$(openvpn_srcdir)/buffer.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-buffer.Tpo $(DEPDIR)/buffer_testdriver-buffer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(openvpn_srcdir)/buffer.c' object='buffer_testdriver-buffer.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-buffer.o `test -f '$(openvpn_srcdir)/buffer.c' || echo '$(srcdir)/'`$(openvpn_srcdir)/buffer.c + +buffer_testdriver-buffer.obj: $(openvpn_srcdir)/buffer.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-buffer.obj -MD -MP -MF $(DEPDIR)/buffer_testdriver-buffer.Tpo -c -o buffer_testdriver-buffer.obj `if test -f '$(openvpn_srcdir)/buffer.c'; then $(CYGPATH_W) '$(openvpn_srcdir)/buffer.c'; else $(CYGPATH_W) '$(srcdir)/$(openvpn_srcdir)/buffer.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-buffer.Tpo $(DEPDIR)/buffer_testdriver-buffer.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(openvpn_srcdir)/buffer.c' object='buffer_testdriver-buffer.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-buffer.obj `if test -f '$(openvpn_srcdir)/buffer.c'; then $(CYGPATH_W) '$(openvpn_srcdir)/buffer.c'; else $(CYGPATH_W) '$(srcdir)/$(openvpn_srcdir)/buffer.c'; fi` + +buffer_testdriver-platform.o: $(openvpn_srcdir)/platform.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-platform.o -MD -MP -MF $(DEPDIR)/buffer_testdriver-platform.Tpo -c -o buffer_testdriver-platform.o `test -f '$(openvpn_srcdir)/platform.c' || echo '$(srcdir)/'`$(openvpn_srcdir)/platform.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-platform.Tpo $(DEPDIR)/buffer_testdriver-platform.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(openvpn_srcdir)/platform.c' object='buffer_testdriver-platform.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-platform.o `test -f '$(openvpn_srcdir)/platform.c' || echo '$(srcdir)/'`$(openvpn_srcdir)/platform.c + +buffer_testdriver-platform.obj: $(openvpn_srcdir)/platform.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -MT buffer_testdriver-platform.obj -MD -MP -MF $(DEPDIR)/buffer_testdriver-platform.Tpo -c -o buffer_testdriver-platform.obj `if test -f '$(openvpn_srcdir)/platform.c'; then $(CYGPATH_W) '$(openvpn_srcdir)/platform.c'; else $(CYGPATH_W) '$(srcdir)/$(openvpn_srcdir)/platform.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/buffer_testdriver-platform.Tpo $(DEPDIR)/buffer_testdriver-platform.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$(openvpn_srcdir)/platform.c' object='buffer_testdriver-platform.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(buffer_testdriver_CFLAGS) $(CFLAGS) -c -o buffer_testdriver-platform.obj `if test -f '$(openvpn_srcdir)/platform.c'; then $(CYGPATH_W) '$(openvpn_srcdir)/platform.c'; else $(CYGPATH_W) '$(srcdir)/$(openvpn_srcdir)/platform.c'; fi` + tls_crypt_testdriver-test_tls_crypt.o: test_tls_crypt.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(tls_crypt_testdriver_CFLAGS) $(CFLAGS) -MT tls_crypt_testdriver-test_tls_crypt.o -MD -MP -MF $(DEPDIR)/tls_crypt_testdriver-test_tls_crypt.Tpo -c -o tls_crypt_testdriver-test_tls_crypt.o `test -f 'test_tls_crypt.c' || echo '$(srcdir)/'`test_tls_crypt.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/tls_crypt_testdriver-test_tls_crypt.Tpo $(DEPDIR)/tls_crypt_testdriver-test_tls_crypt.Po diff --git a/tests/unit_tests/openvpn/mock_msg.c b/tests/unit_tests/openvpn/mock_msg.c index 54b6017..eb0d5e9 100644 --- a/tests/unit_tests/openvpn/mock_msg.c +++ b/tests/unit_tests/openvpn/mock_msg.c @@ -5,7 +5,7 @@ * packet encryption, packet authentication, and * packet compression. * - * Copyright (C) 2016 Fox Crypto B.V. <openvpn@fox-it.com> + * Copyright (C) 2016-2017 Fox Crypto B.V. <openvpn@fox-it.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -39,39 +39,46 @@ unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */ bool fatal_error_triggered = false; -void mock_set_debug_level(int level) +void +mock_set_debug_level(int level) { - x_debug_level = level; + x_debug_level = level; } -void x_msg_va (const unsigned int flags, const char *format, - va_list arglist) +void +x_msg_va(const unsigned int flags, const char *format, + va_list arglist) { - if (flags & M_FATAL) + if (flags & M_FATAL) { - fatal_error_triggered = true; - printf("FATAL ERROR:"); + fatal_error_triggered = true; + printf("FATAL ERROR:"); } - vprintf(format, arglist); - printf("\n"); + vprintf(format, arglist); + printf("\n"); } -void x_msg (const unsigned int flags, const char *format, ...) +void +x_msg(const unsigned int flags, const char *format, ...) { - va_list arglist; - va_start (arglist, format); - x_msg_va (flags, format, arglist); - va_end (arglist); + va_list arglist; + va_start(arglist, format); + x_msg_va(flags, format, arglist); + va_end(arglist); } void -assert_failed (const char *filename, int line, const char *condition) +assert_failed(const char *filename, int line, const char *condition) { - if (condition) - printf ("Assertion failed at %s:%d (%s)", filename, line, condition); - else - printf ("Assertion failed at %s:%d", filename, line); - exit (1); + if (condition) + { + printf("Assertion failed at %s:%d (%s)", filename, line, condition); + } + else + { + printf("Assertion failed at %s:%d", filename, line); + } + exit(1); } /* @@ -79,14 +86,14 @@ assert_failed (const char *filename, int line, const char *condition) * to allocate memory as part of its operation. */ void -out_of_memory (void) +out_of_memory(void) { - fprintf (stderr, "Out of Memory\n"); - exit (1); + fprintf(stderr, "Out of Memory\n"); + exit(1); } bool -dont_mute (unsigned int flags) +dont_mute(unsigned int flags) { - return true; + return true; } diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvpn/test_argv.c index 4d17557..8c90eb9 100644 --- a/tests/unit_tests/openvpn/test_argv.c +++ b/tests/unit_tests/openvpn/test_argv.c @@ -18,17 +18,17 @@ * which makes things difficult beyond any recognition */ size_t -adjust_power_of_2 (size_t u) +adjust_power_of_2(size_t u) { - size_t ret = 1; + size_t ret = 1; - while (ret < u) + while (ret < u) { - ret <<= 1; - assert (ret > 0); + ret <<= 1; + assert(ret > 0); } - return ret; + return ret; } /* Defines for use in the tests and the mock parse_line() */ @@ -39,156 +39,160 @@ adjust_power_of_2 (size_t u) #define SCRIPT_CMD "\"" PATH1 PATH2 "\"" PARAM1 "\"" PARAM2 "\"" int -__wrap_parse_line (const char *line, char **p, const int n, const char *file, - const int line_num, int msglevel, struct gc_arena *gc) +__wrap_parse_line(const char *line, char **p, const int n, const char *file, + const int line_num, int msglevel, struct gc_arena *gc) { - p[0] = PATH1 PATH2; - p[1] = PARAM1; - p[2] = PARAM2; - return 3; + p[0] = PATH1 PATH2; + p[1] = PARAM1; + p[2] = PARAM2; + return 3; } static void -argv_printf__multiple_spaces_in_format__parsed_as_one (void **state) +argv_printf__multiple_spaces_in_format__parsed_as_one(void **state) { - struct argv a = argv_new (); + struct argv a = argv_new(); - argv_printf (&a, " %s %s %d ", PATH1, PATH2, 42); - assert_int_equal (a.argc, 3); + argv_printf(&a, " %s %s %d ", PATH1, PATH2, 42); + assert_int_equal(a.argc, 3); - argv_reset (&a); + argv_reset(&a); } static void -argv_printf_cat__multiple_spaces_in_format__parsed_as_one (void **state) +argv_printf_cat__multiple_spaces_in_format__parsed_as_one(void **state) { - struct argv a = argv_new (); + struct argv a = argv_new(); - argv_printf (&a, "%s ", PATH1); - argv_printf_cat (&a, " %s %s", PATH2, PARAM1); - assert_int_equal (a.argc, 3); + argv_printf(&a, "%s ", PATH1); + argv_printf_cat(&a, " %s %s", PATH2, PARAM1); + assert_int_equal(a.argc, 3); - argv_reset (&a); + argv_reset(&a); } static void -argv_printf__combined_path_with_spaces__argc_correct (void **state) +argv_printf__combined_path_with_spaces__argc_correct(void **state) { - struct argv a = argv_new (); + struct argv a = argv_new(); - argv_printf (&a, "%s%sc", PATH1, PATH2); - assert_int_equal (a.argc, 1); + argv_printf(&a, "%s%sc", PATH1, PATH2); + assert_int_equal(a.argc, 1); - argv_printf (&a, "%s%sc %d", PATH1, PATH2, 42); - assert_int_equal (a.argc, 2); + argv_printf(&a, "%s%sc %d", PATH1, PATH2, 42); + assert_int_equal(a.argc, 2); - argv_printf (&a, "foo %s%sc %s x y", PATH2, PATH1, "foo"); - assert_int_equal (a.argc, 5); + argv_printf(&a, "foo %s%sc %s x y", PATH2, PATH1, "foo"); + assert_int_equal(a.argc, 5); - argv_reset (&a); + argv_reset(&a); } static void -argv_parse_cmd__command_string__argc_correct (void **state) +argv_parse_cmd__command_string__argc_correct(void **state) { - struct argv a = argv_new (); + struct argv a = argv_new(); - argv_parse_cmd (&a, SCRIPT_CMD); - assert_int_equal (a.argc, 3); + argv_parse_cmd(&a, SCRIPT_CMD); + assert_int_equal(a.argc, 3); - argv_reset (&a); + argv_reset(&a); } static void -argv_parse_cmd__command_and_extra_options__argc_correct (void **state) +argv_parse_cmd__command_and_extra_options__argc_correct(void **state) { - struct argv a = argv_new (); + struct argv a = argv_new(); - argv_parse_cmd (&a, SCRIPT_CMD); - argv_printf_cat (&a, "bar baz %d %s", 42, PATH1); - assert_int_equal (a.argc, 7); + argv_parse_cmd(&a, SCRIPT_CMD); + argv_printf_cat(&a, "bar baz %d %s", 42, PATH1); + assert_int_equal(a.argc, 7); - argv_reset (&a); + argv_reset(&a); } static void -argv_printf_cat__used_twice__argc_correct (void **state) +argv_printf_cat__used_twice__argc_correct(void **state) { - struct argv a = argv_new (); + struct argv a = argv_new(); - argv_printf (&a, "%s %s %s", PATH1, PATH2, PARAM1); - argv_printf_cat (&a, "%s", PARAM2); - argv_printf_cat (&a, "foo"); - assert_int_equal (a.argc, 5); + argv_printf(&a, "%s %s %s", PATH1, PATH2, PARAM1); + argv_printf_cat(&a, "%s", PARAM2); + argv_printf_cat(&a, "foo"); + assert_int_equal(a.argc, 5); - argv_reset (&a); + argv_reset(&a); } static void -argv_str__multiple_argv__correct_output (void **state) +argv_str__multiple_argv__correct_output(void **state) { - struct argv a = argv_new (); - struct gc_arena gc = gc_new (); - const char *output; - - argv_printf (&a, "%s%sc", PATH1, PATH2); - argv_printf_cat (&a, "%s", PARAM1); - argv_printf_cat (&a, "%s", PARAM2); - output = argv_str (&a, &gc, PA_BRACKET); - assert_string_equal (output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"); - - argv_reset (&a); - gc_free (&gc); + struct argv a = argv_new(); + struct gc_arena gc = gc_new(); + const char *output; + + argv_printf(&a, "%s%sc", PATH1, PATH2); + argv_printf_cat(&a, "%s", PARAM1); + argv_printf_cat(&a, "%s", PARAM2); + output = argv_str(&a, &gc, PA_BRACKET); + assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"); + + argv_reset(&a); + gc_free(&gc); } static void -argv_insert_head__empty_argv__head_only (void **state) +argv_insert_head__empty_argv__head_only(void **state) { - struct argv a = argv_new (); - struct argv b; + struct argv a = argv_new(); + struct argv b; - b = argv_insert_head (&a, PATH1); - assert_int_equal (b.argc, 1); - assert_string_equal (b.argv[0], PATH1); - argv_reset (&b); + b = argv_insert_head(&a, PATH1); + assert_int_equal(b.argc, 1); + assert_string_equal(b.argv[0], PATH1); + argv_reset(&b); - argv_reset (&a); + argv_reset(&a); } static void -argv_insert_head__non_empty_argv__head_added (void **state) +argv_insert_head__non_empty_argv__head_added(void **state) { - struct argv a = argv_new (); - struct argv b; - int i; - - argv_printf (&a, "%s", PATH2); - b = argv_insert_head (&a, PATH1); - assert_int_equal (b.argc, a.argc + 1); - for (i = 0; i < b.argc; i++) { - if (i == 0) - assert_string_equal (b.argv[i], PATH1); - else - assert_string_equal (b.argv[i], a.argv[i - 1]); - } - argv_reset (&b); - - argv_reset (&a); + struct argv a = argv_new(); + struct argv b; + int i; + + argv_printf(&a, "%s", PATH2); + b = argv_insert_head(&a, PATH1); + assert_int_equal(b.argc, a.argc + 1); + for (i = 0; i < b.argc; i++) { + if (i == 0) + { + assert_string_equal(b.argv[i], PATH1); + } + else + { + assert_string_equal(b.argv[i], a.argv[i - 1]); + } + } + argv_reset(&b); + + argv_reset(&a); } int main(void) { - const struct CMUnitTest tests[] = { - cmocka_unit_test (argv_printf__multiple_spaces_in_format__parsed_as_one), - cmocka_unit_test (argv_printf_cat__multiple_spaces_in_format__parsed_as_one), - cmocka_unit_test (argv_printf__combined_path_with_spaces__argc_correct), - cmocka_unit_test (argv_parse_cmd__command_string__argc_correct), - cmocka_unit_test (argv_parse_cmd__command_and_extra_options__argc_correct), - cmocka_unit_test (argv_printf_cat__used_twice__argc_correct), - cmocka_unit_test (argv_str__multiple_argv__correct_output), - cmocka_unit_test (argv_insert_head__non_empty_argv__head_added), - }; - - return cmocka_run_group_tests_name ("argv", tests, NULL, NULL); + const struct CMUnitTest tests[] = { + cmocka_unit_test(argv_printf__multiple_spaces_in_format__parsed_as_one), + cmocka_unit_test(argv_printf_cat__multiple_spaces_in_format__parsed_as_one), + cmocka_unit_test(argv_printf__combined_path_with_spaces__argc_correct), + cmocka_unit_test(argv_parse_cmd__command_string__argc_correct), + cmocka_unit_test(argv_parse_cmd__command_and_extra_options__argc_correct), + cmocka_unit_test(argv_printf_cat__used_twice__argc_correct), + cmocka_unit_test(argv_str__multiple_argv__correct_output), + cmocka_unit_test(argv_insert_head__non_empty_argv__head_added), + }; + + return cmocka_run_group_tests_name("argv", tests, NULL, NULL); } diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c new file mode 100644 index 0000000..5158eb8 --- /dev/null +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -0,0 +1,56 @@ +/* + * OpenVPN -- An application to securely tunnel IP networks + * over a single UDP port, with support for SSL/TLS-based + * session authentication and key exchange, + * packet encryption, packet authentication, and + * packet compression. + * + * Copyright (C) 2016-2017 Fox Crypto B.V. <openvpn@fox-it.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 + * 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 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 (see the file COPYING included with this + * distribution); if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#elif defined(_MSC_VER) +#include "config-msvc.h" +#endif + +#include "syshead.h" + +#include <setjmp.h> +#include <cmocka.h> + +#include "buffer.h" + +static void +buffer_strprefix(void **state) +{ + assert_true(strprefix("123456", "123456")); + assert_true(strprefix("123456", "123")); + assert_true(strprefix("123456", "")); + assert_false(strprefix("123456", "456")); + assert_false(strprefix("12", "123")); +} + +int +main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(buffer_strprefix), + }; + + return cmocka_run_group_tests_name("buffer", tests, NULL, NULL); +} diff --git a/tests/unit_tests/openvpn/test_tls_crypt.c b/tests/unit_tests/openvpn/test_tls_crypt.c index 473a232..7b014e0 100644 --- a/tests/unit_tests/openvpn/test_tls_crypt.c +++ b/tests/unit_tests/openvpn/test_tls_crypt.c @@ -5,7 +5,7 @@ * packet encryption, packet authentication, and * packet compression. * - * Copyright (C) 2016 Fox Crypto B.V. <openvpn@fox-it.com> + * Copyright (C) 2016-2017 Fox Crypto B.V. <openvpn@fox-it.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 @@ -44,32 +44,33 @@ #include "mock_msg.h" -#define TESTBUF_SIZE 128 +#define TESTBUF_SIZE 128 const char plaintext_short[1]; struct test_context { - struct crypto_options co; - struct key_type kt; - struct buffer source; - struct buffer ciphertext; - struct buffer unwrapped; + struct crypto_options co; + struct key_type kt; + struct buffer source; + struct buffer ciphertext; + struct buffer unwrapped; }; -static int setup(void **state) { +static int +setup(void **state) { struct test_context *ctx = calloc(1, sizeof(*ctx)); - ctx->kt.cipher = cipher_kt_get ("AES-256-CTR"); - ctx->kt.cipher_length = cipher_kt_key_size (ctx->kt.cipher); - ctx->kt.digest = md_kt_get ("SHA256"); - ctx->kt.hmac_length = md_kt_size (ctx->kt.digest); + ctx->kt.cipher = cipher_kt_get("AES-256-CTR"); + ctx->kt.cipher_length = cipher_kt_key_size(ctx->kt.cipher); + ctx->kt.digest = md_kt_get("SHA256"); + ctx->kt.hmac_length = md_kt_size(ctx->kt.digest); struct key key = { 0 }; - init_key_ctx (&ctx->co.key_ctx_bi.encrypt, &key, &ctx->kt, true, "TEST"); - init_key_ctx (&ctx->co.key_ctx_bi.decrypt, &key, &ctx->kt, false, "TEST"); + init_key_ctx(&ctx->co.key_ctx_bi.encrypt, &key, &ctx->kt, true, "TEST"); + init_key_ctx(&ctx->co.key_ctx_bi.decrypt, &key, &ctx->kt, false, "TEST"); - packet_id_init (&ctx->co.packet_id, 0, 0, "test", 0); + packet_id_init(&ctx->co.packet_id, 0, 0, "test", 0); ctx->source = alloc_buf(TESTBUF_SIZE); ctx->ciphertext = alloc_buf(TESTBUF_SIZE); @@ -86,14 +87,15 @@ static int setup(void **state) { return 0; } -static int teardown(void **state) { +static int +teardown(void **state) { struct test_context *ctx = (struct test_context *) *state; - free_buf (&ctx->source); - free_buf (&ctx->ciphertext); - free_buf (&ctx->unwrapped); + free_buf(&ctx->source); + free_buf(&ctx->ciphertext); + free_buf(&ctx->unwrapped); - free_key_ctx_bi (&ctx->co.key_ctx_bi); + free_key_ctx_bi(&ctx->co.key_ctx_bi); free(ctx); @@ -103,92 +105,98 @@ static int teardown(void **state) { /** * Check that short messages are successfully wrapped-and-unwrapped. */ -static void tls_crypt_loopback(void **state) { - struct test_context *ctx = (struct test_context *) *state; - - assert_true (tls_crypt_wrap (&ctx->source, &ctx->ciphertext, &ctx->co)); - assert_true (BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); - assert_true (tls_crypt_unwrap (&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); - assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); - assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), - BLEN(&ctx->source)); +static void +tls_crypt_loopback(void **state) { + struct test_context *ctx = (struct test_context *) *state; + + assert_true(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); + assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); + assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); + assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); + assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), + BLEN(&ctx->source)); } /** * Check that zero-byte messages are successfully wrapped-and-unwrapped. */ -static void tls_crypt_loopback_zero_len(void **state) { - struct test_context *ctx = (struct test_context *) *state; +static void +tls_crypt_loopback_zero_len(void **state) { + struct test_context *ctx = (struct test_context *) *state; - buf_clear(&ctx->source); + buf_clear(&ctx->source); - assert_true (tls_crypt_wrap (&ctx->source, &ctx->ciphertext, &ctx->co)); - assert_true (BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); - assert_true (tls_crypt_unwrap (&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); - assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); - assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), - BLEN(&ctx->source)); + assert_true(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); + assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); + assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); + assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); + assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), + BLEN(&ctx->source)); } /** * Check that max-length messages are successfully wrapped-and-unwrapped. */ -static void tls_crypt_loopback_max_len(void **state) { - struct test_context *ctx = (struct test_context *) *state; - - buf_clear(&ctx->source); - assert_non_null (buf_write_alloc (&ctx->source, - TESTBUF_SIZE - BLEN (&ctx->ciphertext) - tls_crypt_buf_overhead())); - - assert_true (tls_crypt_wrap (&ctx->source, &ctx->ciphertext, &ctx->co)); - assert_true (BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); - assert_true (tls_crypt_unwrap (&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); - assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); - assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), - BLEN(&ctx->source)); +static void +tls_crypt_loopback_max_len(void **state) { + struct test_context *ctx = (struct test_context *) *state; + + buf_clear(&ctx->source); + assert_non_null(buf_write_alloc(&ctx->source, + TESTBUF_SIZE - BLEN(&ctx->ciphertext) - tls_crypt_buf_overhead())); + + assert_true(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); + assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); + assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); + assert_int_equal(BLEN(&ctx->source), BLEN(&ctx->unwrapped)); + assert_memory_equal(BPTR(&ctx->source), BPTR(&ctx->unwrapped), + BLEN(&ctx->source)); } /** * Check that too-long messages are gracefully rejected. */ -static void tls_crypt_fail_msg_too_long(void **state) { - struct test_context *ctx = (struct test_context *) *state; +static void +tls_crypt_fail_msg_too_long(void **state) { + struct test_context *ctx = (struct test_context *) *state; - buf_clear(&ctx->source); - assert_non_null (buf_write_alloc (&ctx->source, - TESTBUF_SIZE - BLEN (&ctx->ciphertext) - tls_crypt_buf_overhead() + 1)); - assert_false (tls_crypt_wrap (&ctx->source, &ctx->ciphertext, &ctx->co)); + buf_clear(&ctx->source); + assert_non_null(buf_write_alloc(&ctx->source, + TESTBUF_SIZE - BLEN(&ctx->ciphertext) - tls_crypt_buf_overhead() + 1)); + assert_false(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); } /** * Check that packets that were wrapped (or unwrapped) with a different key * are not accepted. */ -static void tls_crypt_fail_invalid_key(void **state) { - struct test_context *ctx = (struct test_context *) *state; +static void +tls_crypt_fail_invalid_key(void **state) { + struct test_context *ctx = (struct test_context *) *state; - /* Change decrypt key */ - struct key key = { { 1 } }; - free_key_ctx (&ctx->co.key_ctx_bi.decrypt); - init_key_ctx (&ctx->co.key_ctx_bi.decrypt, &key, &ctx->kt, false, "TEST"); + /* Change decrypt key */ + struct key key = { { 1 } }; + free_key_ctx(&ctx->co.key_ctx_bi.decrypt); + init_key_ctx(&ctx->co.key_ctx_bi.decrypt, &key, &ctx->kt, false, "TEST"); - assert_true (tls_crypt_wrap (&ctx->source, &ctx->ciphertext, &ctx->co)); - assert_true (BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); - assert_false (tls_crypt_unwrap (&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); + assert_true(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); + assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); + assert_false(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); } /** * Check that replayed packets are not accepted. */ -static void tls_crypt_fail_replay(void **state) { - struct test_context *ctx = (struct test_context *) *state; - - assert_true (tls_crypt_wrap (&ctx->source, &ctx->ciphertext, &ctx->co)); - assert_true (BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); - struct buffer tmp = ctx->ciphertext; - assert_true (tls_crypt_unwrap (&tmp, &ctx->unwrapped, &ctx->co)); - buf_clear (&ctx->unwrapped); - assert_false (tls_crypt_unwrap (&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); +static void +tls_crypt_fail_replay(void **state) { + struct test_context *ctx = (struct test_context *) *state; + + assert_true(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); + assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); + struct buffer tmp = ctx->ciphertext; + assert_true(tls_crypt_unwrap(&tmp, &ctx->unwrapped, &ctx->co)); + buf_clear(&ctx->unwrapped); + assert_false(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); } /** @@ -196,34 +204,36 @@ static void tls_crypt_fail_replay(void **state) { * is used for the first control channel packet that arrives, because we don't * know the packet ID yet. */ -static void tls_crypt_ignore_replay(void **state) { - struct test_context *ctx = (struct test_context *) *state; +static void +tls_crypt_ignore_replay(void **state) { + struct test_context *ctx = (struct test_context *) *state; - ctx->co.flags |= CO_IGNORE_PACKET_ID; + ctx->co.flags |= CO_IGNORE_PACKET_ID; - assert_true (tls_crypt_wrap (&ctx->source, &ctx->ciphertext, &ctx->co)); - assert_true (BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); - struct buffer tmp = ctx->ciphertext; - assert_true (tls_crypt_unwrap (&tmp, &ctx->unwrapped, &ctx->co)); - buf_clear (&ctx->unwrapped); - assert_true (tls_crypt_unwrap (&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); + assert_true(tls_crypt_wrap(&ctx->source, &ctx->ciphertext, &ctx->co)); + assert_true(BLEN(&ctx->source) < BLEN(&ctx->ciphertext)); + struct buffer tmp = ctx->ciphertext; + assert_true(tls_crypt_unwrap(&tmp, &ctx->unwrapped, &ctx->co)); + buf_clear(&ctx->unwrapped); + assert_true(tls_crypt_unwrap(&ctx->ciphertext, &ctx->unwrapped, &ctx->co)); } -int main(void) { +int +main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test_setup_teardown(tls_crypt_loopback, setup, teardown), - cmocka_unit_test_setup_teardown(tls_crypt_loopback_zero_len, - setup, teardown), - cmocka_unit_test_setup_teardown(tls_crypt_loopback_max_len, - setup, teardown), - cmocka_unit_test_setup_teardown(tls_crypt_fail_msg_too_long, - setup, teardown), - cmocka_unit_test_setup_teardown(tls_crypt_fail_invalid_key, - setup, teardown), - cmocka_unit_test_setup_teardown(tls_crypt_fail_replay, - setup, teardown), - cmocka_unit_test_setup_teardown(tls_crypt_ignore_replay, - setup, teardown), + cmocka_unit_test_setup_teardown(tls_crypt_loopback, setup, teardown), + cmocka_unit_test_setup_teardown(tls_crypt_loopback_zero_len, + setup, teardown), + cmocka_unit_test_setup_teardown(tls_crypt_loopback_max_len, + setup, teardown), + cmocka_unit_test_setup_teardown(tls_crypt_fail_msg_too_long, + setup, teardown), + cmocka_unit_test_setup_teardown(tls_crypt_fail_invalid_key, + setup, teardown), + cmocka_unit_test_setup_teardown(tls_crypt_fail_replay, + setup, teardown), + cmocka_unit_test_setup_teardown(tls_crypt_ignore_replay, + setup, teardown), }; #if defined(ENABLE_CRYPTO_OPENSSL) diff --git a/tests/unit_tests/plugins/Makefile.in b/tests/unit_tests/plugins/Makefile.in index 16acc0b..1f44c58 100644 --- a/tests/unit_tests/plugins/Makefile.in +++ b/tests/unit_tests/plugins/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.13.4 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. diff --git a/tests/unit_tests/plugins/auth-pam/Makefile.in b/tests/unit_tests/plugins/auth-pam/Makefile.in index 34156b5..dfe7eba 100644 --- a/tests/unit_tests/plugins/auth-pam/Makefile.in +++ b/tests/unit_tests/plugins/auth-pam/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.14.1 from Makefile.am. +# Makefile.in generated by automake 1.13.4 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -434,14 +434,14 @@ distclean-compile: @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c b/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c index 70e472f..e80bffb 100644 --- a/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c +++ b/tests/unit_tests/plugins/auth-pam/test_search_and_replace.c @@ -8,63 +8,70 @@ #include "utils.h" -static void pass_any_null_param__returns_null() { +static void +pass_any_null_param__returns_null() { - char DUMMY[] = "DUMMY"; + char DUMMY[] = "DUMMY"; - assert_null(searchandreplace(NULL,DUMMY,DUMMY)); - assert_null(searchandreplace(DUMMY,NULL,DUMMY)); - assert_null(searchandreplace(DUMMY,DUMMY,NULL)); + assert_null(searchandreplace(NULL,DUMMY,DUMMY)); + assert_null(searchandreplace(DUMMY,NULL,DUMMY)); + assert_null(searchandreplace(DUMMY,DUMMY,NULL)); } -static void pass_any_empty_string__returns_null() { +static void +pass_any_empty_string__returns_null() { - char DUMMY[] = "DUMMY"; - char EMPTY[] = ""; + char DUMMY[] = "DUMMY"; + char EMPTY[] = ""; - assert_null(searchandreplace(EMPTY,DUMMY,DUMMY)); - assert_null(searchandreplace(DUMMY,EMPTY,DUMMY)); - assert_null(searchandreplace(DUMMY,DUMMY,EMPTY)); + assert_null(searchandreplace(EMPTY,DUMMY,DUMMY)); + assert_null(searchandreplace(DUMMY,EMPTY,DUMMY)); + assert_null(searchandreplace(DUMMY,DUMMY,EMPTY)); } -static void replace_single_char__one_time__match_is_replaced() { - char *replaced = searchandreplace("X","X","Y"); +static void +replace_single_char__one_time__match_is_replaced() { + char *replaced = searchandreplace("X","X","Y"); - assert_non_null(replaced); - assert_string_equal("Y", replaced); + assert_non_null(replaced); + assert_string_equal("Y", replaced); - free(replaced); + free(replaced); } -static void replace_single_char__multiple_times__match_all_matches_are_replaced() { - char *replaced = searchandreplace("XaX","X","Y"); +static void +replace_single_char__multiple_times__match_all_matches_are_replaced() { + char *replaced = searchandreplace("XaX","X","Y"); - assert_non_null(replaced); - assert_string_equal ("YaY", replaced); + assert_non_null(replaced); + assert_string_equal("YaY", replaced); - free(replaced); + free(replaced); } -static void replace_longer_text__multiple_times__match_all_matches_are_replaced() { - char *replaced = searchandreplace("XXaXX","XX","YY"); +static void +replace_longer_text__multiple_times__match_all_matches_are_replaced() { + char *replaced = searchandreplace("XXaXX","XX","YY"); - assert_non_null(replaced); - assert_string_equal ("YYaYY", replaced); + assert_non_null(replaced); + assert_string_equal("YYaYY", replaced); - free(replaced); + free(replaced); } -static void pattern_not_found__returns_original() { - char *replaced = searchandreplace("abc","X","Y"); +static void +pattern_not_found__returns_original() { + char *replaced = searchandreplace("abc","X","Y"); - assert_non_null(replaced); - assert_string_equal ("abc", replaced); + assert_non_null(replaced); + assert_string_equal("abc", replaced); - free(replaced); + free(replaced); } -int main(void) { +int +main(void) { const struct CMUnitTest tests[] = { cmocka_unit_test(pass_any_null_param__returns_null), cmocka_unit_test(pass_any_empty_string__returns_null), |