Skip to content

Commit 89d7914

Browse files
committed
Fixup 12494: Improve test coverage for headermutations
1 parent 50bdd15 commit 89d7914

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

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

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static HeaderValueOption header(String key, String value, HeaderAppendAc
7777
}
7878

7979
@Test
80-
public void applyRequestMutations_asciiHeaders() {
80+
public void applyMutations_asciiHeaders() {
8181
Metadata headers = new Metadata();
8282
headers.put(APPEND_KEY, "append-value-1");
8383
headers.put(ADD_KEY, "add-value-original");
@@ -125,7 +125,7 @@ public void applyRequestMutations_asciiHeaders() {
125125
}
126126

127127
@Test
128-
public void applyRequestMutations_removalHasPriority() {
128+
public void applyMutations_removalHasPriority() {
129129
Metadata headers = new Metadata();
130130
headers.put(REMOVE_KEY, "value");
131131
HeaderMutations mutations =
@@ -141,7 +141,7 @@ public void applyRequestMutations_removalHasPriority() {
141141
}
142142

143143
@Test
144-
public void applyRequestMutations_binary() {
144+
public void applyMutations_binary() {
145145
Metadata headers = new Metadata();
146146
byte[] value = new byte[] {1, 2, 3};
147147
HeaderValueOption option =
@@ -203,7 +203,7 @@ public void applyResponseMutations_binary() {
203203
}
204204

205205
@Test
206-
public void applyRequestMutations_keepEmptyValue() {
206+
public void applyMutations_keepEmptyValue() {
207207
Metadata headers = new Metadata();
208208
headers.put(APPEND_KEY, "existing-value");
209209
headers.put(OVERWRITE_KEY, "existing-value");
@@ -243,4 +243,44 @@ public void applyRequestMutations_keepEmptyValue() {
243243
assertThat(headers.containsKey(keepEmptyOverwriteKey)).isTrue();
244244
assertThat(headers.get(keepEmptyOverwriteKey)).isEqualTo("");
245245
}
246+
247+
@Test
248+
public void applyMutations_binaryRemoval() {
249+
Metadata headers = new Metadata();
250+
byte[] value = new byte[] {1, 2, 3};
251+
headers.put(BINARY_KEY, value);
252+
HeaderMutations mutations =
253+
HeaderMutations.create(ImmutableList.of(), ImmutableList.of(BINARY_KEY.name()));
254+
255+
headerMutator.applyMutations(mutations, headers);
256+
257+
assertThat(headers.containsKey(BINARY_KEY)).isFalse();
258+
}
259+
260+
@Test
261+
public void applyMutations_stringValueWithBinaryKey_ignored() {
262+
Metadata headers = new Metadata();
263+
HeaderValueOption option = HeaderValueOption.create(HeaderValue.create("some-key-bin", "value"),
264+
HeaderAppendAction.APPEND_IF_EXISTS_OR_ADD, false);
265+
266+
headerMutator.applyMutations(
267+
HeaderMutations.create(ImmutableList.of(option), ImmutableList.of()), headers);
268+
269+
Metadata.Key<byte[]> key = Metadata.Key.of("some-key-bin", Metadata.BINARY_BYTE_MARSHALLER);
270+
assertThat(headers.containsKey(key)).isFalse();
271+
}
272+
273+
@Test
274+
public void applyMutations_binaryValueWithAsciiKey_ignored() {
275+
Metadata headers = new Metadata();
276+
HeaderValueOption option = HeaderValueOption.create(
277+
HeaderValue.create("some-key", ByteString.copyFrom(new byte[] {1})),
278+
HeaderAppendAction.APPEND_IF_EXISTS_OR_ADD, false);
279+
280+
headerMutator.applyMutations(
281+
HeaderMutations.create(ImmutableList.of(option), ImmutableList.of()), headers);
282+
283+
Metadata.Key<String> key = Metadata.Key.of("some-key", Metadata.ASCII_STRING_MARSHALLER);
284+
assertThat(headers.containsKey(key)).isFalse();
285+
}
246286
}

0 commit comments

Comments
 (0)