Annotation of embedaddon/strongswan/src/libcharon/tests/suites/test_child_create.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2016 Tobias Brunner
3: * HSR Hochschule fuer Technik Rapperswil
4: *
5: * This program is free software; you can redistribute it and/or modify it
6: * under the terms of the GNU General Public License as published by the
7: * Free Software Foundation; either version 2 of the License, or (at your
8: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9: *
10: * This program is distributed in the hope that it will be useful, but
11: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13: * for more details.
14: */
15:
16: #include "test_suite.h"
17:
18: #include <daemon.h>
19: #include <tests/utils/exchange_test_helper.h>
20: #include <tests/utils/exchange_test_asserts.h>
21: #include <tests/utils/job_asserts.h>
22: #include <tests/utils/sa_asserts.h>
23:
24: /**
25: * One of the peers tries to create a new CHILD_SA while the other concurrently
26: * started to rekey the IKE_SA. TEMPORARY_FAILURE should be returned on both
27: * sides and the peers should prepare to retry.
28: */
29: START_TEST(test_collision_ike_rekey)
30: {
31: child_cfg_t *child_cfg;
32: child_cfg_create_t child = {
33: .mode = MODE_TUNNEL,
34: };
35: ike_sa_t *a, *b;
36:
37: exchange_test_helper->establish_sa(exchange_test_helper,
38: &a, &b, NULL);
39:
40: assert_hook_not_called(child_updown);
41: child_cfg = child_cfg_create("child", &child);
42: child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP));
43: child_cfg->add_traffic_selector(child_cfg, TRUE,
44: traffic_selector_create_dynamic(0, 0, 65535));
45: child_cfg->add_traffic_selector(child_cfg, FALSE,
46: traffic_selector_create_dynamic(0, 0, 65535));
47: call_ikesa(a, initiate, child_cfg, 0, NULL, NULL);
48: assert_child_sa_count(a, 1);
49: assert_hook();
50:
51: call_ikesa(b, rekey);
52:
53: /* CREATE_CHILD_SA { SA, Ni, [KEi,] TSi, TSr } --> */
54: assert_hook_not_called(child_updown);
55: assert_single_notify(OUT, TEMPORARY_FAILURE);
56: exchange_test_helper->process_message(exchange_test_helper, b, NULL);
57: assert_child_sa_count(b, 1);
58: assert_hook();
59:
60: /* <-- CREATE_CHILD_SA { SA, Ni, KEi } */
61: assert_single_notify(OUT, TEMPORARY_FAILURE);
62: exchange_test_helper->process_message(exchange_test_helper, a, NULL);
63:
64: /* <-- CREATE_CHILD_SA { N(TEMP_FAIL) } */
65: assert_hook_not_called(child_updown);
66: assert_jobs_scheduled(1);
67: exchange_test_helper->process_message(exchange_test_helper, a, NULL);
68: assert_child_sa_count(a, 1);
69: assert_scheduler();
70: assert_hook();
71:
72: /* CREATE_CHILD_SA { N(TEMP_FAIL) } --> */
73: assert_jobs_scheduled(1);
74: exchange_test_helper->process_message(exchange_test_helper, b, NULL);
75: assert_ike_sa_state(b, IKE_ESTABLISHED);
76: assert_scheduler();
77:
78: /* make sure no message was sent after handling the TEMPORARY_FAILURE and
79: * that the task to retry creating the CHILD_SA is queued and not active
80: * and it can't be initiated immediately */
81: ck_assert(!exchange_test_helper->sender->dequeue(exchange_test_helper->sender));
82: assert_num_tasks(a, 0, TASK_QUEUE_ACTIVE);
83: assert_num_tasks(a, 1, TASK_QUEUE_QUEUED);
84: call_ikesa(a, initiate, NULL, 0, NULL, NULL);
85: assert_num_tasks(a, 0, TASK_QUEUE_ACTIVE);
86:
87: assert_sa_idle(b);
88:
89: call_ikesa(a, destroy);
90: call_ikesa(b, destroy);
91: }
92: END_TEST
93:
94: Suite *child_create_suite_create()
95: {
96: Suite *s;
97: TCase *tc;
98:
99: s = suite_create("child create");
100:
101: tc = tcase_create("collisions ike rekey");
102: tcase_add_test(tc, test_collision_ike_rekey);
103: suite_add_tcase(s, tc);
104:
105: return s;
106: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>