-
-
Notifications
You must be signed in to change notification settings - Fork 191
Expand file tree
/
Copy pathconsumer_fixture.cpp
More file actions
160 lines (142 loc) · 6.28 KB
/
Copy pathconsumer_fixture.cpp
File metadata and controls
160 lines (142 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
This file is part of libhttpserver
Copyright (C) 2011-2019 Sebastiano Merlino
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
USA
*/
// Compile-only consumer fixture: touches every public symbol whose declaration
// was previously guarded by #ifdef HAVE_* in the public headers. This file
// MUST compile and link with the library in every combination of
// HAVE_BAUTH / HAVE_DAUTH / HAVE_GNUTLS / HAVE_WEBSOCKET.
//
// Runtime behaviour is irrelevant; main() returns 0 immediately.
// CI gate: .github/workflows/verify-build.yml.
#include <cstddef>
#include <memory>
#include <string>
#include "./httpserver.hpp"
// create_test_request isn't pulled in by the umbrella header (it lives
// under the test-helper banner), so include it explicitly. AM_CPPFLAGS
// already passes -DHTTPSERVER_COMPILATION, so the gate at the top of
// the header is satisfied.
#include "httpserver/create_test_request.hpp"
namespace fixture {
httpserver::webserver build_server() {
httpserver::create_webserver cw{8080};
cw.use_ssl(false); // always callable (was #ifdef HAVE_GNUTLS implicitly)
cw.basic_auth(false); // always callable (was #ifdef HAVE_BAUTH)
return httpserver::webserver{cw};
}
void touch_request_accessors(const httpserver::http_request& req) {
(void)req.get_user(); // was #ifdef HAVE_BAUTH
(void)req.get_pass(); // was #ifdef HAVE_BAUTH
(void)req.get_digested_user(); // was #ifdef HAVE_DAUTH
(void)req.get_client_cert_dn(); // already unconditional
(void)req.has_tls_session();
using ddr = httpserver::http::http_utils::digest_auth_result;
(void)sizeof(ddr);
// Pin every remaining TLS cert accessor declared in
// http_request.hpp. These were #ifdef HAVE_GNUTLS-gated before being
// made unconditional. Calling them on a TLS-off build returns the documented
// sentinel (empty string / false / 0) without touching gnutls.
(void)req.get_client_cert_issuer_dn();
(void)req.get_client_cert_cn();
(void)req.get_client_cert_fingerprint_sha256();
(void)req.has_client_certificate();
(void)req.is_client_cert_verified();
(void)req.get_client_cert_not_before();
(void)req.get_client_cert_not_after();
// link-time proof that both check_digest_auth overloads are declared unconditionally.
using check_pw_t = httpserver::http::http_utils::digest_auth_result
(httpserver::http_request::*)(
const std::string&, const std::string&, unsigned int, uint32_t,
httpserver::http::http_utils::digest_algorithm) const;
check_pw_t cd_pw = &httpserver::http_request::check_digest_auth;
(void)cd_pw;
using check_digest_t = httpserver::http::http_utils::digest_auth_result
(httpserver::http_request::*)(
const std::string&, const void*, size_t, unsigned int, uint32_t,
httpserver::http::http_utils::digest_algorithm) const;
check_digest_t cd_dg = &httpserver::http_request::check_digest_auth_digest;
(void)cd_dg;
}
// Prove use_ssl/basic_auth/digest_auth are declared unconditionally via
// member-function-pointer address-taking (no runtime invocation needed).
// Also touch each TLS credential-material setter with a no-op value so any
// future HAVE_GNUTLS guard regression is caught by the CI gate.
void touch_create_webserver_setters() {
using cw_setter = httpserver::create_webserver& (
httpserver::create_webserver::*)(bool);
cw_setter s_ssl = &httpserver::create_webserver::use_ssl;
cw_setter s_bauth = &httpserver::create_webserver::basic_auth;
cw_setter s_dauth = &httpserver::create_webserver::digest_auth;
(void)s_ssl;
(void)s_bauth;
(void)s_dauth;
// TLS credential-material setters -- always unconditional.
httpserver::create_webserver cw{8080};
cw.raw_https_mem_key("");
cw.raw_https_mem_cert("");
cw.raw_https_mem_trust("");
cw.https_priorities("");
cw.https_mem_dhparams("");
cw.cred_type(httpserver::http::http_utils::NONE);
cw.psk_cred_handler([](const std::string&) { return std::string{}; });
(void)cw;
}
void touch_features() {
auto f = httpserver::webserver::features();
(void)f.basic_auth;
(void)f.digest_auth;
(void)f.tls;
(void)f.websocket;
}
void touch_ws(httpserver::webserver& ws) {
// Exercise all three websocket-resource public entry points. On
// HAVE_WEBSOCKET-off builds each throws feature_unavailable; on
// HAVE_WEBSOCKET-on builds the smart-ptr overloads throw
// std::invalid_argument on the null inputs (and unregister_ws_resource
// is a no-op on a missing path). Either way, the call sites must
// compile, which is the whole point of this consumer-fixture TU.
try {
ws.register_ws_resource(
"/ws", std::unique_ptr<httpserver::websocket_handler>{});
} catch (...) {
}
try {
ws.register_ws_resource(
"/ws", std::shared_ptr<httpserver::websocket_handler>{});
} catch (...) {
}
try {
ws.unregister_ws_resource("/ws");
} catch (...) {
}
}
httpserver::http_request build_test_req() {
return httpserver::create_test_request()
.user("alice").pass("s3cret") // was #ifdef HAVE_BAUTH
.digested_user("alice") // was #ifdef HAVE_DAUTH
.tls_enabled(true) // was #ifdef HAVE_GNUTLS
.build();
}
} // namespace fixture
int main() {
(void)&fixture::build_server;
(void)&fixture::touch_request_accessors;
(void)&fixture::touch_features;
(void)&fixture::touch_ws;
(void)&fixture::build_test_req;
(void)&fixture::touch_create_webserver_setters;
return 0;
}