aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorArne Schwabe2022-09-14 19:01:34 +0200
committerGert Doering2022-09-20 14:26:04 +0200
commitc9474fa316a6f73286ed97b36c8f8b1ba62141bd (patch)
treeef714ecbc9dde5751f87ea207570854724332693 /tests
parent179b3728b71013413885e453e477997f5a396f78 (diff)
downloadopenvpn-c9474fa316a6f73286ed97b36c8f8b1ba62141bd.zip
openvpn-c9474fa316a6f73286ed97b36c8f8b1ba62141bd.tar.gz
Implement AUTH_FAIL, TEMP message support
This allows a server to indicate a temporary problem on the server and allows the server to indicate how to proceed (i.e. move to the next server, retry the same server, wait a certain time,...) This adds options_utils.c/h to be able to unit test the new function. Patch v2: Improve documentation, format man page better, comment that protocol-flags is not a user usable option. Patch v3: cleanup parse_auth_failed_temp to use a simple const string instead of a buffer Patch v4: move message + strlen(TEMP) to caller Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Heiko Hund <heiko@ist.eigentlich.net> Message-Id: <20220914170134.2659433-1-arne@rfc2549.org> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25210.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit_tests/openvpn/Makefile.am1
-rw-r--r--tests/unit_tests/openvpn/test_misc.c40
2 files changed, 41 insertions, 0 deletions
diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvpn/Makefile.am
index 63b53a6..65cf954 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -176,5 +176,6 @@ misc_testdriver_LDFLAGS = @TEST_LDFLAGS@
misc_testdriver_SOURCES = test_misc.c mock_msg.c \
mock_get_random.c \
$(openvpn_srcdir)/buffer.c \
+ $(openvpn_srcdir)/options_util.c \
$(openvpn_srcdir)/ssl_util.c \
$(openvpn_srcdir)/platform.c
diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvpn/test_misc.c
index 636fc45..90c9a12 100644
--- a/tests/unit_tests/openvpn/test_misc.c
+++ b/tests/unit_tests/openvpn/test_misc.c
@@ -37,6 +37,7 @@
#include <cmocka.h>
#include "ssl_util.h"
+#include "options_util.h"
static void
test_compat_lzo_string(void **state)
@@ -72,8 +73,47 @@ test_compat_lzo_string(void **state)
gc_free(&gc);
}
+static void
+test_auth_fail_temp_no_flags(void **state)
+{
+ struct options o;
+
+ const char *teststr = "TEMP:There are no flags here [really not]";
+
+ const char *msg = parse_auth_failed_temp(&o, teststr + strlen("TEMP"));
+ assert_string_equal(msg, "There are no flags here [really not]");
+}
+
+static void
+test_auth_fail_temp_flags(void **state)
+{
+ struct options o;
+
+ const char *teststr = "[backoff 42,advance no]";
+
+ const char *msg = parse_auth_failed_temp(&o, teststr);
+ assert_string_equal(msg, "");
+ assert_int_equal(o.server_backoff_time, 42);
+ assert_int_equal(o.no_advance, true);
+}
+
+static void
+test_auth_fail_temp_flags_msg(void **state)
+{
+ struct options o;
+
+ const char *teststr = "[advance remote,backoff 77]:go round and round";
+
+ const char *msg = parse_auth_failed_temp(&o, teststr);
+ assert_string_equal(msg, "go round and round");
+ assert_int_equal(o.server_backoff_time, 77);
+}
+
const struct CMUnitTest misc_tests[] = {
cmocka_unit_test(test_compat_lzo_string),
+ cmocka_unit_test(test_auth_fail_temp_no_flags),
+ cmocka_unit_test(test_auth_fail_temp_flags),
+ cmocka_unit_test(test_auth_fail_temp_flags_msg),
};
int