fsdfs
This commit is contained in:
parent
e339e71c74
commit
f0ebdcb2e0
@ -83,6 +83,7 @@ namespace Azure { namespace Core { namespace Test {
|
||||
Azure::Core::Http::_internal::HttpPipeline pipeline(
|
||||
clientOp, "PerfFw", "na", std::move(policiesRe), std::move(policiesOp));
|
||||
m_privatePipeline = std::make_unique<Azure::Core::Http::_internal::HttpPipeline>(pipeline);
|
||||
void SetProxySanitizer();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -153,6 +154,7 @@ namespace Azure { namespace Core { namespace Test {
|
||||
|
||||
private:
|
||||
std::string PrepareRequestBody();
|
||||
void SetProxySanitizer();
|
||||
bool CheckSanitizers();
|
||||
};
|
||||
|
||||
|
||||
@ -188,3 +188,146 @@ bool TestProxyManager::CheckSanitizers()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestProxyManager::SetProxySanitizer()
|
||||
{
|
||||
if (CheckSanitizers())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// we have 3 types of sanitizer,
|
||||
// see
|
||||
// https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md#a-note-about-where-sanitizers-apply
|
||||
enum class SanitizerType
|
||||
{
|
||||
Uri,
|
||||
Header,
|
||||
Body,
|
||||
General,
|
||||
};
|
||||
auto addSanitizer = [&](SanitizerType type,
|
||||
const std::string& regex,
|
||||
const std::string& groupName,
|
||||
const std::string& headerName = std::string()) {
|
||||
const std::map<SanitizerType, std::string> abstractionIdentifierValues = {
|
||||
{SanitizerType::Uri, "UriRegexSanitizer"},
|
||||
{SanitizerType::Header, "HeaderRegexSanitizer"},
|
||||
{SanitizerType::Body, "BodyRegexSanitizer"},
|
||||
{SanitizerType::General, "GeneralRegexSanitizer"},
|
||||
};
|
||||
|
||||
Azure::Core::Url sanitizerRequest(m_proxy);
|
||||
sanitizerRequest.AppendPath("Admin");
|
||||
sanitizerRequest.AppendPath("AddSanitizer");
|
||||
|
||||
auto jsonRoot = Json::_internal::json::object();
|
||||
jsonRoot["value"] = "REDACTED";
|
||||
jsonRoot["regex"] = regex;
|
||||
jsonRoot["groupForReplace"] = groupName;
|
||||
if (!headerName.empty())
|
||||
{
|
||||
jsonRoot["key"] = headerName;
|
||||
}
|
||||
auto jsonString = jsonRoot.dump();
|
||||
|
||||
Azure::Core::IO::MemoryBodyStream payloadStream(
|
||||
reinterpret_cast<const uint8_t*>(jsonString.data()), jsonString.size());
|
||||
Azure::Core::Http::Request request(
|
||||
Azure::Core::Http::HttpMethod::Post, sanitizerRequest, &payloadStream);
|
||||
request.SetHeader("x-abstraction-identifier", abstractionIdentifierValues.at(type));
|
||||
Azure::Core::Context ctx;
|
||||
auto response = m_privatePipeline->Send(request, ctx);
|
||||
(void)response;
|
||||
};
|
||||
|
||||
addSanitizer(SanitizerType::General, g_accountRegex, "account");
|
||||
addSanitizer(SanitizerType::Body, "client_secret=(?<clientsecret>[^&]+)", "clientsecret");
|
||||
addSanitizer(SanitizerType::Body, "client_id=(?<clientid>[^&]+)", "clientid");
|
||||
addSanitizer(
|
||||
SanitizerType::Body,
|
||||
"(?<=<UserDelegationKey>).*?(?:<SignedTid>)(.*)(?:</SignedTid>)",
|
||||
"signedtid");
|
||||
addSanitizer(
|
||||
SanitizerType::Body,
|
||||
"(?<=<UserDelegationKey>).*?(?:<SignedOid>)(.*)(?:</SignedOid>)",
|
||||
"signedoid");
|
||||
const std::string storageSasSignatureRegex = "\\?.*sig=(?<sassig>[a-zA-Z0-9\\%\\/+=]+)";
|
||||
addSanitizer(SanitizerType::Uri, storageSasSignatureRegex, "sassig");
|
||||
addSanitizer(SanitizerType::Header, storageSasSignatureRegex, "sassig", "x-ms-copy-source");
|
||||
addSanitizer(SanitizerType::Header, storageSasSignatureRegex, "sassig", "x-ms-rename-source");
|
||||
addSanitizer(SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-copy-source-authorization");
|
||||
addSanitizer(SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-encryption-key");
|
||||
addSanitizer(SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-rename-source");
|
||||
addSanitizer(SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-file-rename-source");
|
||||
addSanitizer(SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-copy-source");
|
||||
addSanitizer(SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-copy-source-authorization");
|
||||
addSanitizer(
|
||||
SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-file-rename-source-authorization");
|
||||
addSanitizer(SanitizerType::Header, "(?<auth>.+)", "auth", "x-ms-encryption-key-sha256");
|
||||
addSanitizer(SanitizerType::Header, "(?<cookie>.+)", "cookie", "Cookie");
|
||||
addSanitizer(SanitizerType::Header, "(?<cookie>.+)", "cookie", "Set-Cookie");
|
||||
const std::string storageUserDelegationKeyRegex
|
||||
= "\\u003CValue\\u003E(?<userdelegationkey>[a-zA-Z0-9\\/=+]+).*\\u003C\\/"
|
||||
"UserDelegationKey\\u003E";
|
||||
addSanitizer(SanitizerType::Body, storageUserDelegationKeyRegex, "userdelegationkey");
|
||||
|
||||
Azure::Core::Url matcherRequest(m_proxy);
|
||||
matcherRequest.AppendPath("Admin");
|
||||
matcherRequest.AppendPath("SetMatcher");
|
||||
std::string matcherBody;
|
||||
{
|
||||
auto jsonRoot = Json::_internal::json::object();
|
||||
jsonRoot["compareBodies"] = false;
|
||||
jsonRoot["ignoreQueryOrdering"] = true;
|
||||
const std::vector<std::string> excludedHeaders = {
|
||||
"Expect",
|
||||
"Connection",
|
||||
"Cookie",
|
||||
};
|
||||
jsonRoot["excludedHeaders"] = std::accumulate(
|
||||
excludedHeaders.begin(),
|
||||
excludedHeaders.end(),
|
||||
std::string(),
|
||||
[](const std::string& lhs, const std::string& rhs) {
|
||||
return lhs + (lhs.empty() ? "" : ",") + rhs;
|
||||
});
|
||||
const std::vector<std::string> ignoredHeaders = {
|
||||
"x-ms-copy-source",
|
||||
"x-ms-file-change-time",
|
||||
"x-ms-file-creation-time",
|
||||
"x-ms-file-last-write-time",
|
||||
"x-ms-rename-source",
|
||||
"x-ms-immutability-policy-until-date",
|
||||
};
|
||||
const std::vector<std::string> ignoreQueryParameters = {
|
||||
"st",
|
||||
"se",
|
||||
"sig",
|
||||
"sv",
|
||||
};
|
||||
jsonRoot["ignoredHeaders"] = std::accumulate(
|
||||
ignoredHeaders.begin(),
|
||||
ignoredHeaders.end(),
|
||||
std::string(),
|
||||
[](const std::string& lhs, const std::string& rhs) {
|
||||
return lhs + (lhs.empty() ? "" : ",") + rhs;
|
||||
});
|
||||
jsonRoot["ignoredQueryParameters"] = std::accumulate(
|
||||
ignoreQueryParameters.begin(),
|
||||
ignoreQueryParameters.end(),
|
||||
std::string(),
|
||||
[](const std::string& lhs, const std::string& rhs) {
|
||||
return lhs + (lhs.empty() ? "" : ",") + rhs;
|
||||
});
|
||||
matcherBody = jsonRoot.dump();
|
||||
}
|
||||
{
|
||||
Azure::Core::IO::MemoryBodyStream payloadStream(
|
||||
reinterpret_cast<const uint8_t*>(matcherBody.data()), matcherBody.size());
|
||||
Azure::Core::Http::Request request(
|
||||
Azure::Core::Http::HttpMethod::Post, matcherRequest, &payloadStream);
|
||||
request.SetHeader("x-abstraction-identifier", "CustomDefaultMatcher");
|
||||
Azure::Core::Context ctx;
|
||||
auto response = m_privatePipeline->Send(request, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user