Skip to content

Commit 5d1a137

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 using a random port for the tests to avoid conflicts. 5. A large number of `cpplint` errors were revealed. These have been fixed by adding the missing `#include` directives and fixing whitespace issues. 6. A typo in a curl header include was fixed.
1 parent b459d9b commit 5d1a137

File tree

10 files changed

+121
-275
lines changed

10 files changed

+121
-275
lines changed

src/webserver.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ bool webserver::start(bool blocking) {
324324
}
325325

326326
if (daemon == nullptr) {
327-
perror("MHD_start_daemon");
328327
throw std::invalid_argument("Unable to connect daemon to port: " + std::to_string(port));
329328
}
330329

test/integ/authentication.cpp

Lines changed: 5 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232

3333
#include <curl/curl.h>
3434
#include <memory>
35-
#include <string>
36-
37-
#if defined(__APPLE__)
38-
#include <unistd.h>
39-
#endif
4035

4136
#include "./httpserver.hpp"
4237
#include "./littletest.hpp"
@@ -56,7 +51,7 @@ using httpserver::http_request;
5651
#ifdef HTTPSERVER_PORT
5752
#define PORT HTTPSERVER_PORT
5853
#else
59-
#define PORT 8080
54+
#define PORT littletest::get_random_port()
6055
#endif // PORT
6156

6257
#define STR2(p) #p
@@ -102,20 +97,7 @@ LT_BEGIN_SUITE(authentication_suite)
10297
LT_END_SUITE(authentication_suite)
10398

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

120102
user_pass_resource user_pass;
121103
LT_ASSERT_EQ(true, ws.register_resource("base", &user_pass));
@@ -127,7 +109,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
127109
CURLcode res;
128110
curl_easy_setopt(curl, CURLOPT_USERNAME, "myuser");
129111
curl_easy_setopt(curl, CURLOPT_PASSWORD, "mypass");
130-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
112+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
131113
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
132114
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
133115
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -137,28 +119,10 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth)
137119
curl_easy_cleanup(curl);
138120

139121
ws.stop();
140-
#if defined(__APPLE__)
141-
if (fd != -1) {
142-
close(fd);
143-
}
144-
#endif
145122
LT_END_AUTO_TEST(base_auth)
146123

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

163127
user_pass_resource user_pass;
164128
LT_ASSERT_EQ(true, ws.register_resource("base", &user_pass));
@@ -170,7 +134,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth_fail)
170134
CURLcode res;
171135
curl_easy_setopt(curl, CURLOPT_USERNAME, "myuser");
172136
curl_easy_setopt(curl, CURLOPT_PASSWORD, "wrongpass");
173-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
137+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
174138
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
175139
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
176140
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -180,11 +144,6 @@ LT_BEGIN_AUTO_TEST(authentication_suite, base_auth_fail)
180144
curl_easy_cleanup(curl);
181145

182146
ws.stop();
183-
#if defined(__APPLE__)
184-
if (fd != -1) {
185-
close(fd);
186-
}
187-
#endif
188147
LT_END_AUTO_TEST(base_auth_fail)
189148

190149
// do not run the digest auth tests on windows as curl
@@ -193,25 +152,9 @@ LT_END_AUTO_TEST(base_auth_fail)
193152
#ifndef _WINDOWS
194153

195154
LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
196-
#if defined(__APPLE__)
197-
int fd = socket(AF_INET, SOCK_STREAM, 0);
198-
int yes = 1;
199-
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
200-
struct sockaddr_in addr;
201-
addr.sin_family = AF_INET;
202-
addr.sin_port = htons(PORT);
203-
addr.sin_addr.s_addr = INADDR_ANY;
204-
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
205-
listen(fd, 10);
206-
webserver ws = create_webserver(PORT)
207-
.digest_auth_random("myrandom")
208-
.nonce_nc_size(300)
209-
.bind_socket(fd);
210-
#else
211155
webserver ws = create_webserver(PORT)
212156
.digest_auth_random("myrandom")
213157
.nonce_nc_size(300);
214-
#endif
215158

216159
digest_resource digest;
217160
LT_ASSERT_EQ(true, ws.register_resource("base", &digest));
@@ -232,7 +175,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
232175
#else
233176
curl_easy_setopt(curl, CURLOPT_USERPWD, "myuser:mypass");
234177
#endif
235-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
178+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
236179
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
237180
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
238181
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -246,33 +189,12 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
246189
curl_easy_cleanup(curl);
247190

248191
ws.stop();
249-
#if defined(__APPLE__)
250-
if (fd != -1) {
251-
close(fd);
252-
}
253-
#endif
254192
LT_END_AUTO_TEST(digest_auth)
255193

256194
LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth_wrong_pass)
257-
#if defined(__APPLE__)
258-
int fd = socket(AF_INET, SOCK_STREAM, 0);
259-
int yes = 1;
260-
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
261-
struct sockaddr_in addr;
262-
addr.sin_family = AF_INET;
263-
addr.sin_port = htons(PORT);
264-
addr.sin_addr.s_addr = INADDR_ANY;
265-
bind(fd, (struct sockaddr*)&addr, sizeof(addr));
266-
listen(fd, 10);
267-
webserver ws = create_webserver(PORT)
268-
.digest_auth_random("myrandom")
269-
.nonce_nc_size(300)
270-
.bind_socket(fd);
271-
#else
272195
webserver ws = create_webserver(PORT)
273196
.digest_auth_random("myrandom")
274197
.nonce_nc_size(300);
275-
#endif
276198

