unit-tests: Only deliver messages to the SA they are addressed to
authorTobias Brunner <tobias@strongswan.org>
Mon, 30 May 2016 13:39:38 +0000 (15:39 +0200)
committerTobias Brunner <tobias@strongswan.org>
Fri, 17 Jun 2016 16:48:05 +0000 (18:48 +0200)
src/libcharon/tests/utils/exchange_test_helper.c

index ab56227..f32906d 100644 (file)
@@ -182,16 +182,24 @@ METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
 METHOD(exchange_test_helper_t, process_message, status_t,
        private_exchange_test_helper_t *this, ike_sa_t *ike_sa, message_t *message)
 {
-       status_t status;
+       status_t status = FAILED;
+       ike_sa_id_t *id;
 
        if (!message)
        {
                message = this->public.sender->dequeue(this->public.sender);
        }
-       charon->bus->set_sa(charon->bus, ike_sa);
-       status = ike_sa->process_message(ike_sa, message);
-       charon->bus->set_sa(charon->bus, NULL);
+       id = message->get_ike_sa_id(message);
+       id = id->clone(id);
+       id->switch_initiator(id);
+       if (!id->get_responder_spi(id) || id->equals(id, ike_sa->get_id(ike_sa)))
+       {
+               charon->bus->set_sa(charon->bus, ike_sa);
+               status = ike_sa->process_message(ike_sa, message);
+               charon->bus->set_sa(charon->bus, NULL);
+       }
        message->destroy(message);
+       id->destroy(id);
        return status;
 }