Repository navigation
Expand file tree
/
Copy pathtest_ca_store.cpp
More file actions
42 lines (35 loc) · 1.55 KB
/
Copy pathtest_ca_store.cpp
File metadata and controls
42 lines (35 loc) · 1.55 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
// The trust store the platform supplies is found with nothing configured, and a
// public certificate chain verifies against it.
//
// On a Windows Sockets build the store is the system's ROOT store, read through
// the Win32 API; elsewhere it is a bundle file at one of the known locations.
// Either way a default-constructed client verifies a public server. A host that
// cannot be reached is a skip, so a runner without egress reports "not run"; a
// certificate the client refused is a failure.
#include <gtest/gtest.h>
#include <cstdlib>
import mcpplibs.tinyhttps;
import std;
namespace https = mcpplibs::tinyhttps;
TEST(SystemStore, IsFoundWithNothingConfigured) {
if (const char* file = std::getenv("SSL_CERT_FILE"); file && *file) {
GTEST_SKIP() << "SSL_CERT_FILE is set, so the system store is not consulted";
}
const auto pem = https::load_ca_certs();
EXPECT_FALSE(pem.empty());
EXPECT_NE(pem.find("-----BEGIN CERTIFICATE-----"), std::string::npos);
}
TEST(SystemStore, APublicChainVerifiesAgainstIt) {
https::Socket::platform_init();
https::HttpClientConfig config;
config.connectTimeoutMs = 15000;
config.readTimeoutMs = 20000;
https::HttpClient client{config};
https::HttpRequest request;
request.url = "https://one.one.one.one/";
const auto response = client.send(request);
if (response.statusCode == 0 && response.statusText == "Connection failed") {
GTEST_SKIP() << "one.one.one.one is not reachable from this runner";
}
EXPECT_NE(response.statusCode, 0) << response.statusText;
}