Skip to content

Commit 8d6cd46

Browse files
committed
Handle gemini review comments.
1 parent ac5a132 commit 8d6cd46

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

xds/src/main/java/io/grpc/xds/internal/headermutations/HeaderMutationFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ private boolean isHeaderMutationAllowed(String headerName,
9797
&& rules.disallowExpression().get().matcher(headerName).matches()) {
9898
return false;
9999
}
100-
if (rules.allowExpression().isPresent()) {
101-
return rules.allowExpression().get().matcher(headerName).matches();
100+
if (rules.allowExpression().isPresent()
101+
&& rules.allowExpression().get().matcher(headerName).matches()) {
102+
return true;
102103
}
103104
return !rules.disallowAll();
104105
}

xds/src/test/java/io/grpc/xds/internal/headermutations/HeaderMutationFilterTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,31 @@ public void filter_allowExpression_onlyAllowsRelevantExpressions()
154154
HeaderMutations filtered = filter.filter(mutations);
155155

156156

157-
assertThat(filtered.headersToRemove()).containsExactly("x-allowed-remove");
157+
assertThat(filtered.headersToRemove()).containsExactly("x-allowed-remove", "not-allowed-remove");
158158
assertThat(filtered.headers()).containsExactly(header("x-allowed-key", "value"),
159-
header("x-allowed-resp-key", "value"));
159+
header("not-allowed-key", "value"),
160+
header("x-allowed-resp-key", "value"),
161+
header("not-allowed-resp-key", "value"));
162+
}
163+
164+
@Test
165+
public void filter_allowExpression_fallsThroughToDisallowAll()
166+
throws HeaderMutationDisallowedException {
167+
HeaderMutationRulesConfig rules = HeaderMutationRulesConfig.builder()
168+
.disallowAll(true)
169+
.allowExpression(Pattern.compile("^x-allowed-.*")).build();
170+
HeaderMutationFilter filter = new HeaderMutationFilter(Optional.of(rules));
171+
HeaderMutations mutations = HeaderMutations.create(
172+
ImmutableList.of(header("x-allowed-key", "value"), header("not-allowed-key", "value")),
173+
ImmutableList.of("x-allowed-remove", "not-allowed-remove"));
174+
175+
HeaderMutations filtered = filter.filter(mutations);
176+
177+
assertThat(filtered.headersToRemove()).containsExactly("x-allowed-remove");
178+
assertThat(filtered.headers()).containsExactly(header("x-allowed-key", "value"));
160179
}
161180

181+
162182
@Test
163183
public void filter_allowExpression_overridesDisallowAll()
164184
throws HeaderMutationDisallowedException {

0 commit comments

Comments
 (0)