unit-tests: Add asserts against ike|child_rekey hooks
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <test_suite.h>
|
||||
|
||||
#include "exchange_test_asserts.h"
|
||||
@@ -56,6 +58,51 @@ bool exchange_test_asserts_child_updown(listener_t *listener, ike_sa_t *ike_sa,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
bool exchange_test_asserts_ike_rekey(listener_t *listener, ike_sa_t *old,
|
||||
ike_sa_t *new)
|
||||
{
|
||||
listener_hook_assert_t *this = (listener_hook_assert_t*)listener;
|
||||
ike_sa_id_t *id;
|
||||
uint64_t spi;
|
||||
|
||||
this->count++;
|
||||
id = old->get_id(old);
|
||||
spi = id->get_initiator_spi(id);
|
||||
assert_listener_msg(this->spi_old == spi, this, "unexpected old IKE_SA "
|
||||
"%.16"PRIx64"_i instead of %.16"PRIx64"_i",
|
||||
be64toh(spi), be64toh(this->spi_old));
|
||||
id = new->get_id(new);
|
||||
spi = id->get_initiator_spi(id);
|
||||
assert_listener_msg(this->spi_new == spi, this, "unexpected new IKE_SA "
|
||||
"%.16"PRIx64"_i instead of %.16"PRIx64"_i",
|
||||
be64toh(spi), be64toh(this->spi_new));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
bool exchange_test_asserts_child_rekey(listener_t *listener, ike_sa_t *ike_sa,
|
||||
child_sa_t *old, child_sa_t *new)
|
||||
{
|
||||
listener_hook_assert_t *this = (listener_hook_assert_t*)listener;
|
||||
uint32_t spi, expected;
|
||||
|
||||
this->count++;
|
||||
spi = old->get_spi(old, TRUE);
|
||||
expected = this->spi_old;
|
||||
assert_listener_msg(expected == spi, this, "unexpected old CHILD_SA %.8x "
|
||||
"instead of %.8x", spi, expected);
|
||||
spi = new->get_spi(new, TRUE);
|
||||
expected = this->spi_new;
|
||||
assert_listener_msg(expected == spi, this, "unexpected new CHILD_SA %.8x "
|
||||
"instead of %.8x", spi, expected);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert a given message rule
|
||||
*/
|
||||
|
||||
@@ -65,6 +65,11 @@ struct listener_hook_assert_t {
|
||||
* Expected updown result
|
||||
*/
|
||||
bool up;
|
||||
|
||||
/**
|
||||
* Initiator/Inbound SPIs to expect in rekey event
|
||||
*/
|
||||
uint64_t spi_old, spi_new;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -84,6 +89,18 @@ bool exchange_test_asserts_ike_updown(listener_t *this, ike_sa_t *ike_sa,
|
||||
bool exchange_test_asserts_child_updown(listener_t *this, ike_sa_t *ike_sa,
|
||||
child_sa_t *child_sa, bool up);
|
||||
|
||||
/**
|
||||
* Implementation of listener_t::ike_rekey.
|
||||
*/
|
||||
bool exchange_test_asserts_ike_rekey(listener_t *this, ike_sa_t *old,
|
||||
ike_sa_t *new);
|
||||
|
||||
/**
|
||||
* Implementation of listener_t::child_rekey.
|
||||
*/
|
||||
bool exchange_test_asserts_child_rekey(listener_t *this, ike_sa_t *ike_sa,
|
||||
child_sa_t *old, child_sa_t *new);
|
||||
|
||||
/**
|
||||
* Check if a statement evaluates to TRUE, use original source file and line
|
||||
* in the error message if not.
|
||||
@@ -135,6 +152,24 @@ bool exchange_test_asserts_child_updown(listener_t *this, ike_sa_t *ike_sa,
|
||||
.up = e, \
|
||||
)
|
||||
|
||||
/**
|
||||
* Initialize an assertion that enforces that the given rekey hook was called
|
||||
* with the SAs with the matching initiator/inbound SPIs.
|
||||
* Must be matched by a call to assert_hook().
|
||||
*
|
||||
* @param name name of the hook
|
||||
* @param old SPI of the old SA
|
||||
* @param new SPI of the new SA
|
||||
*/
|
||||
#define assert_hook_rekey(name, old, new) \
|
||||
_assert_hook_init(name, \
|
||||
streq(#name, "ike_rekey") ? (void*)exchange_test_asserts_ike_rekey \
|
||||
: (void*)exchange_test_asserts_child_rekey, \
|
||||
.expected = 1, \
|
||||
.spi_old = old, \
|
||||
.spi_new = new, \
|
||||
)
|
||||
|
||||
/**
|
||||
* Initialize assertions against invocations of listener_t hooks. Each call
|
||||
* must be matched by a call to assert_hook().
|
||||
|
||||
Reference in New Issue
Block a user