Skip to content

Commit d0febc2

Browse files
committed
remove registry based approach for attributes and resolve comments
1 parent 4801530 commit d0febc2

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

xds/src/main/java/io/grpc/xds/internal/matcher/HeadersWrapper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public String get(Object key) {
4444
return null;
4545
}
4646
String headerName = ((String) key).toLowerCase(java.util.Locale.ROOT);
47-
if ("te".equals(headerName)) {
47+
// The "te" header is a hop-by-hop header used for protocol signaling (trailers).
48+
// Per gRFC A41, it must be treated as not present to prevent matching logic
49+
// from depending on transport-level semantics.
50+
if (headerName.equals("te")) {
4851
return null;
4952
}
5053
switch (headerName) {

xds/src/test/java/io/grpc/xds/internal/matcher/CelEnvironmentTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
import static org.junit.Assert.fail;
2121

2222
import com.google.common.io.BaseEncoding;
23+
import dev.cel.common.CelAbstractSyntaxTree;
2324
import dev.cel.common.CelValidationException;
25+
import dev.cel.common.types.SimpleType;
26+
import dev.cel.compiler.CelCompiler;
27+
import dev.cel.compiler.CelCompilerFactory;
28+
import dev.cel.runtime.CelEvaluationException;
29+
import dev.cel.runtime.CelRuntime;
2430
import io.grpc.Metadata;
2531
import java.util.Map;
2632
import java.util.Optional;
@@ -33,6 +39,16 @@
3339
@RunWith(JUnit4.class)
3440
public final class CelEnvironmentTest {
3541

42+
private static final CelCompiler LENIENT_COMPILER =
43+
CelCompilerFactory.standardCelCompilerBuilder()
44+
.addVar("request", SimpleType.DYN)
45+
.build();
46+
47+
private static CelAbstractSyntaxTree compileLenientAst(String expression)
48+
throws CelValidationException {
49+
return LENIENT_COMPILER.compile(expression).getAst();
50+
}
51+
3652
@Test
3753
public void headersWrapper_resolvesPseudoHeaders() {
3854
MatchContext context = MatchContext.newBuilder()
@@ -192,6 +208,42 @@ public void celEnvironment_disabledFeatures_throwsValidationException() {
192208
}
193209
}
194210

211+
@Test
212+
public void celEnvironment_runtime_disabledFeatures_throwsException() throws Exception {
213+
MatchContext context = MatchContext.newBuilder().build();
214+
GrpcCelEnvironment resolver = new GrpcCelEnvironment(context);
215+
216+
// String concatenation fails at runtime evaluation (missing overload)
217+
CelAbstractSyntaxTree stringConcatAst = compileLenientAst("'a' + 'b'");
218+
CelRuntime.Program stringConcatProgram = CelCommon.RUNTIME.createProgram(stringConcatAst);
219+
try {
220+
stringConcatProgram.eval(resolver);
221+
Assert.fail("String concatenation evaluation should fail");
222+
} catch (CelEvaluationException e) {
223+
assertThat(e).hasMessageThat().contains("No matching overload");
224+
}
225+
226+
// List concatenation fails at runtime evaluation (missing overload)
227+
CelAbstractSyntaxTree listConcatAst = compileLenientAst("[1] + [2]");
228+
CelRuntime.Program listConcatProgram = CelCommon.RUNTIME.createProgram(listConcatAst);
229+
try {
230+
listConcatProgram.eval(resolver);
231+
Assert.fail("List concatenation evaluation should fail");
232+
} catch (CelEvaluationException e) {
233+
assertThat(e).hasMessageThat().contains("No matching overload");
234+
}
235+
236+
// String conversion fails at runtime evaluation (missing overload/function)
237+
CelAbstractSyntaxTree stringConvAst = compileLenientAst("string(1)");
238+
CelRuntime.Program stringConvProgram = CelCommon.RUNTIME.createProgram(stringConvAst);
239+
try {
240+
stringConvProgram.eval(resolver);
241+
Assert.fail("String conversion evaluation should fail");
242+
} catch (CelEvaluationException e) {
243+
assertThat(e).hasMessageThat().contains("No matching overload");
244+
}
245+
}
246+
195247
@Test
196248
public void celEnvironment_method_fallback() {
197249
MatchContext context = MatchContext.newBuilder().build();

0 commit comments

Comments
 (0)