Interop reported an error for a present match and it is discovered this
case is missing from unit test. We have test for present (false) and we
have special case test but we don't have the normal present (true) test.
We also had a bug in a our code:
if (!value.has_value()) {
if (header_matcher.type ==
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::PRESENT) {
return !header_matcher.present_match;
} else {
// For all other header matcher types, we need the header value to
// exist to consider matches.
return false;
}
}
switch (header_matcher.type) {
case XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::EXACT:
return value.value() == header_matcher.string_matcher;
case XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::REGEX:
return RE2::FullMatch(value.value().data(), *header_matcher.regex_match);
case XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::RANGE:
int64_t int_value;
if (!absl::SimpleAtoi(value.value(), &int_value)) {
return false;
}
return int_value >= header_matcher.range_start &&
int_value < header_matcher.range_end;
case XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::PREFIX:
return absl::StartsWith(value.value(), header_matcher.string_matcher);
case XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::SUFFIX:
return absl::EndsWith(value.value(), header_matcher.string_matcher);
default:
return false;
}
Note if header has value, we will go into the swtich but there is no case
XdsApi::Route::Matchers::HeaderMatcher::HeaderMatcherType::PRESENT,
which means we would have gone into default and decleared not a match.
The same day this bug was discovered by interop test, https://github.com/grpc/grpc/pull/25122
was submitted and the refactoring fixed the bug.
Nevertheless, I added the test case for the future.
was not the correct fix and caused window test issues.
The correct fix is to ensure the test uses the same time apis as the
product code: grp_get_cycle_counter (which is platform dependent) to get
current time.
Tested both in open source and patched into google3 to ensure successful
import:
https://critique-ng.corp.google.com/cl/349981071/analysis
Google's internal version of the gRPC codebase uses a version of
protobuf with a different namespace and include paths. This commit makes
parse_json.cc rely on config_protobuf.h for protobuf types so that it
will work properly in that environment. I also replaced a call to
Status::error_code() with a call to Status::code() instead. This way the
code will work with absl::Status, which has a somewhat different API
compared to google::protobuf::util::Status.