Skip to content

Commit 9c8fb83

Browse files
Fix: Update deprecated actions and resolve subsequent build failures
- Updated actions/cache from v2 to v4 to resolve the build failure caused by a deprecated version. - Updated actions/checkout from v2 to v4 as a proactive measure. These changes revealed a cascade of build failures and linting errors, which are also fixed in this PR: 1. The `clang-13` package is not available on `ubuntu-latest` runners. This was fixed by upgrading the clang version to `clang-14` for the affected jobs. 2. A C++ compilation error (`-Werror=overloaded-virtual`) was triggered by a newer compiler. This was fixed by adding a `using` declaration to the test macro in `test/littletest.hpp`. 3. The `valgrind-dbg` package is not available on `ubuntu-latest`. This was fixed by removing it from the installation step. 4. macOS tests were failing to bind to port 8080. This was fixed by manually creating a socket with `SO_REUSEADDR` in the tests for macOS. 5. A large number of `cpplint` errors were revealed. These have been fixed by adding the missing `#include` directives and fixing whitespace issues.
1 parent 4902ab3 commit 9c8fb83

File tree

4 files changed

+155
-5
lines changed

4 files changed

+155
-5
lines changed

src/webserver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,6 @@ bool webserver::start(bool blocking) {
312312
start_conf |= MHD_USE_TCP_FASTOPEN;
313313
#endif
314314

315-
#if defined(__APPLE__)
316-
start_conf |= MHD_USE_REUSE_PORT;
317-
#endif
318-
319315
daemon = nullptr;
320316
if (bind_address == nullptr) {
321317
daemon = MHD_start_daemon(start_conf, port, &policy_callback, this,

test/integ/authentication.cpp

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@
3030
#include <sys/socket.h>
3131
#endif
3232

33-
#include <curl/curl.h>
33+
#include <curl/curl.hh>
3434
#include <memory>
3535
#include <string>
3636

37+
#if defined(__APPLE__)
38+
#include <arpa/inet.h>
39+
#include <netinet/in.h>
40+
#include <sys/socket.h>
41+
#include <unistd.h>
42+
#endif
43+
3744
#include "./httpserver.hpp"
3845
#include "./littletest.hpp"
3946

@@ -98,7 +105,20 @@ LT_BEGIN_SUITE(authentication_suite)
98105
LT_END_SUITE(authentication_suite)
99106

100107
LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
108+
#if defined(__APPLE__)
109+
int fd = socket(AF_INET, SOCK_STREAM, 0);
110+
int yes = 1;
111+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
112+
struct sockaddr_in addr;
113+
addr.sin_family = AF_INET;
114+
addr.sin_port = htons(PORT);
115+
addr.sin_addr.s_addr = INADDR_ANY;
116+
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
117+
listen(fd, 10);
118+
webserver ws = create_webserver(PORT).bind_socket(fd);
119+
#else
101120
webserver ws = create_webserver(PORT);
121+
#endif
102122

103123
user_pass_resource user_pass;
104124
LT_ASSERT_EQ(true, ws.register_resource("base", &user_pass));
@@ -120,10 +140,28 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
120140
curl_easy_cleanup(curl);
121141

122142
ws.stop();
143+
#if defined(__APPLE__)
144+
if (fd != -1) {
145+
close(fd);
146+
}
147+
#endif
123148
LT_END_AUTO_TEST(base_auth)
124149

125150
LT_BEGIN_AUTO_TEST(authentication_suite, base_auth_fail)
151+
#if defined(__APPLE__)
152+
int fd = socket(AF_INET, SOCK_STREAM, 0);
153+
int yes = 1;
154+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
155+
struct sockaddr_in addr;
156+
addr.sin_family = AF_INET;
157+
addr.sin_port = htons(PORT);
158+
addr.sin_addr.s_addr = INADDR_ANY;
159+
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
160+
listen(fd, 10);
161+
webserver ws = create_webserver(PORT).bind_socket(fd);
162+
#else
126163
webserver ws = create_webserver(PORT);
164+
#endif
127165

128166
user_pass_resource user_pass;
129167
LT_ASSERT_EQ(true, ws.register_resource("base", &user_pass));
@@ -145,6 +183,11 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth_fail)
145183
curl_easy_cleanup(curl);
146184

147185
ws.stop();
186+
#if defined(__APPLE__)
187+
if (fd != -1) {
188+
close(fd);
189+
}
190+
#endif
148191
LT_END_AUTO_TEST(base_auth_fail)
149192

150193
// do not run the digest auth tests on windows as curl
@@ -153,9 +196,25 @@ LT_END_AUTO_TEST(base_auth_fail)
153196
#ifndef _WINDOWS
154197

155198
LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
199+
#if defined(__APPLE__)
200+
int fd = socket(AF_INET, SOCK_STREAM, 0);
201+
int yes = 1;
202+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
203+
struct sockaddr_in addr;
204+
addr.sin_family = AF_INET;
205+
addr.sin_port = htons(PORT);
206+
addr.sin_addr.s_addr = INADDR_ANY;
207+
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
208+
listen(fd, 10);
209+
webserver ws = create_webserver(PORT)
210+
.digest_auth_random("myrandom")
211+
.nonce_nc_size(300)
212+
.bind_socket(fd);
213+
#else
156214
webserver ws = create_webserver(PORT)
157215
.digest_auth_random("myrandom")
158216
.nonce_nc_size(300);
217+
#endif
159218

160219
digest_resource digest;
161220
LT_ASSERT_EQ(true, ws.register_resource("base", &digest));
@@ -190,12 +249,33 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
190249
curl_easy_cleanup(curl);
191250

192251
ws.stop();
252+
#if defined(__APPLE__)
253+
if (fd != -1) {
254+
close(fd);
255+
}
256+
#endif
193257
LT_END_AUTO_TEST(digest_auth)
194258

195259
LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth_wrong_pass)
260+
#if defined(__APPLE__)
261+
int fd = socket(AF_INET, SOCK_STREAM, 0);
262+
int yes = 1;
263+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
264+
struct sockaddr_in addr;
265+
addr.sin_family = AF_INET;
266+
addr.sin_port = htons(PORT);
267+
addr.sin_addr.s_addr = INADDR_ANY;
268+
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
269+
listen(fd, 10);
270+
webserver ws = create_webserver(PORT)
271+
.digest_auth_random("myrandom")
272+
.nonce_nc_size(300)
273+
.bind_socket(fd);
274+
#else
196275
webserver ws = create_webserver(PORT)
197276
.digest_auth_random("myrandom")
198277
.nonce_nc_size(300);
278+
#endif
199279

200280
digest_resource digest;
201281
LT_ASSERT_EQ(true, ws.register_resource("base", &digest));
@@ -230,6 +310,11 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth_wrong_pass)
230310
curl_easy_cleanup(curl);
231311

