Make the CAPath option available on all OSes and change to throw on runtime on non-linux. (#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.
This commit is contained in:
parent
7eeb60960c
commit
88242f3cf1
@ -123,7 +123,6 @@ namespace Azure { namespace Core { namespace Http {
|
||||
*/
|
||||
std::string CAInfo;
|
||||
|
||||
#if defined(AZ_PLATFORM_LINUX)
|
||||
/**
|
||||
* @brief Path to a directory which holds PEM encoded file, containing the certificate
|
||||
* authorities sent to libcurl handle directly.
|
||||
@ -135,7 +134,6 @@ namespace Azure { namespace Core { namespace Http {
|
||||
*
|
||||
*/
|
||||
std::string CAPath;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief All HTTP requests will keep the connection channel open to the service.
|
||||
|
||||
@ -1283,11 +1283,7 @@ inline std::string GetConnectionKey(std::string const& host, CurlTransportOption
|
||||
key.append(",");
|
||||
key.append(!options.CAInfo.empty() ? options.CAInfo : "0");
|
||||
key.append(",");
|
||||
#if defined(AZ_PLATFORM_LINUX)
|
||||
key.append(!options.CAPath.empty() ? options.CAPath : "0");
|
||||
#else
|
||||
key.append("0"); // CAPath is always empty on Windows;
|
||||
#endif
|
||||
key.append(",");
|
||||
key.append(
|
||||
options.Proxy.HasValue() ? (options.Proxy.Value().empty() ? "NoProxy" : options.Proxy.Value())
|
||||
@ -2320,7 +2316,6 @@ CurlConnection::CurlConnection(
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(AZ_PLATFORM_LINUX)
|
||||
if (!options.CAPath.empty())
|
||||
{
|
||||
if (!SetLibcurlOption(m_handle, CURLOPT_CAPATH, options.CAPath.c_str(), &result))
|
||||
@ -2331,7 +2326,6 @@ CurlConnection::CurlConnection(
|
||||
+ std::string(curl_easy_strerror(result)));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LIBCURL_VERSION_NUM >= 0x074D00 // 7.77.0
|
||||
if (!options.SslOptions.PemEncodedExpectedRootCertificates.empty())
|
||||
|
||||
@ -235,10 +235,10 @@ namespace Azure { namespace Core { namespace Test {
|
||||
.ConnectionPoolIndex.clear());
|
||||
}
|
||||
|
||||
#if defined(AZ_PLATFORM_LINUX)
|
||||
TEST(CurlTransportOptions, setCADirectory)
|
||||
{
|
||||
Azure::Core::Http::CurlTransportOptions curlOptions;
|
||||
#if defined(AZ_PLATFORM_LINUX)
|
||||
// openssl default cert location will be used only if environment variable SSL_CERT_DIR
|
||||
// is not set
|
||||
const char* ca = getenv(X509_get_default_cert_dir_env());
|
||||
@ -250,6 +250,9 @@ namespace Azure { namespace Core { namespace Test {
|
||||
{
|
||||
curlOptions.CAPath = X509_get_default_cert_dir();
|
||||
}
|
||||
#else
|
||||
curlOptions.CAPath = "UnsupportedPathOnWindows";
|
||||
#endif
|
||||
|
||||
auto transportAdapter = std::make_shared<Azure::Core::Http::CurlTransport>(curlOptions);
|
||||
Azure::Core::Http::Policies::TransportOptions options;
|
||||
@ -265,6 +268,7 @@ namespace Azure { namespace Core { namespace Test {
|
||||
Azure::Core::Url url(AzureSdkHttpbinServer::Get());
|
||||
Azure::Core::Http::Request request(Azure::Core::Http::HttpMethod::Get, url);
|
||||
|
||||
#if defined(AZ_PLATFORM_LINUX)
|
||||
std::unique_ptr<Azure::Core::Http::RawResponse> response;
|
||||
EXPECT_NO_THROW(response = pipeline.Send(request, Azure::Core::Context::ApplicationContext));
|
||||
EXPECT_EQ(response->GetStatusCode(), Azure::Core::Http::HttpStatusCode::Ok);
|
||||
@ -273,8 +277,24 @@ namespace Azure { namespace Core { namespace Test {
|
||||
// app-destruction
|
||||
EXPECT_NO_THROW(Azure::Core::Http::_detail::CurlConnectionPool::g_curlConnectionPool
|
||||
.ConnectionPoolIndex.clear());
|
||||
}
|
||||
#else
|
||||
EXPECT_THROW(
|
||||
pipeline.Send(request, Azure::Core::Context::ApplicationContext),
|
||||
Azure::Core::Http::TransportException);
|
||||
try
|
||||
{
|
||||
pipeline.Send(request, Azure::Core::Context::ApplicationContext);
|
||||
}
|
||||
catch (Azure::Core::Http::TransportException& e)
|
||||
{
|
||||
EXPECT_TRUE(
|
||||
std::string(e.what()).find(
|
||||
"A requested feature, protocol or option was not found built-in "
|
||||
"in this libcurl due to a build-time decision.")
|
||||
!= std::string::npos);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(CurlTransportOptions, httpsDefault)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user