ceftests: Fix CookieTest failure with --use-test-http-server (see issue #3348)

This commit is contained in:
Marshall Greenblatt
2022-08-01 21:09:02 -04:00
parent a895274add
commit 0b1c3938c6
4 changed files with 18 additions and 11 deletions

View File

@@ -1111,10 +1111,12 @@ class CookieAccessResponseHandler {
}; };
std::string GetHeaderValue(const CefServer::HeaderMap& header_map, std::string GetHeaderValue(const CefServer::HeaderMap& header_map,
const std::string& header_name) { const std::string& header_name_lower) {
CefServer::HeaderMap::const_iterator it = header_map.find(header_name); for (const auto& [name, value] : header_map) {
if (it != header_map.end()) if (AsciiStrToLower(name) == header_name_lower) {
return it->second; return value;
}
}
return std::string(); return std::string();
} }
@@ -1131,7 +1133,7 @@ class CookieAccessSchemeHandler : public CefResourceHandler {
CefRequest::HeaderMap headerMap; CefRequest::HeaderMap headerMap;
request->GetHeaderMap(headerMap); request->GetHeaderMap(headerMap);
const std::string& cookie_str = GetHeaderValue(headerMap, "Cookie"); const std::string& cookie_str = GetHeaderValue(headerMap, "cookie");
TestCookieString(cookie_str, data_->cookie_js_ct_, data_->cookie_net_ct_); TestCookieString(cookie_str, data_->cookie_js_ct_, data_->cookie_net_ct_);
// Continue immediately. // Continue immediately.

View File

@@ -11,6 +11,12 @@
#include "include/cef_request_context_handler.h" #include "include/cef_request_context_handler.h"
#include "tests/gtest/include/gtest/gtest.h" #include "tests/gtest/include/gtest/gtest.h"
std::string AsciiStrToLower(const std::string& str) {
std::string lowerStr = str;
std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), ::tolower);
return lowerStr;
}
void TestMapEqual(const CefRequest::HeaderMap& map1, void TestMapEqual(const CefRequest::HeaderMap& map1,
const CefRequest::HeaderMap& map2, const CefRequest::HeaderMap& map2,
bool allowExtras) { bool allowExtras) {
@@ -25,11 +31,9 @@ void TestMapEqual(const CefRequest::HeaderMap& map1,
for (it1 = map1.begin(); it1 != map1.end(); ++it1) { for (it1 = map1.begin(); it1 != map1.end(); ++it1) {
bool found = false; bool found = false;
std::string name1 = it1->first; std::string name1 = AsciiStrToLower(it1->first);
std::transform(name1.begin(), name1.end(), name1.begin(), ::tolower);
for (it2 = map2.begin(); it2 != map2.end(); ++it2) { for (it2 = map2.begin(); it2 != map2.end(); ++it2) {
std::string name2 = it2->first; std::string name2 = AsciiStrToLower(it2->first);
std::transform(name2.begin(), name2.end(), name2.begin(), ::tolower);
if (name1 == name2 && it1->second == it2->second) { if (name1 == name2 && it1->second == it2->second) {
found = true; found = true;
break; break;

View File

@@ -16,6 +16,8 @@
CefTime CefTimeFrom(CefBaseTime value); CefTime CefTimeFrom(CefBaseTime value);
CefBaseTime CefBaseTimeFrom(const CefTime& value); CefBaseTime CefBaseTimeFrom(const CefTime& value);
std::string AsciiStrToLower(const std::string& str);
// Test that CefRequest::HeaderMap objects are equal. Multiple values with the // Test that CefRequest::HeaderMap objects are equal. Multiple values with the
// same key are allowed, but not duplicate entries with the same key/value. If // same key are allowed, but not duplicate entries with the same key/value. If
// |allowExtras| is true then additional header fields will be allowed in // |allowExtras| is true then additional header fields will be allowed in

View File

@@ -453,8 +453,7 @@ std::string GetHeaderValue(const CefRequest::HeaderMap& header_map,
const std::string& header_name_lower) { const std::string& header_name_lower) {
CefRequest::HeaderMap::const_iterator it = header_map.begin(); CefRequest::HeaderMap::const_iterator it = header_map.begin();
for (; it != header_map.end(); ++it) { for (; it != header_map.end(); ++it) {
std::string name = it->first; std::string name = AsciiStrToLower(it->first);
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
if (name == header_name_lower) if (name == header_name_lower)
return it->second; return it->second;
} }