Re: [Openvpn-devel] [PATCH v7 7/7] Implement unit tests for auth-gen-token

2019-09-18 Thread David Sommerseth
On 17/09/2019 14:33, Arne Schwabe wrote:
> From: Arne Schwabe 
> 
> The unit test is breaking the 80 char limit in some places
> but the remaining lines it breaks the limit I feel
> forcing the 80 char limit will impair readibility
> 
> Patch V2: adapt unit tests to other V2 patches
> Patch V4: Resolve rebase conflicts
> Patch V5: Add \ lost in rebase that broke compilation
> Patch V7: Fix unit test failure, try to stay below 80
> ---
>  tests/unit_tests/openvpn/Makefile.am   |  18 +-
>  tests/unit_tests/openvpn/test_auth_token.c | 394 +
>  2 files changed, 411 insertions(+), 1 deletion(-)
>  create mode 100644 tests/unit_tests/openvpn/test_auth_token.c

Acked-By: David Sommerseth 

This looks good now, and passes on my system.


-- 
kind regards,

David Sommerseth
OpenVPN Inc



___
Openvpn-devel mailing list
Openvpn-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openvpn-devel


[Openvpn-devel] [PATCH v7 7/7] Implement unit tests for auth-gen-token

2019-09-17 Thread Arne Schwabe
From: Arne Schwabe 

The unit test is breaking the 80 char limit in some places
but the remaining lines it breaks the limit I feel
forcing the 80 char limit will impair readibility

Patch V2: adapt unit tests to other V2 patches
Patch V4: Resolve rebase conflicts
Patch V5: Add \ lost in rebase that broke compilation
Patch V7: Fix unit test failure, try to stay below 80
---
 tests/unit_tests/openvpn/Makefile.am   |  18 +-
 tests/unit_tests/openvpn/test_auth_token.c | 394 +
 2 files changed, 411 insertions(+), 1 deletion(-)
 create mode 100644 tests/unit_tests/openvpn/test_auth_token.c

diff --git a/tests/unit_tests/openvpn/Makefile.am 
b/tests/unit_tests/openvpn/Makefile.am
index d015b293..60e84639 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -6,7 +6,7 @@ if HAVE_LD_WRAP_SUPPORT
 test_binaries += argv_testdriver buffer_testdriver
 endif
 
-test_binaries += crypto_testdriver packet_id_testdriver
+test_binaries += crypto_testdriver packet_id_testdriver auth_token_testdriver
 if HAVE_LD_WRAP_SUPPORT
 test_binaries += tls_crypt_testdriver
 endif
@@ -94,3 +94,19 @@ networking_testdriver_SOURCES = test_networking.c mock_msg.c 
\
$(openvpn_srcdir)/packet_id.c \
$(openvpn_srcdir)/platform.c
 endif
+
+auth_token_testdriver_CFLAGS  = @TEST_CFLAGS@ \
+   -I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir) \
+   $(OPTIONAL_CRYPTO_CFLAGS)
+auth_token_testdriver_LDFLAGS = @TEST_LDFLAGS@ \
+   $(OPTIONAL_CRYPTO_LIBS)
+
+auth_token_testdriver_SOURCES = test_auth_token.c mock_msg.c \
+   $(openvpn_srcdir)/buffer.c \
+   $(openvpn_srcdir)/crypto.c \
+   $(openvpn_srcdir)/crypto_mbedtls.c \
+   $(openvpn_srcdir)/crypto_openssl.c \
+   $(openvpn_srcdir)/otime.c \
+   $(openvpn_srcdir)/packet_id.c \
+   $(openvpn_srcdir)/platform.c \
+   $(openvpn_srcdir)/base64.c
diff --git a/tests/unit_tests/openvpn/test_auth_token.c 
b/tests/unit_tests/openvpn/test_auth_token.c
new file mode 100644
index ..6b30dfbd
--- /dev/null
+++ b/tests/unit_tests/openvpn/test_auth_token.c
@@ -0,0 +1,394 @@
+/*
+ *  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-2018 Fox Crypto B.V. 
+ *
+ *  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; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#elif defined(_MSC_VER)
+#include "config-msvc.h"
+#endif
+
+#include "syshead.h"
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "auth_token.c"
+
+#include "mock_msg.h"
+
+struct test_context {
+struct tls_multi multi;
+struct key_type kt;
+struct user_pass up;
+struct tls_session session;
+};
+
+/* Dummy functions that do nothing to mock the functionality */
+void
+send_push_reply_auth_token(struct tls_multi *multi)
+{
+}
+
+void
+auth_set_client_reason(struct tls_multi *multi, const char *reason)
+{
+
+}
+
+static const char *now0key0 = 
"SESS_ID_AT_0123456789abcdefAE5JsQJOVfo8jnI3RL3tBaR5NkE4yPfcylFUHmHSc5Bu";
+
+static const char *zeroinline = "-BEGIN OpenVPN auth-token server 
key-\n"
+
"\n"
+
"\n"
+
"AAA=\n"
+"-END OpenVPN auth-token server key-";
+
+static const char *allx01inline = "-BEGIN OpenVPN auth-token server 
key-\n"
+  
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n"
+  
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n"
+  
"AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=\n"
+  "-END OpenVPN auth-token server 
key-";
+
+static const char *random_key = "-BEGIN OpenVPN auth-token server 
key-\n"
+
"+mmmf7IQ5cymtMVjKYTWk8IOcYanRlpQmV9Tb