2 * Copyright (C) 2016 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
17 * This class and singleton object initializes charon and provides helper
18 * methods to create unit tests for IKEv2 exchanges.
20 * It also registers special implementations for the kernel_ipsec_t interface,
21 * the sender and provides dummy configs and credentials.
23 * @defgroup exchange_test_helper exchange_test_helper
24 * @{ @ingroup test_utils_c
27 #ifndef EXCHANGE_TEST_HELPER_H_
28 #define EXCHANGE_TEST_HELPER_H_
32 #include "mock_sender.h"
34 typedef struct exchange_test_helper_t exchange_test_helper_t
;
35 typedef struct exchange_test_sa_conf_t exchange_test_sa_conf_t
;
37 struct exchange_test_helper_t
{
40 * Sender instance used during tests
42 mock_sender_t
*sender
;
45 * Set the initial byte of all nonces generated by future nonce
46 * generators (already instatiated nonce generators are not affected).
48 u_char nonce_first_byte
;
51 * Creates an established IKE_SA/CHILD_SA
53 * @param[out] init IKE_SA of the initiator
54 * @param[out] resp IKE_SA of the responder
55 * @param conf configuration for SAs
57 void (*establish_sa
)(exchange_test_helper_t
*this, ike_sa_t
**init
,
58 ike_sa_t
**resp
, exchange_test_sa_conf_t
*conf
);
61 * Pass a message to the given IKE_SA for processing, setting the IKE_SA on
62 * the bus while processing the message.
64 * @param ike_sa the IKE_SA receiving the message
65 * @param message the message, or NULL to pass the next message in the
66 * send queue (adopted)
67 * @return return value from ike_sa_t::process_message()
69 status_t (*process_message
)(exchange_test_helper_t
*this, ike_sa_t
*sa
,
73 * Register a listener with the bus.
75 * Don't use bus_t::add_listener() directly for listeners on the stack
76 * as that could lead to invalid listeners registered when hooks are
77 * triggered during cleanup if a test case fails. All of the listeners
78 * added this way are unregistered with the bus before cleaning up.
80 * @param listener listener to add to the bus
82 void (*add_listener
)(exchange_test_helper_t
*this, listener_t
*listener
);
85 struct exchange_test_sa_conf_t
{
88 * Configuration for initiator and responder
95 } initiator
, responder
;
99 * Since we don't use the IKE_SA manager to checkout SAs use this to call a
100 * method on the given IKE_SA in its context.
102 #define call_ikesa(sa, method, ...) ({ \
103 charon->bus->set_sa(charon->bus, sa); \
104 sa->method(sa, ##__VA_ARGS__); \
105 charon->bus->set_sa(charon->bus, NULL); \
109 * The one and only instance of the helper object.
111 * Set between exchange_test_helper_setup() and exchange_test_helper_teardown()
114 extern exchange_test_helper_t
*exchange_test_helper
;
117 * Initialize charon and the helper object.
119 * @param plugins plugins to load
121 void exchange_test_helper_init(char *plugins
);
124 * Deinitialize the helper object.
126 void exchange_test_helper_deinit();
128 #endif /** EXCHANGE_TEST_HELPER_H_ @} */