Skip to content

Commit

Permalink
tests: Add a unit test for sspi plugin.
Browse files Browse the repository at this point in the history
A new unit test for the sspi plugin that simply exercises the the sspi
plugin operations.  Only blackbox testing is performed at this stage
since it is not straightforward to perform whitebox testing of the
sspi plugin internals.
  • Loading branch information
ossama-othman committed Jul 7, 2022
1 parent 1b09a8e commit 8570f83
Show file tree
Hide file tree
Showing 6 changed files with 430 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ tests/test-id-manager
tests/test-sockaddr
tests/test-addr-info
tests/test-murmur-hash
tests/test-sspi

tests/mptcpwrap-tester
tests/*.log
tests/*.trs
Expand Down
17 changes: 15 additions & 2 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## SPDX-License-Identifier: BSD-3-Clause
##
## Copyright (c) 2017-2021, Intel Corporation
## Copyright (c) 2017-2022, Intel Corporation

include $(top_srcdir)/aminclude_static.am

Expand All @@ -20,6 +20,7 @@ TEST_PLUGIN_DIR_SECURITY = $(abs_builddir)/plugins/security/.libs
TEST_PLUGIN_DIR_PRIORITY = $(abs_builddir)/plugins/priority/.libs
TEST_PLUGIN_DIR_NOOP = $(abs_builddir)/plugins/noop/.libs
TEST_PLUGIN_DIR_BAD = $(abs_builddir)/plugins/bad/.libs
TEST_PLUGIN_DIR_PM = $(abs_top_builddir)/plugins/path_managers/.libs

check_PROGRAMS = \
test-plugin \
Expand All @@ -30,7 +31,8 @@ check_PROGRAMS = \
test-id-manager \
test-sockaddr \
test-addr-info \
test-murmur-hash
test-murmur-hash \
test-sspi

noinst_PROGRAMS = mptcpwrap-tester

Expand Down Expand Up @@ -121,6 +123,17 @@ test_murmur_hash_LDADD = \
$(ELL_LIBS) \
$(CODE_COVERAGE_LIBS)

test_sspi_SOURCES = test-sspi.c
test_sspi_CPPFLAGS = \
$(AM_CPPFLAGS) \
-DTEST_PLUGIN_DIR=\"$(TEST_PLUGIN_DIR_PM)\"
test_sspi_LDADD = \
$(top_builddir)/src/libpath_manager.la \
$(top_builddir)/lib/libmptcpd.la \
$(builddir)/lib/libmptcpd_test.la \
$(ELL_LIBS) \
$(CODE_COVERAGE_LIBS)

mptcpwrap_tester_SOURCES = mptcpwrap-tester.c
mptcpwrap_tester_LDADD = $(CODE_COVERAGE_LIBS)

Expand Down
4 changes: 3 additions & 1 deletion tests/lib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## SPDX-License-Identifier: BSD-3-Clause
##
## Copyright (c) 2019-2020, Intel Corporation
## Copyright (c) 2019-2020, 2022, Intel Corporation

include $(top_srcdir)/aminclude_static.am

Expand All @@ -17,6 +17,8 @@ check_LTLIBRARIES = libmptcpd_test.la
libmptcpd_test_la_SOURCES = \
call_count.c \
call_plugin.c \
interface.c \
interface.h \
sockaddr.c \
test-plugin.h \
test-util.c \
Expand Down
102 changes: 102 additions & 0 deletions tests/lib/interface.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// SPDX-License-Identifier: BSD-3-Clause
/**
* @file tests/lib/interface.c
*
* @brief @c mptcpd_interface related utility functions.
*
* Copyright (c) 2022, Intel Corporation
*/

#ifdef HAVE_CONFIG_H
# include <mptcpd/private/config.h> // For NDEBUG
#endif

#include <assert.h>

#include <net/if_arp.h>
#include <net/if.h>
#include <netinet/in.h>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#include <ell/util.h>
#include <ell/queue.h>
#pragma GCC diagnostic pop

#include <mptcpd/network_monitor.h>

#include "interface.h"


static int
addr_compare(void const *a, void const *b, void *user_data)
{
(void) a;
(void) b;
(void) user_data;

// No need to sort.
return 1;
}

// -----------------------------------------------------------------------

struct mptcpd_interface *test_mptcpd_interface_create(void)
{
struct mptcpd_interface *const i =
l_new(struct mptcpd_interface, 1);

// Bind test IP address to loopback interface.
static char const loopback[] = "lo";

i->family = AF_UNSPEC;
i->type = ARPHRD_LOOPBACK;
i->flags = IFF_UP | IFF_LOOPBACK;

i->index = if_nametoindex(loopback);
assert(i->index != 0);

l_strlcpy(i->name, loopback, L_ARRAY_SIZE(i->name));

i->addrs = l_queue_new();

return i;
}

bool test_mptcpd_interface_insert_addr(struct mptcpd_interface *i,
struct sockaddr const *sa)
{
assert(sa->sa_family == AF_INET || sa->sa_family == AF_INET6);

struct sockaddr *addr = NULL;

if (sa->sa_family == AF_INET)
addr = l_memdup(sa, sizeof(struct sockaddr_in));
else
addr = l_memdup(sa, sizeof(struct sockaddr_in6));

/*
The mptcpd network monitor actually inserts an instance of
the internal struct nm_addr_info into this list but it is
actually expected for users to treat the list as a list of
struct sockaddr const* objects. This works since the first
member of struct nm_addr_info is a struct sockaddr_storage,
meaning the latter will have the same address as the
former. Just treat this list as list of struct sockaddr*
for the purposes of the mptcpd unit test suite.
*/
return l_queue_insert(i->addrs, addr, addr_compare, NULL);
}

void test_mptcpd_interface_destroy(struct mptcpd_interface *i)
{
l_queue_destroy(i->addrs, l_free);
l_free(i);
}


/*
Local Variables:
c-file-style: "linux"
End:
*/
40 changes: 40 additions & 0 deletions tests/lib/interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: BSD-3-Clause
/**
* @file tests/lib/interface.h
*
* @brief @c mptcpd_interface related utility functions.
*
* Copyright (c) 2022, Intel Corporation
*/

#include <stdbool.h>


struct mptcpd_interface;
struct sockaddr;

/// Create a @c struct @c mptcpd_interface for test purposes.
struct mptcpd_interface *test_mptcpd_interface_create(void);

/**
* @brief Add an IP address to the address list in @a i.
*
* @param[in,out] i mptcpd interface information to which the IP
* address @a sa will be added.
* @param[in] sa IP address to be add to the address list in
* @a i.
*
* @return @c true on success, @c false otherwise.
*/
bool test_mptcpd_interface_insert_addr(struct mptcpd_interface *i,
struct sockaddr const *sa);

/// Destroy the @c struct @c mptcpd_interface instance @a i.
void test_mptcpd_interface_destroy(struct mptcpd_interface *i);


/*
Local Variables:
c-file-style: "linux"
End:
*/

0 comments on commit 8570f83

Please sign in to comment.