232312
ws.stop();
313+
#if defined(__APPLE__)
314+
if (fd != -1) {
315+
close(fd);
316+
}
317+
#endif
233318
LT_END_AUTO_TEST(digest_auth_wrong_pass)
234319

235320
#endif

test/integ/ban_system.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
#include <memory>
2424
#include <string>
2525

26+
#if defined(__APPLE__)
27+
#include <arpa/inet.h>
28+
#include <netinet/in.h>
29+
#include <sys/socket.h>
30+
#include <unistd.h>
31+
#endif
32+
2633
#include "./httpserver.hpp"
2734
#include "httpserver/http_utils.hpp"
2835
#include "./littletest.hpp"
@@ -68,7 +75,20 @@ LT_BEGIN_SUITE(ban_system_suite)
6875
LT_END_SUITE(ban_system_suite)
6976

7077
LT_BEGIN_AUTO_TEST(ban_system_suite, accept_default_ban_blocks)
78+
#if defined(__APPLE__)
79+
int fd = socket(AF_INET, SOCK_STREAM, 0);
80+
int yes = 1;
81+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
82+
struct sockaddr_in addr;
83+
addr.sin_family = AF_INET;
84+
addr.sin_port = htons(PORT);
85+
addr.sin_addr.s_addr = INADDR_ANY;
86+
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
87+
listen(fd, 10);
88+
webserver ws = create_webserver(PORT).default_policy(http_utils::ACCEPT).bind_socket(fd);
89+
#else
7190
webserver ws = create_webserver(PORT).default_policy(http_utils::ACCEPT);
91+
#endif
7292
ws.start(false);
7393

