• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

grpc / grpc-java / #19778

11 Apr 2025 03:25PM UTC coverage: 88.572% (-0.01%) from 88.586%
#19778

push

github

web-flow
xds: Enable deprecation warnings

The security code referenced fields removed from gRFC A29 before it was
finalized.

Note that this fixes a bug in CommonTlsContextUtil where
CombinedValidationContext was not checked. I believe this was the only
location with such a bug as I audited all non-test usages of
has/getValidationContext() and confirmed they have have a corresponding
has/getCombinedValidationContext().

34707 of 39185 relevant lines covered (88.57%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.19
/../xds/src/main/java/io/grpc/xds/internal/MatcherParser.java
1
/*
2
 * Copyright 2021 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc.xds.internal;
18

19
import com.google.re2j.Pattern;
20
import com.google.re2j.PatternSyntaxException;
21

22
// TODO(zivy@): may reuse common matchers parsers.
23
public final class MatcherParser {
×
24
  /** Translates envoy proto HeaderMatcher to internal HeaderMatcher.*/
25
  public static Matchers.HeaderMatcher parseHeaderMatcher(
26
          io.envoyproxy.envoy.config.route.v3.HeaderMatcher proto) {
27
    switch (proto.getHeaderMatchSpecifierCase()) {
1✔
28
      case EXACT_MATCH:
29
        @SuppressWarnings("deprecation") // gRFC A63: support indefinitely
30
        String exactMatch = proto.getExactMatch();
1✔
31
        return Matchers.HeaderMatcher.forExactValue(
1✔
32
                        proto.getName(), exactMatch, proto.getInvertMatch());
1✔
33
      case SAFE_REGEX_MATCH:
34
        @SuppressWarnings("deprecation") // gRFC A63: support indefinitely
35
        String rawPattern = proto.getSafeRegexMatch().getRegex();
1✔
36
        Pattern safeRegExMatch;
37
        try {
38
          safeRegExMatch = Pattern.compile(rawPattern);
1✔
39
        } catch (PatternSyntaxException e) {
1✔
40
          throw new IllegalArgumentException(
1✔
41
                "HeaderMatcher [" + proto.getName() + "] contains malformed safe regex pattern: "
1✔
42
                        + e.getMessage());
1✔
43
        }
1✔
44
        return Matchers.HeaderMatcher.forSafeRegEx(
1✔
45
              proto.getName(), safeRegExMatch, proto.getInvertMatch());
1✔
46
      case RANGE_MATCH:
47
        Matchers.HeaderMatcher.Range rangeMatch = Matchers.HeaderMatcher.Range.create(
1✔
48
              proto.getRangeMatch().getStart(), proto.getRangeMatch().getEnd());
1✔
49
        return Matchers.HeaderMatcher.forRange(
1✔
50
              proto.getName(), rangeMatch, proto.getInvertMatch());
1✔
51
      case PRESENT_MATCH:
52
        return Matchers.HeaderMatcher.forPresent(
1✔
53
              proto.getName(), proto.getPresentMatch(), proto.getInvertMatch());
1✔
54
      case PREFIX_MATCH:
55
        @SuppressWarnings("deprecation") // gRFC A63: support indefinitely
56
        String prefixMatch = proto.getPrefixMatch();
1✔
57
        return Matchers.HeaderMatcher.forPrefix(
1✔
58
              proto.getName(), prefixMatch, proto.getInvertMatch());
1✔
59
      case SUFFIX_MATCH:
60
        @SuppressWarnings("deprecation") // gRFC A63: support indefinitely
61
        String suffixMatch = proto.getSuffixMatch();
1✔
62
        return Matchers.HeaderMatcher.forSuffix(
1✔
63
              proto.getName(), suffixMatch, proto.getInvertMatch());
1✔
64
      case CONTAINS_MATCH:
65
        @SuppressWarnings("deprecation") // gRFC A63: support indefinitely
66
        String containsMatch = proto.getContainsMatch();
×
67
        return Matchers.HeaderMatcher.forContains(
×
68
              proto.getName(), containsMatch, proto.getInvertMatch());
×
69
      case STRING_MATCH:
70
        return Matchers.HeaderMatcher.forString(
1✔
71
          proto.getName(), parseStringMatcher(proto.getStringMatch()), proto.getInvertMatch());
1✔
72
      case HEADERMATCHSPECIFIER_NOT_SET:
73
      default:
74
        throw new IllegalArgumentException(
×
75
                "Unknown header matcher type: " + proto.getHeaderMatchSpecifierCase());
×
76
    }
77
  }
78

79
  /** Translate StringMatcher envoy proto to internal StringMatcher. */
80
  public static Matchers.StringMatcher parseStringMatcher(
81
            io.envoyproxy.envoy.type.matcher.v3.StringMatcher proto) {
82
    switch (proto.getMatchPatternCase()) {
1✔
83
      case EXACT:
84
        return Matchers.StringMatcher.forExact(proto.getExact(), proto.getIgnoreCase());
1✔
85
      case PREFIX:
86
        return Matchers.StringMatcher.forPrefix(proto.getPrefix(), proto.getIgnoreCase());
1✔
87
      case SUFFIX:
88
        return Matchers.StringMatcher.forSuffix(proto.getSuffix(), proto.getIgnoreCase());
×
89
      case SAFE_REGEX:
90
        return Matchers.StringMatcher.forSafeRegEx(
×
91
                Pattern.compile(proto.getSafeRegex().getRegex()));
×
92
      case CONTAINS:
93
        return Matchers.StringMatcher.forContains(proto.getContains());
×
94
      case MATCHPATTERN_NOT_SET:
95
      default:
96
        throw new IllegalArgumentException(
1✔
97
                "Unknown StringMatcher match pattern: " + proto.getMatchPatternCase());
1✔
98
    }
99
  }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc