Skip to content

Commit ed93035

Browse files
committed
Add: first tests of radiusutils.c
1 parent 90ae580 commit ed93035

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

util/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ if (BUILD_TESTS)
169169
${LINKER_HARDENING_FLAGS})
170170
add_unit_test (kb-test kb_tests.c gvm_base_shared ${GLIB_LDFLAGS} ${REDIS_LDFLAGS}
171171
${LINKER_HARDENING_FLAGS})
172+
add_unit_test (radiusutils-test radiusutils_tests.c gvm_util_shared gvm_base_shared
173+
${GLIB_LDFLAGS} ${RADIUS_LDFLAGS}
174+
${LINKER_HARDENING_FLAGS})
172175
add_unit_test (versionutils-test versionutils_tests.c
173176
${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${GPGME_LDFLAGS} ${ZLIB_LDFLAGS}
174177
${RADIUS_LDFLAGS} ${LIBSSH_LDFLAGS} ${GNUTLS_LDFLAGS}

util/radiusutils_tests.c

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* SPDX-FileCopyrightText: 2019-2025 Greenbone AG
2+
*
3+
* SPDX-License-Identifier: GPL-2.0-or-later
4+
*/
5+
6+
#include "radiusutils.c"
7+
8+
#include <cgreen/assertions.h>
9+
#include <cgreen/cgreen.h>
10+
#include <cgreen/constraint_syntax_helpers.h>
11+
#include <cgreen/internal/c_assertions.h>
12+
#include <cgreen/mocks.h>
13+
14+
Describe (radiusutils);
15+
BeforeEach (radiusutils)
16+
{
17+
}
18+
19+
AfterEach (radiusutils)
20+
{
21+
}
22+
23+
#define HOST "eghost"
24+
#define SECRET "the_secret"
25+
26+
#ifdef ENABLE_RADIUS_AUTH
27+
28+
/* radius_init */
29+
30+
Ensure (radiusutils, radius_init)
31+
{
32+
rc_handle *rh;
33+
34+
rh = radius_init (HOST, SECRET);
35+
assert_that (rh, is_not_null);
36+
}
37+
38+
#else
39+
40+
/* radius_authenticate */
41+
42+
Ensure (radiusutils, radius_authenticate_returns_minus1)
43+
{
44+
assert_that (radius_authenticate ("h", "s", "u", "p"),
45+
is_equal_to (-1));
46+
}
47+
48+
#endif
49+
50+
/* Test suite. */
51+
int
52+
main (int argc, char **argv)
53+
{
54+
TestSuite *suite;
55+
56+
suite = create_test_suite ();
57+
58+
#ifdef ENABLE_RADIUS_AUTH
59+
add_test_with_context (suite, radiusutils, radius_init);
60+
#else
61+
add_test_with_context (suite, radiusutils, radius_authenticate_returns_minus1);
62+
#endif
63+
64+
if (argc > 1)
65+
return run_single_test (suite, argv[1], create_text_reporter ());
66+
67+
return run_test_suite (suite, create_text_reporter ());
68+
}

0 commit comments

Comments
 (0)