Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
503215a
Changed one line
LarryOsterman Feb 19, 2022
639af2d
Set WinHTTP_OPTION_CLIENT_CERT_CONTEXT to enable connections to attes…
LarryOsterman Feb 22, 2022
b548635
Map service specific CLIENT_ID, CLIENT_SECRET, and TENANT_ID to AZURE…
LarryOsterman Feb 22, 2022
f82904f
clang-format
LarryOsterman Feb 22, 2022
fc1a481
clang-format again
LarryOsterman Feb 22, 2022
9c3966a
Only set TLS options if we request TLS
LarryOsterman Feb 22, 2022
48e5ce5
Fixed uninitialized variable problem in storage
LarryOsterman Feb 23, 2022
4982f12
Compilation issues
LarryOsterman Feb 23, 2022
eb80057
Pull request feedback
LarryOsterman Feb 23, 2022
cc7f426
Renamed serviceName parameter to match the parameter to new-testresou…
LarryOsterman Feb 23, 2022
304f92e
Don't set environment variables if they're already set
LarryOsterman Feb 23, 2022
d51d09c
clang-format
LarryOsterman Feb 23, 2022
9fe931e
Set serviceDirectory from environment variables
LarryOsterman Feb 23, 2022
565f60c
@#$@# clang-format
LarryOsterman Feb 24, 2022
fb5a4b3
backed out inadvertant change to cmakelists.txt in azure-core\test
LarryOsterman Feb 24, 2022
07c1f22
Further updates to reduce code churn
LarryOsterman Feb 24, 2022
303dd5e
Added AZURE_SERVICE_DIRECTORY to CI test invocation
LarryOsterman Feb 24, 2022
119e2b3
Fixed missing $
LarryOsterman Feb 24, 2022
62916f0
Dump environment variables during tests
LarryOsterman Feb 24, 2022
31dbac0
Upper case serviceDirectory; clarified exception message to make it m…
LarryOsterman Feb 24, 2022
4689bb2
Moved AZURE_SERVICE_DIRECTORY definition from ctest step to variables
LarryOsterman Feb 24, 2022
8c79c6e
Fixed thumbprint generation to use correct buffer - fixes rare crash …
LarryOsterman Feb 24, 2022
03eedca
Explain purpose of AZURE_SERVICE_DIRECTORY environment variable in ar…
LarryOsterman Feb 24, 2022
731fb3c
Small readme update
LarryOsterman Feb 24, 2022
514f25d
Move AZURE_SERVICE_DIRECTORY check to getenv
LarryOsterman Feb 24, 2022
2eb1782
clang_format
LarryOsterman Feb 24, 2022
7f8c322
Comment cleanup
LarryOsterman Feb 24, 2022
b889020
Declare requestSecureHttp as const
LarryOsterman Feb 24, 2022
7349047
Pull request feedback
LarryOsterman Feb 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/attestation/azure-security-attestation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,4 @@ Azure SDK for C++ is licensed under the [MIT](https://github.com/Azure/azure-sdk
[cloud_shell_bash]: https://shell.azure.com/bash

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-cpp%2Fsdk%2Fattestation%2Fazure-security-attestation%2FREADME.png)

Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ namespace Azure { namespace Security { namespace Attestation { namespace _detail
ValidateTokenIssuer(validationOptions);
}

operator Models::AttestationToken<T>&&() { return std::move(m_token); }
/**
* @brief Convert the internal attestation token to a public AttestationToken object.
*/
operator Models::AttestationToken<T>&() { return m_token; }
};
}}}} // namespace Azure::Security::Attestation::_detail
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace Azure { namespace Security { namespace Attestation { namespace Test {
// Create
virtual void SetUp() override
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
Azure::Core::Test::TestBase::SetUpTestBase("ATTESTATION", AZURE_TEST_RECORDING_DIR);

std::string const mode(std::get<0>(GetParam()));
if (mode == "Shared")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Azure { namespace Security { namespace Attestation { namespace Test {
// Create
virtual void SetUp() override
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
Azure::Core::Test::TestBase::SetUpTestBase("ATTESTATION", AZURE_TEST_RECORDING_DIR);

std::string mode(GetParam());
if (mode == "Shared")
Expand Down
47 changes: 43 additions & 4 deletions sdk/core/azure-core-test/inc/azure/core/test/test_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "azure/core/test/network_models.hpp"
#include "azure/core/test/test_context_manager.hpp"

#include <algorithm>
#include <chrono>
#include <memory>
#include <regex>
Expand Down Expand Up @@ -45,6 +46,7 @@ namespace Azure { namespace Core { namespace Test {
*
*/
bool m_wasSkipped = false;
std::string m_serviceName{};

void PrepareOptions(Azure::Core::_internal::ClientOptions& options)
{
Expand Down Expand Up @@ -244,10 +246,26 @@ namespace Azure { namespace Core { namespace Test {
}

// Util for tests getting env vars
std::string GetEnv(const std::string& name)
std::string GetEnv(std::string const& name)
{
const auto ret = Azure::Core::_internal::Environment::GetVariable(name.c_str());

#if !defined(NDEBUG)
// The azure CI pipeline uppercases all EnvVar values from ci.yml files.
// That means that any mixed case strings will not be found when run from the CI
// pipeline.
//
// Check to ensure that the filename is upper case
{
std::string ucName = name;
std::transform(ucName.begin(), ucName.end(), ucName.begin(), [](char const& ch) {
return static_cast<char>(std::toupper(ch));
});
if (ucName != name)
{
throw std::runtime_error("All Azure SDK environment variables must be all upper case.");
Comment thread
LarryOsterman marked this conversation as resolved.
}
Comment thread
LarryOsterman marked this conversation as resolved.
Outdated
}
#endif
auto ret = Azure::Core::_internal::Environment::GetVariable(name.c_str());
if (ret.empty())
{
throw std::runtime_error("Missing required environment variable: " + name);
Expand All @@ -262,8 +280,11 @@ namespace Azure { namespace Core { namespace Test {
* @brief Run before each test.
*
*/
void SetUpTestBase(std::string const& baseRecordingPath)
void SetUpTestBase(std::string const& serviceName, std::string const& baseRecordingPath)
Comment thread
LarryOsterman marked this conversation as resolved.
Outdated
{

m_serviceName = serviceName;

// Init interceptor from PlayBackRecorder
std::string recordingPath(baseRecordingPath);
recordingPath.append("/recordings");
Expand All @@ -276,6 +297,24 @@ namespace Azure { namespace Core { namespace Test {
Sanitize(testNameInfo->test_suite_name()), Sanitize(testNameInfo->name()));
m_testContext.RecordingPath = recordingPath;
m_interceptor = std::make_unique<Azure::Core::Test::InterceptorManager>(m_testContext);

if (!m_testContext.IsPlaybackMode())
{
auto SetBuiltinEnvironment
= [](std::string const& serviceName, std::string const& targetVariable) {
std::string targetValue = Azure::Core::_internal::Environment::GetVariable(
(serviceName + targetVariable).c_str());
Comment thread
LarryOsterman marked this conversation as resolved.
Outdated
if (!targetValue.empty())
{
Azure::Core::_internal::Environment::SetVariable(
("AZURE" + targetVariable).c_str(), targetValue.c_str());
}
};
;
SetBuiltinEnvironment(serviceName, "_TENANT_ID");
SetBuiltinEnvironment(serviceName, "_CLIENT_ID");
SetBuiltinEnvironment(serviceName, "_CLIENT_SECRET");
}
}

/**
Expand Down
25 changes: 21 additions & 4 deletions sdk/core/azure-core/src/http/winhttp/win_http_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ void WinHttpTransport::CreateRequestHandle(std::unique_ptr<_detail::HandleManage
{
const std::string& path = handleManager->m_request.GetUrl().GetRelativeUrl();
HttpMethod requestMethod = handleManager->m_request.GetMethod();
bool requestSecureHttp(
Comment thread
LarryOsterman marked this conversation as resolved.
Outdated
!Azure::Core::_internal::StringExtensions::LocaleInvariantCaseInsensitiveEqual(
handleManager->m_request.GetUrl().GetScheme(), HttpScheme));

// Create an HTTP request handle.
handleManager->m_requestHandle = WinHttpOpenRequest(
Expand All @@ -314,10 +317,7 @@ void WinHttpTransport::CreateRequestHandle(std::unique_ptr<_detail::HandleManage
NULL, // Use HTTP/1.1
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, // No media types are accepted by the client
Azure::Core::_internal::StringExtensions::LocaleInvariantCaseInsensitiveEqual(
handleManager->m_request.GetUrl().GetScheme(), HttpScheme)
? 0
: WINHTTP_FLAG_SECURE); // Uses secure transaction semantics (SSL/TLS)
requestSecureHttp ? WINHTTP_FLAG_SECURE : 0); // Uses secure transaction semantics (SSL/TLS)

if (!handleManager->m_requestHandle)
{
Expand All @@ -330,6 +330,23 @@ void WinHttpTransport::CreateRequestHandle(std::unique_ptr<_detail::HandleManage
// ERROR_NOT_ENOUGH_MEMORY
GetErrorAndThrow("Error while getting a request handle.");
}

if (requestSecureHttp)
{
// If the service requests TLS client certificates, we want to let the WinHTTP APIs know that
// it's ok to initiate the request without a client certificate.
//
// Note: If/When TLS client certificate support is added to the pipeline, this line may need to
// be revisited.
if (!WinHttpSetOption(
handleManager->m_requestHandle,
WINHTTP_OPTION_CLIENT_CERT_CONTEXT,
WINHTTP_NO_CLIENT_CERT_CONTEXT,
0))
{
GetErrorAndThrow("Error while setting client cert context to ignore..");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Extra period

Suggested change
GetErrorAndThrow("Error while setting client cert context to ignore..");
GetErrorAndThrow("Error while setting client cert context to ignore.");

}
}
}

// For PUT/POST requests, send additional data using WinHttpWriteData.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace Azure { namespace Identity { namespace Test {
// Runs before every test.
virtual void SetUp() override
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
Azure::Core::Test::TestBase::SetUpTestBase("IDENTITY", AZURE_TEST_RECORDING_DIR);
}
};
}}} // namespace Azure::Identity::Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace Azure {
// Runs before every test.
virtual void SetUp() override
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
Azure::Core::Test::TestBase::SetUpTestBase("KEYVAULT", AZURE_TEST_RECORDING_DIR);
m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL");

// Options and credential for the client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { nam
// Create
virtual void SetUp() override
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
Azure::Core::Test::TestBase::SetUpTestBase("KEYVAULT", AZURE_TEST_RECORDING_DIR);
m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL");
m_keyVaultHsmUrl = GetEnv("AZURE_KEYVAULT_HSM_URL");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Secrets {
// Create
void InitializeClient()
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
Azure::Core::Test::TestBase::SetUpTestBase("KEYVAULT", AZURE_TEST_RECORDING_DIR);
m_keyVaultUrl = GetEnv("AZURE_KEYVAULT_URL");

// Options and credential for the client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ namespace Azure { namespace Storage { namespace Test {

TEST_P(DownloadBlockBlob, downloadToBuffer)
{
auto const p = GetParam();
BlobConcurrentDownloadParameter const& p(GetParam());
auto const testName(GetTestName(true));
auto client = GetBlockBlobClient(testName);
UploadBlockBlob(8_MB);
Expand Down Expand Up @@ -773,7 +773,7 @@ namespace Azure { namespace Storage { namespace Test {

TEST_P(DownloadBlockBlob, downloadToFile)
{
auto const p = GetParam();
BlobConcurrentDownloadParameter const& p(GetParam());
auto const testName(GetTestName(true));
auto client = GetBlockBlobClient(testName);
UploadBlockBlob(8_MB);
Expand Down Expand Up @@ -1191,7 +1191,7 @@ namespace Azure { namespace Storage { namespace Test {
auto const testName(GetTestName());
auto blockBlobClient = GetBlockBlobClient(testName);
SetOptions();
auto const p = GetParam();
UploadBlockBlob::ParamType const& p(GetParam());
auto const blobSize = p.Size;
std::vector<uint8_t> blobContent(static_cast<size_t>(8_MB), 'x');

Expand Down Expand Up @@ -1227,7 +1227,7 @@ namespace Azure { namespace Storage { namespace Test {
auto const testName(GetTestName());
auto blockBlobClient = GetBlockBlobClient(testName);
SetOptions();
auto const p = GetParam();
UploadBlockBlob::ParamType const& p(GetParam());
auto const blobSize = p.Size;
std::vector<uint8_t> blobContent(static_cast<size_t>(8_MB), 'x');

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/azure-storage-common/test/ut/test_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ namespace Azure { namespace Storage {

virtual void SetUp() override
{
Azure::Core::Test::TestBase::SetUpTestBase(AZURE_TEST_RECORDING_DIR);
Azure::Core::Test::TestBase::SetUpTestBase("STORAGE", AZURE_TEST_RECORDING_DIR);
}

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ namespace Azure { namespace Storage { namespace Test {

TEST_P(UploadFile, fromBuffer)
{
auto const p = GetParam();
UploadFile::ParamType const& p(GetParam());
std::vector<uint8_t> fileContent(static_cast<size_t>(8_MB), 'x');
auto fileClient = m_fileSystemClient->GetFileClient(GetTestNameLowerCase());

Expand Down Expand Up @@ -461,7 +461,7 @@ namespace Azure { namespace Storage { namespace Test {

TEST_P(UploadFile, fromFile)
{
auto const p = GetParam();
UploadFile::ParamType const& p(GetParam());
std::vector<uint8_t> fileContent(static_cast<size_t>(8_MB), 'x');
auto fileClient = m_fileSystemClient->GetFileClient(GetTestNameLowerCase());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace Azure { namespace Storage { namespace Test {

TEST_P(UploadShare, fromBuffer)
{
auto const p = GetParam();
UploadShare::ParamType const& p(GetParam());
auto fileClient = m_fileShareDirectoryClient->GetFileClient(m_testName);
std::vector<uint8_t> fileContent(static_cast<size_t>(p.FileSize), 'x');

Expand All @@ -418,7 +418,7 @@ namespace Azure { namespace Storage { namespace Test {
TEST_P(UploadShare, fromFile)
{

auto const p = GetParam();
UploadShare::ParamType const& p(GetParam());
auto fileClient = m_fileShareDirectoryClient->GetFileClient(m_testName);
std::vector<uint8_t> fileContent = std::vector<uint8_t>(static_cast<size_t>(p.FileSize), 'x');

Expand Down