]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Add tests for IKE_SA rekeying
authorTobias Brunner <tobias@strongswan.org>
Fri, 27 May 2016 08:31:42 +0000 (10:31 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 17 Jun 2016 16:48:04 +0000 (18:48 +0200)
src/libcharon/tests/Makefile.am
src/libcharon/tests/exchange_tests.h
src/libcharon/tests/suites/test_ike_rekey.c [new file with mode: 0644]

index c835145468746dfe96084ea8ca017e6f75398b96..4e2bdfd022367355f8dce82fb8c582745301f840 100644 (file)
@@ -26,6 +26,7 @@ libcharon_tests_LDADD = \
 exchange_tests_SOURCES = \
   suites/test_child_delete.c \
   suites/test_child_rekey.c \
+  suites/test_ike_rekey.c \
   utils/exchange_test_asserts.h utils/exchange_test_asserts.c \
   utils/exchange_test_helper.h utils/exchange_test_helper.c \
   utils/job_asserts.h \
index 8be5f542d3bb522f4dba4bcba495f575d1b66016..0d0c192d8e718aff6db9f52005b00c302176ca7a 100644 (file)
@@ -13,5 +13,6 @@
  * for more details.
  */
 
+TEST_SUITE(ike_rekey_suite_create)
 TEST_SUITE(child_delete_suite_create)
 TEST_SUITE(child_rekey_suite_create)
diff --git a/src/libcharon/tests/suites/test_ike_rekey.c b/src/libcharon/tests/suites/test_ike_rekey.c
new file mode 100644 (file)
index 0000000..d2e365e
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2016 Tobias Brunner
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#include "test_suite.h"
+
+#include <tests/utils/exchange_test_helper.h>
+#include <tests/utils/exchange_test_asserts.h>
+#include <tests/utils/sa_asserts.h>
+
+/**
+ * Regular IKE_SA rekey either initiated by the original initiator or
+ * responder of the IKE_SA.
+ */
+START_TEST(test_regular)
+{
+       ike_sa_t *a, *b, *new_sa;
+       status_t s;
+
+       if (_i)
+       {       /* responder rekeys the IKE_SA */
+               exchange_test_helper->establish_sa(exchange_test_helper,
+                                                                                  &b, &a, NULL);
+       }
+       else
+       {       /* initiator rekeys the IKE_SA */
+               exchange_test_helper->establish_sa(exchange_test_helper,
+                                                                                  &a, &b, NULL);
+       }
+       /* these should never get called as this results in a successful rekeying */
+       assert_hook_not_called(ike_updown);
+       assert_hook_not_called(child_updown);
+
+       assert_hook_not_called(ike_rekey);
+       call_ikesa(a, rekey);
+       assert_ike_sa_state(a, IKE_REKEYING);
+       assert_hook();
+
+       /* CREATE_CHILD_SA { SA, Ni, KEi } --> */
+       assert_hook_rekey(ike_rekey, 1, 3);
+       assert_no_notify(IN, REKEY_SA);
+       exchange_test_helper->process_message(exchange_test_helper, b, NULL);
+       assert_ike_sa_state(b, IKE_REKEYING);
+       assert_child_sa_count(b, 0);
+       new_sa = assert_ike_sa_checkout(3, 4, FALSE);
+       assert_ike_sa_state(new_sa, IKE_ESTABLISHED);
+       assert_child_sa_count(new_sa, 1);
+       assert_ike_sa_count(1);
+       assert_hook();
+
+       /* <-- CREATE_CHILD_SA { SA, Nr, KEr } */
+       assert_hook_rekey(ike_rekey, 1, 3);
+       assert_no_notify(IN, REKEY_SA);
+       exchange_test_helper->process_message(exchange_test_helper, a, NULL);
+       assert_ike_sa_state(a, IKE_DELETING);
+       assert_child_sa_count(a, 0);
+       new_sa = assert_ike_sa_checkout(3, 4, TRUE);
+       assert_ike_sa_state(new_sa, IKE_ESTABLISHED);
+       assert_child_sa_count(new_sa, 1);
+       assert_ike_sa_count(2);
+       assert_hook();
+
+       /* we don't expect this hook to get called anymore */
+       assert_hook_not_called(ike_rekey);
+
+       /* INFORMATIONAL { D } --> */
+       assert_single_payload(IN, PLV2_DELETE);
+       s = exchange_test_helper->process_message(exchange_test_helper, b, NULL);
+       ck_assert_int_eq(DESTROY_ME, s);
+       call_ikesa(b, destroy);
+       /* <-- INFORMATIONAL { } */
+       assert_message_empty(IN);
+       s = exchange_test_helper->process_message(exchange_test_helper, a, NULL);
+       ck_assert_int_eq(DESTROY_ME, s);
+       call_ikesa(a, destroy);
+
+       /* ike_rekey/ike_updown/child_updown */
+       assert_hook();
+       assert_hook();
+       assert_hook();
+
+       charon->ike_sa_manager->flush(charon->ike_sa_manager);
+}
+END_TEST
+
+Suite *ike_rekey_suite_create()
+{
+       Suite *s;
+       TCase *tc;
+
+       s = suite_create("ike rekey");
+
+       tc = tcase_create("regular");
+       tcase_add_loop_test(tc, test_regular, 0, 2);
+       suite_add_tcase(s, tc);
+
+       return s;
+}