Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
run: sudo apt-get update

- name: Setup Dependencies
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-12 ${{ matrix.compiler }} dnsutils python3-pip
run: sudo apt-get install cmake libc-ares-dev libcurl4-openssl-dev libev-dev build-essential clang-tidy-12 ${{ matrix.compiler }} dnsutils python3-pip valgrind

- name: Setup Robot Framework
run: sudo pip3 install robotframework
Expand All @@ -47,4 +47,6 @@ jobs:
if: ${{ success() || failure() }}
with:
name: robot-logs-${{ matrix.compiler }}
path: ${{github.workspace}}/tests/robot/*.html
path: |
${{github.workspace}}/tests/robot/*.html
${{github.workspace}}/tests/robot/valgrind-*.log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ log.html
output.xml
report.html
custom_curl/
valgrind-*.log
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-gnu-zero-variadic-macro-arguments -Wno-
endif()

# VERSION
# It is possible to define external default value like: cmake -DSW_VERSION=1.2-custom

find_package(Git)
if(Git_FOUND)
Expand All @@ -43,15 +44,23 @@ if(Git_FOUND)
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
message(STATUS "Version: ${GIT_VERSION}")

if(GIT_VERSION)
set(SW_VERSION "${GIT_VERSION}")
else()
message(WARNING "Could not find out version from git command!")
endif()

# May not update version in some cases (example: git commit --amend)
set_property(GLOBAL APPEND
PROPERTY CMAKE_CONFIGURE_DEPENDS
"${CMAKE_SOURCE_DIR}/.git/index")
else()
set(GIT_VERSION "UNKNOWN")
message(WARNING "Could not find git command! Version is set to: ${GIT_VERSION}")
message(WARNING "Could not find git command!")
endif()

if(NOT SW_VERSION)
message(WARNING "Version unset, using hardcoded!")
endif()

# LIBRARY DEPENDENCIES
Expand Down Expand Up @@ -99,9 +108,12 @@ set_property(TARGET ${TARGET_NAME} PROPERTY C_STANDARD 11)

define_file_basename_for_sources("https_dns_proxy")

set_source_files_properties(
src/main.c src/options.c
PROPERTIES COMPILE_FLAGS "-DGIT_VERSION='\"${GIT_VERSION}\"'")

if(SW_VERSION)
set_source_files_properties(
src/options.c
PROPERTIES COMPILE_FLAGS "-DSW_VERSION='\"${SW_VERSION}\"'")
endif()

if(CLANG_TIDY_EXE)
set_target_properties(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Usage: ./https_dns_proxy [-a <listen_addr>] [-p <listen_port>]

Functional tests can be executed using [Robot Framework](https://robotframework.org/).

dig command is expected to be available.
dig and valgrind commands are expected to be available.

```
pip3 install robotframework
Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ int main(int argc, char *argv[]) {

logging_init(opt.logfd, opt.loglevel);

ILOG("Version " GIT_VERSION);
ILOG("Built "__DATE__" "__TIME__".");
ILOG("Version: %s", options_sw_version());
ILOG("Built: " __DATE__ " " __TIME__);
ILOG("System c-ares: %s", ares_version(NULL));
ILOG("System libcurl: %s", curl_version());

Expand Down
11 changes: 10 additions & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@

#define DEFAULT_HTTP_VERSION 2


const char * options_sw_version() {
#ifdef SW_VERSION
return SW_VERSION;
#else
return "2023.01.01-atLeast"; // update date sometimes, like 1-2 times a year
#endif
}

void options_init(struct Options *opt) {
opt->listen_addr = "127.0.0.1";
opt->listen_port = 5053;
Expand Down Expand Up @@ -107,7 +116,7 @@ int options_parse_args(struct Options *opt, int argc, char **argv) {
case 'h':
return -1;
case 'V': // version
printf("%s\n", GIT_VERSION);
printf("%s\n", options_sw_version());
exit(0);
default:
printf("Unknown state!");
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef struct Options options_t;
#ifdef __cplusplus
extern "C" {
#endif
const char * options_sw_version();
void options_init(struct Options *opt);
int options_parse_args(struct Options *opt, int argc, char **argv);
void options_show_usage(int argc, char **argv);
Expand Down
59 changes: 41 additions & 18 deletions tests/robot/functional_tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,40 @@ ${PORT} 55353


*** Settings ***
Test Setup Start Proxy
Test Teardown Stop Proxy


*** Keywords ***
Common Test Setup
Set Test Variable &{expected_logs} loop destroyed=1 # last log line
Set Test Variable @{error_logs} [F] # any fatal error

Start Proxy
[Arguments] @{args}
@{default_args} = Create List -v -v -v -4 -p ${PORT}
@{proces_args} = Combine Lists ${default_args} ${args}
${proxy} = Start Process ${BINARY_PATH} @{proces_args}
# ... stdout=${TEMPDIR}/https_dns_proxy_robot_test_stdout.txt
... stderr=STDOUT alias=proxy
Set Test Variable ${proxy}
Set Test Variable &{expected_logs} loop destroyed=1 # last log line
Set Test Variable @{error_logs} [F] # any fatal error
Set Test Variable ${dig_timeout} 2
Set Test Variable ${dig_retry} 0
Sleep 0.5
Common Test Setup

Start Proxy With Valgrind
[Arguments] @{args}
@{default_args} = Create List --track-fds=yes --time-stamp=yes --log-file=valgrind-%p.log
... --gen-suppressions=all --tool=memcheck --leak-check=full --leak-resolution=high
... --show-leak-kinds=all --track-origins=yes --keep-stacktraces=alloc-and-free
... ${BINARY_PATH} -v -v -v -4 -p ${PORT}
@{proces_args} = Combine Lists ${default_args} ${args}
${proxy} = Start Process valgrind @{proces_args}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: process (two S).

... stderr=STDOUT alias=proxy
Set Test Variable ${proxy}
Set Test Variable ${dig_timeout} 4
Set Test Variable ${dig_retry} 2
Sleep 3 # wait for valgrind to fire up the proxy
Common Test Setup

Stop Proxy
Send Signal To Process SIGINT ${proxy}
Expand All @@ -44,7 +62,7 @@ Stop Proxy

Start Dig
[Arguments] ${domain}=google.com
${handle} = Start Process dig +timeout\=2 +retry\=0 @127.0.0.1 -p ${PORT} ${domain}
${handle} = Start Process dig +timeout\=${dig_timeout} +retry\=${dig_retry} @127.0.0.1 -p ${PORT} ${domain}
... stderr=STDOUT alias=dig
[Return] ${handle}

Expand All @@ -60,26 +78,31 @@ Run Dig
${handle} = Start Dig ${domain}
Stop Dig ${handle}

Run Dig Parallel
${dig_handles} = Create List
FOR ${domain} IN facebook.com microsoft.com youtube.com maps.google.com wikipedia.org amazon.com
${handle} = Start Dig ${domain}
Append To List ${dig_handles} ${handle}
END
FOR ${handle} IN @{dig_handles}
Stop Dig ${handle}
END

*** Test Cases ***
Simple smoke test
Run Dig

*** Test Cases ***
Handle Unbound Server Does Not Support HTTP/1.1
[Setup] NONE
Start Proxy -x -r https://doh.mullvad.net/dns-query # resolver uses Unbound
Run Keyword And Expect Error 9 != 0 # timeout exit code
... Run Dig

Reuse HTTP/2 Connection
[Documentation] After first successful request, further requests should not open new connections
Run Dig # opens first connection
${dig_handles} = Create List
FOR ${domain} IN facebook.com microsoft.com youtube.com maps.google.com wikipedia.org amazon.com
${handle} = Start Dig ${domain}
Append To List ${dig_handles} ${handle}
END
FOR ${handle} IN @{dig_handles}
Stop Dig ${handle}
END
Start Proxy
Run Dig # Simple smoke test and opens first connection
Run Dig Parallel
Set To Dictionary ${expected_logs} curl opened socket=1 # curl must not open more sockets then 1

Valgrind Resource Leak Check
Start Proxy With Valgrind
Run Dig Parallel