Skip to content

Commit 312f166

Browse files
committed
Handle gemini review comments.
1 parent ac5a132 commit 312f166

2 files changed

Lines changed: 24 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: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,30 @@ 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",
158+
"not-allowed-remove");
158159
assertThat(filtered.headers()).containsExactly(header("x-allowed-key", "value"),
159-
header("x-allowed-resp-key", "value"));
160+
header("not-allowed-key", "value"), 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().disallowAll(true)
168+
.allowExpression(Pattern.compile("^x-allowed-.*")).build();
169+
HeaderMutationFilter filter = new HeaderMutationFilter(Optional.of(rules));
170+
HeaderMutations mutations = HeaderMutations.create(
171+
ImmutableList.of(header("x-allowed-key", "value"), header("not-allowed-key", "value")),
172+
ImmutableList.of("x-allowed-remove", "not-allowed-remove"));
173+
174+
HeaderMutations filtered = filter.filter(mutations);
175+
176+
assertThat(filtered.headersToRemove()).containsExactly("x-allowed-remove");
177+
assertThat(filtered.headers()).containsExactly(header("x-allowed-key", "value"));
160178
}
161179

180+
162181
@Test
163182
public void filter_allowExpression_overridesDisallowAll()
164183
throws HeaderMutationDisallowedException {

0 commit comments

Comments
 (0)