Skip to content

Commit 88242f3

Browse files
authored
Make the CAPath option available on all OSes and change to throw on runtime on non-linux. (Azure#5207)
* Make the CAPath option available on all OSes and change to throw on runtime on non-linux. * Address PR feedback, update test, and let curl fail on unsupported platforms.
1 parent 7eeb609 commit 88242f3

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

sdk/core/azure-core/inc/azure/core/http/curl_transport.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ namespace Azure { namespace Core { namespace Http {
123123
*/
124124
std::string CAInfo;
125125

126-
#if defined(AZ_PLATFORM_LINUX)
127126
/**
128127
* @brief Path to a directory which holds PEM encoded file, containing the certificate
129128
* authorities sent to libcurl handle directly.
@@ -135,7 +134,6 @@ namespace Azure { namespace Core { namespace Http {
135134
*
136135
*/
137136
std::string CAPath;
138-
#endif
139137

140138
/**
141139
* @brief All HTTP requests will keep the connection channel open to the service.

sdk/core/azure-core/src/http/curl/curl.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,11 +1283,7 @@ inline std::string GetConnectionKey(std::string const& host, CurlTransportOption
12831283
key.append(",");
12841284
key.append(!options.CAInfo.empty() ? options.CAInfo : "0");
12851285
key.append(",");
1286-
#if defined(AZ_PLATFORM_LINUX)
12871286
key.append(!options.CAPath.empty() ? options.CAPath : "0");
1288-
#else
1289-
key.append("0"); // CAPath is always empty on Windows;
1290-
#endif
12911287
key.append(",");
12921288
key.append(
12931289
options.Proxy.HasValue() ? (options.Proxy.Value().empty() ? "NoProxy" : options.Proxy.Value())
@@ -2320,7 +2316,6 @@ CurlConnection::CurlConnection(
23202316
}
23212317
}
23222318

2323-
#if defined(AZ_PLATFORM_LINUX)
23242319
if (!options.CAPath.empty())
23252320
{
23262321
if (!SetLibcurlOption(m_handle, CURLOPT_CAPATH, options.CAPath.c_str(), &result))
@@ -2331,7 +2326,6 @@ CurlConnection::CurlConnection(
23312326
+ std::string(curl_easy_strerror(result)));
23322327
}
23332328
}
2334-
#endif
23352329

23362330
#if LIBCURL_VERSION_NUM >= 0x074D00 // 7.77.0
23372331
if (!options.SslOptions.PemEncodedExpectedRootCertificates.empty())

sdk/core/azure-core/test/ut/curl_options_test.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ namespace Azure { namespace Core { namespace Test {
235235
.ConnectionPoolIndex.clear());
236236
}
237237

238-
#if defined(AZ_PLATFORM_LINUX)
239238
TEST(CurlTransportOptions, setCADirectory)
240239
{
241240
Azure::Core::Http::CurlTransportOptions curlOptions;
241+
#if defined(AZ_PLATFORM_LINUX)
242242
// openssl default cert location will be used only if environment variable SSL_CERT_DIR
243243
// is not set
244244
const char* ca = getenv(X509_get_default_cert_dir_env());
@@ -250,6 +250,9 @@ namespace Azure { namespace Core { namespace Test {
250250
{
251251
curlOptions.CAPath = X509_get_default_cert_dir();
252252
}
253+
#else
254+
curlOptions.CAPath = "UnsupportedPathOnWindows";
255+
#endif
253256

254257
auto transportAdapter = std::make_shared<Azure::Core::Http::CurlTransport>(curlOptions);
255258
Azure::Core::Http::Policies::TransportOptions options;
@@ -265,6 +268,7 @@ namespace Azure { namespace Core { namespace Test {
265268
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
266269
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
267270

271+
#if defined(AZ_PLATFORM_LINUX)
268272
std::unique_ptr<Azure::Core::Http::RawResponse> response;
269273
EXPECT_NO_THROW(response = pipeline.Send(request, Azure::Core::Context::ApplicationContext));
270274
EXPECT_EQ(response->GetStatusCode(), Azure::Core::Http::HttpStatusCode::Ok);
@@ -273,8 +277,24 @@ namespace Azure { namespace Core { namespace Test {
273277
// app-destruction
274278
EXPECT_NO_THROW(Azure::Core::Http::_detail::CurlConnectionPool::g_curlConnectionPool
275279
.ConnectionPoolIndex.clear());
276-
}
280+
#else
281+
EXPECT_THROW(
282+
pipeline.Send(request, Azure::Core::Context::ApplicationContext),
283+
Azure::Core::Http::TransportException);
284+
try
285+
{
286+
pipeline.Send(request, Azure::Core::Context::ApplicationContext);
287+
}
288+
catch (Azure::Core::Http::TransportException& e)
289+
{
290+
EXPECT_TRUE(
291+
std::string(e.what()).find(
292+
"A requested feature, protocol or option was not found built-in "
293+
"in this libcurl due to a build-time decision.")
294+
!= std::string::npos);
295+
}
277296
#endif
297+
}
278298

279299
TEST(CurlTransportOptions, httpsDefault)
280300
{

0 commit comments

Comments
 (0)