From 60b75f4677dc9b89fb3e3153d681e66d842c8998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 20 Apr 2020 07:16:08 +0200 Subject: tests: add tests on functions relay_auth_password_hash_algo_search and relay_auth_generate_nonce --- tests/unit/plugins/relay/test-relay-auth.cpp | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/plugins/relay/test-relay-auth.cpp b/tests/unit/plugins/relay/test-relay-auth.cpp index 15dc07e3b..8c51bfe46 100644 --- a/tests/unit/plugins/relay/test-relay-auth.cpp +++ b/tests/unit/plugins/relay/test-relay-auth.cpp @@ -24,6 +24,8 @@ extern "C" { #include +#include +#include #include "src/plugins/relay/relay-auth.h" } @@ -55,6 +57,47 @@ TEST_GROUP(RelayAuth) { }; +/* + * Tests functions: + * relay_auth_password_hash_algo_search + */ + +TEST(RelayAuth, PasswordHashAlgoSearch) +{ + LONGS_EQUAL(-1, relay_auth_password_hash_algo_search (NULL)); + LONGS_EQUAL(-1, relay_auth_password_hash_algo_search ("")); + LONGS_EQUAL(-1, relay_auth_password_hash_algo_search ("zzz")); + + LONGS_EQUAL(0, relay_auth_password_hash_algo_search ("plain")); +} + +/* + * Tests functions: + * relay_auth_generate_nonce + */ + +TEST(RelayAuth, GenerateNonce) +{ + char *nonce; + + POINTERS_EQUAL(NULL, relay_auth_generate_nonce (-1)); + POINTERS_EQUAL(NULL, relay_auth_generate_nonce (0)); + + nonce = relay_auth_generate_nonce (1); + LONGS_EQUAL(2, strlen (nonce)); + CHECK(isxdigit ((int)nonce[0])); + CHECK(isxdigit ((int)nonce[1])); + free (nonce); + + nonce = relay_auth_generate_nonce (2); + LONGS_EQUAL(4, strlen (nonce)); + CHECK(isxdigit ((int)nonce[0])); + CHECK(isxdigit ((int)nonce[1])); + CHECK(isxdigit ((int)nonce[2])); + CHECK(isxdigit ((int)nonce[3])); + free (nonce); +} + /* * Tests functions: * relay_auth_parse_sha -- cgit v1.2.3