Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: first tests of radiusutils.c #898

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ if (BUILD_TESTS)
${LINKER_HARDENING_FLAGS})
add_unit_test (kb-test kb_tests.c gvm_base_shared ${GLIB_LDFLAGS} ${REDIS_LDFLAGS}
${LINKER_HARDENING_FLAGS})
add_unit_test (radiusutils-test radiusutils_tests.c gvm_util_shared gvm_base_shared
${GLIB_LDFLAGS} ${RADIUS_LDFLAGS}
${LINKER_HARDENING_FLAGS})
add_unit_test (versionutils-test versionutils_tests.c
${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${GPGME_LDFLAGS} ${ZLIB_LDFLAGS}
${RADIUS_LDFLAGS} ${LIBSSH_LDFLAGS} ${GNUTLS_LDFLAGS}
Expand Down
68 changes: 68 additions & 0 deletions util/radiusutils_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* SPDX-FileCopyrightText: 2019-2025 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "radiusutils.c"

#include <cgreen/assertions.h>
#include <cgreen/cgreen.h>
#include <cgreen/constraint_syntax_helpers.h>
#include <cgreen/internal/c_assertions.h>
#include <cgreen/mocks.h>

Describe (radiusutils);
BeforeEach (radiusutils)
{
}

AfterEach (radiusutils)
{
}

#define HOST "eghost"
#define SECRET "the_secret"

#ifdef ENABLE_RADIUS_AUTH

/* radius_init */

Ensure (radiusutils, radius_init)
{
rc_handle *rh;

rh = radius_init (HOST, SECRET);
assert_that (rh, is_not_null);
}

#else

/* radius_authenticate */

Ensure (radiusutils, radius_authenticate_returns_minus1)
{
assert_that (radius_authenticate ("h", "s", "u", "p"),
is_equal_to (-1));
}

#endif

/* Test suite. */
int
main (int argc, char **argv)
{
TestSuite *suite;

suite = create_test_suite ();

#ifdef ENABLE_RADIUS_AUTH
add_test_with_context (suite, radiusutils, radius_init);
#else
add_test_with_context (suite, radiusutils, radius_authenticate_returns_minus1);
#endif

if (argc > 1)
return run_single_test (suite, argv[1], create_text_reporter ());

Check warning on line 65 in util/radiusutils_tests.c

View check run for this annotation

Codecov / codecov/patch

util/radiusutils_tests.c#L65

Added line #L65 was not covered by tests

return run_test_suite (suite, create_text_reporter ());
}
Loading