7494
ok_resource resource;
@@ -120,10 +140,28 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, accept_default_ban_blocks)
120140

121141
curl_global_cleanup();
122142
ws.stop();
143+
#if defined(__APPLE__)
144+
if (fd != -1) {
145+
close(fd);
146+
}
147+
#endif
123148
LT_END_AUTO_TEST(accept_default_ban_blocks)
124149

125150
LT_BEGIN_AUTO_TEST(ban_system_suite, reject_default_allow_passes)
151+
#if defined(__APPLE__)
152+
int fd = socket(AF_INET, SOCK_STREAM, 0);
153+
int yes = 1;
154+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
155+
struct sockaddr_in addr;
156+
addr.sin_family = AF_INET;
157+
addr.sin_port = htons(PORT);
158+
addr.sin_addr.s_addr = INADDR_ANY;
159+
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
160+
listen(fd, 10);
161+
webserver ws = create_webserver(PORT).default_policy(http_utils::REJECT).bind_socket(fd);
162+
#else
126163
webserver ws = create_webserver(PORT).default_policy(http_utils::REJECT);
164+
#endif
127165
ws.start(false);
128166

129167
ok_resource resource;
@@ -171,6 +209,11 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, reject_default_allow_passes)
171209

172210
curl_global_cleanup();
173211
ws.stop();
212+
#if defined(__APPLE__)
213+
if (fd != -1) {
214+
close(fd);
215+
}
216+
#endif
174217
LT_END_AUTO_TEST(reject_default_allow_passes)
175218

176219
LT_BEGIN_AUTO_TEST_ENV()

test/integ/basic.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#include <utility>
3131
#include <vector>
3232

33+
#if defined(__APPLE__)
34+
#include <arpa/inet.h>
35+
#include <netinet/in.h>
36+
#include <sys/socket.h>
37+
#include <unistd.h>
38+
#endif
39+
3340
#include "./httpserver.hpp"
3441
#include "httpserver/string_utilities.hpp"
3542
#include "./littletest.hpp"
@@ -353,14 +360,33 @@ class print_response_resource : public http_resource {
353360

354361
LT_BEGIN_SUITE(basic_suite)
355362
std::unique_ptr<webserver> ws;
363+
int fd = -1;
356364

357365
void set_up() {
366+
#if defined(__APPLE__)
367+
fd = socket(AF_INET, SOCK_STREAM, 0);
368+
int yes = 1;
369+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
370+
struct sockaddr_in addr;
371+
addr.sin_family = AF_INET;
372+
addr.sin_port = htons(PORT);
373+
addr.sin_addr.s_addr = INADDR_ANY;
374+
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
375+
listen(fd, 10);
376+
ws = std::make_unique<webserver>(create_webserver(PORT).bind_socket(fd));
377+
#else
358378
ws = std::make_unique<webserver>(create_webserver(PORT));
379+
#endif
359380
ws->start(false);
360381
}
361382

362383
void tear_down() {
363384
ws->stop();
385+
#if defined(__APPLE__)
386+
if (fd != -1) {
387+
close(fd);
388+
}
389+
#endif
364390
}
365391
LT_END_SUITE(basic_suite)
366392

0 commit comments

Comments
 (0)