Add CI tests

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-12-15 20:56:00 +01:00
parent c2d4f06864
commit 6bc033e537
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
5 changed files with 17 additions and 17 deletions

View File

@ -507,12 +507,12 @@ void parse_args(int argc, char* argv[])
// Need to get dns.port and the resolver settings
readFTLconf(&config, false);
char *name = resolveHostname(argv[2]);
char *name = resolveHostname(argv[2], true);
if(name == NULL)
exit(EXIT_FAILURE);
// Print result
printf("%s -> %s\n", argv[2], name);
printf("%s\n", name);
free(name);
exit(EXIT_SUCCESS);
}

View File

@ -19,7 +19,7 @@
#include "../datastructure.h"
// struct config
#include "../config/config.h"
// resolveHostname()
// resolve_this_name()
#include "../resolve.h"
// killed
#include "../signals.h"

View File

@ -43,7 +43,7 @@ struct DNS_HEADER
bool rd :1; // recursion desired
bool tc :1; // truncated message
bool aa :1; // authoritive answer
bool aa :1; // authoritative answer
uint8_t opcode :4; // purpose of message
bool qr :1; // query/response flag
@ -349,13 +349,13 @@ static void __attribute__((nonnull(1,3))) name_toDNS(unsigned char *dns, const s
*dns++='\0';
}
char *__attribute__((malloc)) resolveHostname(const char *addr)
char *__attribute__((malloc)) resolveHostname(const char *addr, const bool force)
{
// Get host name
char *hostn = NULL;
// Check if we want to resolve host names
if(!resolve_this_name(addr))
if(!force && !resolve_this_name(addr))
{
log_debug(DEBUG_RESOLVER, "Configured to not resolve host name for %s", addr);
@ -383,15 +383,6 @@ char *__attribute__((malloc)) resolveHostname(const char *addr)
return hostn;
}
// Check if we want to resolve host names
if(!resolve_this_name(addr))
{
log_debug(DEBUG_RESOLVER, "Configured to not resolve host name for %s", addr);
// Return an empty host name
return strdup("");
}
// Test if we want to resolve an IPv6 address
bool IPv6 = false;
if(strstr(addr,":") != NULL)
@ -510,7 +501,7 @@ static size_t resolveAndAddHostname(size_t ippos, size_t oldnamepos)
// Important: Don't hold a lock while resolving as the main thread
// (dnsmasq) needs to be operable during the call to resolveHostname()
char *newname = resolveHostname(ipaddr);
char *newname = resolveHostname(ipaddr, false);
// If no hostname was found, try to obtain hostname from the network table
// This may be disabled due to a user setting

View File

@ -11,7 +11,7 @@
#define RESOLVE_H
void *DNSclient_thread(void *val);
char *resolveHostname(const char *addr) __attribute__((malloc));
char *resolveHostname(const char *addr, const bool force) __attribute__((malloc));
bool resolve_names(void) __attribute__((pure));
bool resolve_this_name(const char *ipaddr) __attribute__((pure));

View File

@ -1570,6 +1570,15 @@
[[ ${lines[0]} == "eae293f0c30369935a7457a789658bedebf92d544e7526bc43aa07883a597fa9 test/test.pem" ]]
}
@test "Internal IP -> name resolution works" {
run bash -c "./pihole-FTL ptr 127.0.0.1 | tail -n1"
printf "%s\n" "${lines[@]}"
[[ ${lines[0]} == "localhost" ]]
run bash -c "./pihole-FTL ptr ::1 | tail -n1"
printf "%s\n" "${lines[@]}"
[[ ${lines[0]} == "localhost" ]]
}
@test "API validation" {
run python3 test/api/checkAPI.py
printf "%s\n" "${lines[@]}"