Skip to content

Commit 72edd1d

Browse files
committed
tests: local network only
This modifies all existing minimal examples / tests that need external network, to use a local partner instead. Accordingly, LWS_CTEST_INTERNET_AVAILABLE is removed since all tests have made arrangements to no longer need external network.
1 parent 8952062 commit 72edd1d

45 files changed

Lines changed: 1466 additions & 1244 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,10 @@ option(LWS_ONLY_SSPC "Remove everything from library except standalone SSPC clie
240240
#
241241
# CTest options
242242
#
243-
#
244243
# If you build with LWS_WITH_MINIMAL_EXAMPLES, you can use CTest / make test to run
245-
# examples that can give a pass/fail response. By default it runs tests both against
246-
# a local server peer and warmcat.com, if your CI wants to do the tests but does not
247-
# have internet routing, then you can still run a subset of tests with CTest / make
248-
# test that only does local tests by disabling this option.
244+
# examples that can give a pass/fail response. All of the ctests run against local
245+
# server peers only, they do not need any internet routing.
249246
#
250-
option(LWS_CTEST_INTERNET_AVAILABLE "CTest will performs tests that need the Internet" ON)
251247

252248
if (NOT LWS_IPV4)
253249
set(LWS_CTEST_SERVER_RESOLVE "::1")

READMEs/README.ctest.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ process exiting with exit code 0 as success, anything else as failure.
3535

3636
## Generating the tests
3737

38-
The main tests just need `-DLWS_WITH_MINIMAL_EXAMPLES=1`. You can optionally set
39-
`-DLWS_CTEST_INTERNET_AVAILABLE=0` to indicate you can't run the tests that need
40-
internet connectivity.
38+
The main tests just need `-DLWS_WITH_MINIMAL_EXAMPLES=1`. All of the tests run
39+
against local server peers only and do not need any internet connectivity.
4140

4241
## Preparing to run the tests
4342

cmake/LwsCheckRequirements.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ MACRO(require_lws_config reqconfig _val result)
3737
endif()
3838
endif()
3939
set(${result} 0)
40+
set(MET 0)
4041
else()
4142
if (LWS_WITH_MINIMAL_EXAMPLES)
4243
set(MET ${SAME})
@@ -61,6 +62,14 @@ MACRO(require_lws_config reqconfig _val result)
6162
endif()
6263
endif()
6364

65+
# for non-requirements result vars, export whether the requirement
66+
# was met, so callers can gate optional features on it (eg, proxy
67+
# api ctests). "requirements" keeps its earlier-failed sticky 0.
68+
69+
if (NOT _cmp)
70+
set(${result} ${MET})
71+
endif()
72+
6473
endif()
6574
ENDMACRO()
6675

minimal-examples-lowlevel/api-tests/api-test-dns-server/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,4 @@ if (requirements)
2323
else()
2424
target_link_libraries(${SAMP} websockets ${LIBWEBSOCKETS_DEP_LIBS})
2525
endif()
26-
27-
if (LWS_CTEST_INTERNET_AVAILABLE)
28-
endif()
2926
endif()

minimal-examples-lowlevel/api-tests/api-test-secure-streams/CMakeLists.txt

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,13 @@ if (requirements)
1515

1616
add_executable(${PROJECT_NAME} main.c)
1717

18-
if (LWS_CTEST_INTERNET_AVAILABLE)
19-
add_test(NAME api-test-secure-streams COMMAND ${PROJECT_NAME})
20-
set_tests_properties(api-test-secure-streams
21-
PROPERTIES
22-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples-lowlevel/api-tests/api-test-secure-streams
23-
TIMEOUT 90)
24-
endif()
25-
2618
#
2719
# Local-server variant: runs the same test logic against a local
2820
# lws-minimal-http-server-httpbin over TLS, so it does not need any
2921
# external network egress. Suitable for IPv6-only / no-egress CI.
3022
#
3123

32-
if (LWS_CTEST_INTERNET_AVAILABLE AND NOT WIN32 AND LWS_WITH_SERVER)
24+
if (NOT WIN32 AND LWS_WITH_SERVER)
3325
lws_get_free_port(PORT_ATS_SRV_TLS)
3426

3527
configure_file(policy-local.json.in policy-local.json @ONLY)

minimal-examples-lowlevel/http-server/minimal-http-server-httpbin/minimal-http-server-httpbin.c

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
* Universal Public Domain Dedication.
88
*
99
* This demonstrates a minimal http server that mimics basic httpbin.org functionality
10-
* used by lws ctests for testing offline, e.g. /status/200, /delay/10, /bytes/1000.
10+
* used by lws ctests for testing offline, e.g. /status/200, /delay/10,
11+
* /bytes/1000 and /urlarg/?x=... (echoes back the x= uri argument).
12+
*
13+
* The routes respond to POSTs the same as GETs, after consuming the request
14+
* body.
1115
*/
1216

1317
#include <libwebsockets.h>
@@ -31,11 +35,15 @@ struct pss {
3135
lws_sorted_usec_list_t sul;
3236
struct lws *wsi;
3337
char path[128];
38+
char urlarg[8192];
39+
size_t urlarg_len;
3440
int status_code;
3541
int delay_secs;
3642
size_t bytes_left;
3743
int headers_sent;
3844
int writing_bytes;
45+
int echoing_urlarg;
46+
int is_post;
3947
};
4048

4149
static int interrupted;
@@ -81,18 +89,41 @@ callback_httpbin(struct lws *wsi, enum lws_callback_reasons reason,
8189
pss->bytes_left = 0;
8290
pss->headers_sent = 0;
8391
pss->writing_bytes = 0;
92+
pss->echoing_urlarg = 0;
93+
pss->is_post = !!lws_hdr_total_length(wsi, WSI_TOKEN_POST_URI);
8494

8595
lwsl_notice("%s: HTTP: URI %s\n", __func__, uri);
8696

8797
if (!strncmp(uri, "/status/", 8)) {
8898
pss->status_code = atoi(uri + 8);
8999
} else if (!strncmp(uri, "/delay/", 7)) {
90100
pss->delay_secs = atoi(uri + 7);
101+
} else if (!strncmp(uri, "/urlarg", 7)) {
102+
/*
103+
* Echo back the x= uri argument content, like the
104+
* urlarg plugin on warmcat's test server
105+
*/
106+
int alen = lws_get_urlarg_by_name_safe(wsi, "x",
107+
pss->urlarg, sizeof(pss->urlarg) - 1);
108+
109+
if (alen < 0) {
110+
pss->status_code = 400;
111+
} else {
112+
pss->urlarg_len = (size_t)alen;
113+
pss->bytes_left = (size_t)alen;
114+
pss->writing_bytes = 1;
115+
pss->echoing_urlarg = 1;
116+
}
91117
} else if (!strncmp(uri, "/bytes/", 7)) {
92118
pss->bytes_left = (size_t)atoll(uri + 7);
93119
pss->writing_bytes = 1;
94120
}
95121

122+
if (pss->is_post) {
123+
/* consume the POST body, reply after it has all come */
124+
return 0;
125+
}
126+
96127
if (pss->delay_secs > 0) {
97128
lwsl_notice("%s: delaying %d secs\n", __func__, pss->delay_secs);
98129
lws_sul_schedule(lws_get_context(wsi), 0, &pss->sul, delay_cb,
@@ -104,6 +135,18 @@ callback_httpbin(struct lws *wsi, enum lws_callback_reasons reason,
104135
return 0;
105136
}
106137

138+
case LWS_CALLBACK_HTTP_BODY:
139+
/* we just discard POST body content */
140+
return 0;
141+
142+
case LWS_CALLBACK_HTTP_BODY_COMPLETION:
143+
pss->wsi = wsi;
144+
pss->status_code = 200;
145+
pss->headers_sent = 0;
146+
/* keep any route-set response body, eg POST /bytes/1000 */
147+
lws_callback_on_writable(wsi);
148+
return 0;
149+
107150
case LWS_CALLBACK_HTTP_WRITEABLE:
108151

109152
if (!pss || pss->delay_secs)
@@ -142,7 +185,12 @@ callback_httpbin(struct lws *wsi, enum lws_callback_reasons reason,
142185
if (chunk > sizeof(buf) - LWS_PRE)
143186
chunk = sizeof(buf) - LWS_PRE;
144187

145-
memset(start, 'A', chunk);
188+
if (pss->echoing_urlarg)
189+
memcpy(start,
190+
pss->urlarg + (pss->urlarg_len -
191+
pss->bytes_left), chunk);
192+
else
193+
memset(start, 'A', chunk);
146194

147195
n = lws_write(wsi, start, chunk, (pss->bytes_left == chunk) ? LWS_WRITE_HTTP_FINAL : LWS_WRITE_HTTP);
148196
if (n < 0)

minimal-examples-lowlevel/secure-streams/minimal-secure-streams-blob/CMakeLists.txt

Lines changed: 71 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -22,100 +22,32 @@ if (requirements)
2222

2323
find_program(VALGRIND "valgrind")
2424

25-
if (LWS_CTEST_INTERNET_AVAILABLE AND NOT WIN32)
26-
27-
#
28-
# When running in CI, wait for a lease on the resources
29-
# before starting this test, so the server does not get
30-
# thousands of simultaneous tls connection attempts
31-
#
32-
# sai-resource holds the lease on the resources until
33-
# the time given in seconds or the sai-resource instance
34-
# exits, whichever happens first
35-
#
36-
# If running under Sai, creates a lock test called "res_sspcmin"
37-
#
38-
39-
sai_resource(warmcat_conns 1 40 sspcminblob)
40-
41-
#
42-
# simple test not via proxy
43-
#
44-
45-
if (VALGRIND AND NOT LWS_WITH_ASAN)
46-
message("testing via valgrind")
47-
add_test(NAME ssblob-warmcat COMMAND
48-
${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
49-
$<TARGET_FILE:lws-minimal-secure-streams>)
50-
else()
51-
add_test(NAME ssblob-warmcat COMMAND lws-minimal-secure-streams)
52-
endif()
53-
54-
set_tests_properties(ssblob-warmcat
55-
PROPERTIES
56-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples-lowlevel/secure-streams/minimal-secure-streams
57-
TIMEOUT 40)
58-
if (DEFINED ENV{SAI_OVN})
59-
set_tests_properties(ssblob-warmcat PROPERTIES FIXTURES_REQUIRED "res_sspcmin")
60-
endif()
61-
62-
if (HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API)
63-
64-
#
65-
# Define test dep to bring up and take down the test
66-
# proxy
67-
#
68-
69-
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
70-
# uds abstract namespace for linux
71-
set(CTEST_SOCKET_PATH "@ctest-ssblobproxy-$ENV{SAI_PROJECT}-$ENV{SAI_OVN}")
72-
else()
73-
# filesystem socket for others
74-
if (DEFINED ENV{SAI_OVN})
75-
string(SUBSTRING "$ENV{SAI_OVN}" 32 16 SHORT_HASH)
76-
else()
77-
set(SHORT_HASH "0")
78-
endif()
79-
set(CTEST_SOCKET_PATH "/tmp/ctest-ssblobproxy-$ENV{SAI_PROJECT}-${SHORT_HASH}")
80-
endif()
81-
add_test(NAME st_ssblobproxy COMMAND
82-
${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh
83-
ssblobproxy $<TARGET_FILE:lws-minimal-secure-streams-proxy>
84-
-i ${CTEST_SOCKET_PATH} )
85-
set_tests_properties(st_ssblobproxy PROPERTIES WORKING_DIRECTORY . FIXTURES_SETUP ssblobproxy TIMEOUT 800)
86-
87-
add_test(NAME ki_ssblobproxy COMMAND
88-
${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh
89-
ssblobproxy $<TARGET_FILE:lws-minimal-secure-streams-proxy>
90-
-i ${CTEST_SOCKET_PATH})
91-
set_tests_properties(ki_ssblobproxy PROPERTIES FIXTURES_CLEANUP ssblobproxy)
92-
93-
#
94-
# the client part that will connect to the proxy
95-
#
96-
97-
if (VALGRIND AND NOT LWS_WITH_ASAN)
98-
message("testing via valgrind")
99-
add_test(NAME sspcblob-minimal COMMAND
100-
${VALGRIND} --tool=memcheck --leak-check=yes --num-callers=20
101-
$<TARGET_FILE:lws-minimal-secure-streams-blob-client> -i +${CTEST_SOCKET_PATH} --timeout_ms 65000)
102-
else()
103-
add_test(NAME sspcblob-minimal COMMAND lws-minimal-secure-streams-blob-client -i +${CTEST_SOCKET_PATH} --timeout_ms 65000)
104-
endif()
105-
106-
set(fixlist "ssblobproxy")
107-
if (DEFINED ENV{SAI_OVN})
108-
list(APPEND fixlist "res_ssblobproxy")
109-
endif()
110-
111-
set_tests_properties(sspcblob-minimal PROPERTIES
112-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples-lowlevel/secure-streams/minimal-secure-streams-blob
113-
FIXTURES_REQUIRED "${fixlist}"
114-
TIMEOUT 70)
115-
116-
endif()
117-
118-
endif()
25+
#
26+
# Local-server variant: runs against a local lws-minimal-http-server-httpbin
27+
# over TLS, so it does not need any external network egress.
28+
#
29+
30+
if (NOT WIN32 AND LWS_WITH_SERVER)
31+
lws_get_free_port(PORT_BLOB_HBIN_TLS)
32+
33+
configure_file(policy-local.json.in policy-local.json @ONLY)
34+
35+
add_test(NAME st_blob_hbin
36+
COMMAND ${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh
37+
blob_hbin $<TARGET_FILE:lws-minimal-http-server-httpbin>
38+
-s -p ${PORT_BLOB_HBIN_TLS})
39+
add_test(NAME ki_blob_hbin
40+
COMMAND ${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh
41+
blob_hbin $<TARGET_FILE_NAME:lws-minimal-http-server-httpbin>
42+
-p ${PORT_BLOB_HBIN_TLS})
43+
set_tests_properties(st_blob_hbin PROPERTIES
44+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/minimal-examples-lowlevel/http-server/minimal-http-server-tls
45+
FIXTURES_SETUP blob_hbin
46+
TIMEOUT 800
47+
ENVIRONMENT "SAI_LIST_PORT=${PORT_BLOB_HBIN_TLS}")
48+
set_tests_properties(ki_blob_hbin PROPERTIES FIXTURES_CLEANUP blob_hbin)
49+
50+
endif()
11951

12052
if (websockets_shared)
12153
target_link_libraries(${SAMP} websockets_shared ${LIBWEBSOCKETS_DEP_LIBS})
@@ -138,4 +70,49 @@ if (requirements)
13870
endif()
13971
endif()
14072

73+
74+
#
75+
# Local-proxy variant: the proxy uses the local policy and the local
76+
# httpbin peer instead of fetching a policy from warmcat.com, so this
77+
# needs no external network egress. Deliberately outside the
78+
#
79+
80+
if (NOT WIN32 AND LWS_WITH_SERVER AND
81+
(HAS_LWS_WITH_SECURE_STREAMS_PROXY_API OR LWS_WITH_SECURE_STREAMS_PROXY_API))
82+
83+
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
84+
# uds abstract namespace for linux
85+
set(CTEST_LOCAL_SOCKET_PATH "@ctest-sspblob-local-$ENV{SAI_PROJECT}-$ENV{SAI_OVN}")
86+
else()
87+
# filesystem socket for others
88+
if (DEFINED ENV{SAI_OVN})
89+
string(SUBSTRING "$ENV{SAI_OVN}" 32 16 SHORT_HASH)
90+
else()
91+
set(SHORT_HASH "0")
92+
endif()
93+
set(CTEST_LOCAL_SOCKET_PATH "/tmp/ctest-sspblob-local-$ENV{SAI_PROJECT}-${SHORT_HASH}")
94+
endif()
95+
96+
configure_file(policy-local.json.in policy-local.json @ONLY)
97+
98+
add_test(NAME st_blob_proxy_local COMMAND
99+
${CMAKE_SOURCE_DIR}/scripts/ctest-background.sh
100+
blob_proxy_local $<TARGET_FILE:lws-minimal-secure-streams-proxy>
101+
-i ${CTEST_LOCAL_SOCKET_PATH}
102+
-c ${CMAKE_CURRENT_BINARY_DIR}/policy-local.json)
103+
set_tests_properties(st_blob_proxy_local PROPERTIES
104+
WORKING_DIRECTORY .
105+
FIXTURES_SETUP blob_proxy_local
106+
FIXTURES_REQUIRED "blob_hbin"
107+
TIMEOUT 800)
108+
109+
add_test(NAME ki_blob_proxy_local COMMAND
110+
${CMAKE_SOURCE_DIR}/scripts/ctest-background-kill.sh
111+
blob_proxy_local $<TARGET_FILE:lws-minimal-secure-streams-proxy>
112+
-i ${CTEST_LOCAL_SOCKET_PATH}
113+
-c ${CMAKE_CURRENT_BINARY_DIR}/policy-local.json)
114+
set_tests_properties(ki_blob_proxy_local PROPERTIES FIXTURES_CLEANUP blob_proxy_local)
115+
116+
endif()
117+
141118
endif()

minimal-examples-lowlevel/secure-streams/minimal-secure-streams-blob/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ protocol it uses is kept separated in policy-database.c
2121
Commandline option|Meaning
2222
---|---
2323
-d <loglevel>|Debug verbosity in decimal, eg, -d15
24+
-c <policy-file>|Use the policy from this JSON file instead of the compiled-in one, eg to target a local test server
2425
-f| Force connecting to the wrong endpoint to check backoff retry flow
2526
-p| Run as proxy server for clients to connect to over unix domain socket
2627
--force-portal|Force the SS Captive Portal Detection to feel it's behind a portal

0 commit comments

Comments
 (0)