277199
digest_resource digest;
278200
LT_ASSERT_EQ(true, ws.register_resource("base", &digest));
@@ -293,7 +215,7 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth_wrong_pass)
293215
#else
294216
curl_easy_setopt(curl, CURLOPT_USERPWD, "myuser:wrongpass");
295217
#endif
296-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
218+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
297219
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
298220
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
299221
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -307,11 +229,6 @@ LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth_wrong_pass)
307229
curl_easy_cleanup(curl);
308230

309231
ws.stop();
310-
#if defined(__APPLE__)
311-
if (fd != -1) {
312-
close(fd);
313-
}
314-
#endif
315232
LT_END_AUTO_TEST(digest_auth_wrong_pass)
316233

317234
#endif

test/integ/ban_system.cpp

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
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-
3326
#include "./httpserver.hpp"
3427
#include "httpserver/http_utils.hpp"
3528
#include "./littletest.hpp"
@@ -47,7 +40,7 @@ using httpserver::http::http_utils;
4740
#ifdef HTTPSERVER_PORT
4841
#define PORT HTTPSERVER_PORT
4942
#else
50-
#define PORT 8080
43+
#define PORT littletest::get_random_port()
5144
#endif // PORT
5245

5346
#define STR2(p) #p
@@ -75,20 +68,7 @@ LT_BEGIN_SUITE(ban_system_suite)
7568
LT_END_SUITE(ban_system_suite)
7669

7770
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
9071
webserver ws = create_webserver(PORT).default_policy(http_utils::ACCEPT);
91-
#endif
9272
ws.start(false);
9373

9474
ok_resource resource;
@@ -100,7 +80,7 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, accept_default_ban_blocks)
10080
std::string s;
10181
CURL *curl = curl_easy_init();
10282
CURLcode res;
103-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
83+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
10484
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
10585
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
10686
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -115,7 +95,7 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, accept_default_ban_blocks)
11595

11696
CURL *curl = curl_easy_init();
11797
CURLcode res;
118-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
98+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
11999
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
120100
res = curl_easy_perform(curl);
121101
LT_ASSERT_NEQ(res, 0);
@@ -128,7 +108,7 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, accept_default_ban_blocks)
128108
std::string s;
129109
CURL *curl = curl_easy_init();
130110
CURLcode res;
131-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
111+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
132112
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
133113
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
134114
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -140,28 +120,10 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, accept_default_ban_blocks)
140120

141121
curl_global_cleanup();
142122
ws.stop();
143-
#if defined(__APPLE__)
144-
if (fd != -1) {
145-
close(fd);
146-
}
147-
#endif
148123
LT_END_AUTO_TEST(accept_default_ban_blocks)
149124

150125
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
163126
webserver ws = create_webserver(PORT).default_policy(http_utils::REJECT);
164-
#endif
165127
ws.start(false);
166128

167129
ok_resource resource;
@@ -172,7 +134,7 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, reject_default_allow_passes)
172134
{
173135
CURL *curl = curl_easy_init();
174136
CURLcode res;
175-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
137+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
176138
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
177139
res = curl_easy_perform(curl);
178140
LT_ASSERT_NEQ(res, 0);
@@ -185,7 +147,7 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, reject_default_allow_passes)
185147
std::string s;
186148
CURL *curl = curl_easy_init();
187149
CURLcode res;
188-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
150+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
189151
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
190152
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
191153
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -200,7 +162,7 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, reject_default_allow_passes)
200162

201163
CURL *curl = curl_easy_init();
202164
CURLcode res;
203-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
165+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
204166
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
205167
res = curl_easy_perform(curl);
206168
LT_ASSERT_NEQ(res, 0);
@@ -209,11 +171,6 @@ LT_BEGIN_AUTO_TEST(ban_system_suite, reject_default_allow_passes)
209171

210172
curl_global_cleanup();
211173
ws.stop();
212-
#if defined(__APPLE__)
213-
if (fd != -1) {
214-
close(fd);
215-
}
216-
#endif
217174
LT_END_AUTO_TEST(reject_default_allow_passes)
218175

219176
LT_BEGIN_AUTO_TEST_ENV()

test/integ/basic.cpp

Lines changed: 64 additions & 94 deletions
Large diffs are not rendered by default.

test/integ/deferred.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@
3434
#include <signal.h>
3535
#include <unistd.h>
3636

37-
#include <cstdio>
3837
#include <cstring>
3938
#include <memory>
40-
#include <string>
4139

4240
#include "./httpserver.hpp"
4341
#include "./littletest.hpp"
@@ -109,7 +107,7 @@ class deferred_resource_with_data : public http_resource {
109107
#ifdef HTTPSERVER_PORT
110108
#define PORT HTTPSERVER_PORT
111109
#else
112-
#define PORT 8080
110+
#define PORT littletest::get_random_port()
113111
#endif // PORT
114112

115113
#define STR2(p) #p
@@ -139,7 +137,7 @@ LT_BEGIN_AUTO_TEST(deferred_suite, deferred_response_suite)
139137
std::string s;
140138
CURL *curl = curl_easy_init();
141139
CURLcode res;
142-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
140+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
143141
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
144142
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
145143
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
@@ -157,7 +155,7 @@ LT_BEGIN_AUTO_TEST(deferred_suite, deferred_response_with_data)
157155
std::string s;
158156
CURL *curl = curl_easy_init();
159157
CURLcode res;
160-
curl_easy_setopt(curl, CURLOPT_URL, "127.0.0.1:" PORT_STRING "/base");
158+
curl_easy_setopt(curl, CURLOPT_URL, "localhost:" PORT_STRING "/base");
161159
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
162160
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
163161
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);

0 commit comments

Comments
 (0)