@@ -21,10 +21,10 @@ static std::string serverPubKeyPath;
2121static std::string clientKeyPath;
2222static std::string clientCertPath;
2323
24- std::string loadCertificateFromFile (const std::string certPath ) {
25- std::ifstream certFile (certPath );
24+ std::string loadFileContent (const std::string filePath ) {
25+ std::ifstream file (filePath );
2626 std::stringstream buffer;
27- buffer << certFile .rdbuf ();
27+ buffer << file .rdbuf ();
2828 return buffer.str ();
2929}
3030
@@ -147,7 +147,7 @@ TEST(SslTests, LoadCertFromBufferTestSimpel) {
147147 std::string baseDirPath{server->getBaseDirPath ()};
148148 std::string crtPath{baseDirPath + " certificates/" };
149149 std::string keyPath{baseDirPath + " keys/" };
150- std::string certBuffer = loadCertificateFromFile (crtPath + " ca-bundle.crt" );
150+ std::string certBuffer = loadFileContent (crtPath + " ca-bundle.crt" );
151151 SslOptions sslOpts = Ssl (ssl::CaBuffer{std::move (certBuffer)}, ssl::CertFile{crtPath + " client.crt" }, ssl::KeyFile{keyPath + " client.key" }, ssl::VerifyPeer{true }, ssl::VerifyHost{true }, ssl::VerifyStatus{false });
152152 Response response = cpr::Get (url, sslOpts, Timeout{5000 }, Verbose{});
153153 std::string expected_text = " Hello world!" ;
@@ -159,6 +159,27 @@ TEST(SslTests, LoadCertFromBufferTestSimpel) {
159159}
160160#endif
161161
162+ #if SUPPORT_CURLOPT_SSLKEY_BLOB
163+ TEST (SslTests, LoadKeyFromBlobTestSimpel) {
164+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
165+
166+ Url url{server->GetBaseUrl () + " /hello.html" };
167+
168+ std::string baseDirPath{server->getBaseDirPath ()};
169+ std::string crtPath{baseDirPath + " certificates/" };
170+ std::string keyPath{baseDirPath + " keys/" };
171+ std::string keyBuffer = loadFileContent (keyPath + " client.key" );
172+ SslOptions sslOpts = Ssl (ssl::CaInfo{crtPath + " ca-bundle.crt" }, ssl::CertFile{crtPath + " client.crt" }, ssl::KeyBlob{std::move (keyBuffer)}, ssl::VerifyPeer{true }, ssl::VerifyHost{true }, ssl::VerifyStatus{false });
173+ Response response = cpr::Get (url, sslOpts, Timeout{5000 }, Verbose{});
174+ std::string expected_text = " Hello world!" ;
175+ EXPECT_EQ (expected_text, response.text );
176+ EXPECT_EQ (url, response.url );
177+ EXPECT_EQ (std::string{" text/html" }, response.header [" content-type" ]);
178+ EXPECT_EQ (200 , response.status_code );
179+ EXPECT_EQ (ErrorCode::OK, response.error .code ) << response.error .message ;
180+ }
181+ #endif
182+
162183fs::path GetBasePath (const std::string& execPath) {
163184 return fs::path (fs::path{execPath}.parent_path ().string () + " /" ).make_preferred ();
164185}
0 commit comments