Add a (failing!) test for spurious HTTP methods in request metrics

This commit is contained in:
Jon Chambers 2026-04-09 12:10:22 -04:00 committed by Jon Chambers
parent 837065bfbd
commit 0d42f37a5c

View File

@ -6,6 +6,7 @@
package org.whispersystems.textsecuregcm.metrics;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ -240,6 +241,42 @@ class MetricsHttpChannelListenerIntegrationTest {
);
}
@Test
void unexpectedMethod() throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
COUNT_DOWN_LATCH_FUTURE_REFERENCE.set(countDownLatch);
final ArgumentCaptor<Iterable<Tag>> tagCaptor = ArgumentCaptor.forClass(Iterable.class);
final Map<String, Counter> counterMap = Map.of(
MetricsHttpChannelListener.REQUEST_COUNTER_NAME, REQUEST_COUNTER,
MetricsHttpChannelListener.RESPONSE_BYTES_COUNTER_NAME, RESPONSE_BYTES_COUNTER,
MetricsHttpChannelListener.REQUEST_BYTES_COUNTER_NAME, REQUEST_BYTES_COUNTER
);
when(METER_REGISTRY.counter(anyString(), any(Iterable.class)))
.thenAnswer(a -> counterMap.getOrDefault(a.getArgument(0, String.class), mock(Counter.class)));
try (final Response _ = EXTENSION.client().target(
String.format("http://localhost:%d%s", EXTENSION.getLocalPort(), "/v1/test/hello"))
.request()
.header(HttpHeaders.USER_AGENT, "Signal-Android/4.53.7 (Android 8.1)")
.method("ANNOY")) {
assertTrue(countDownLatch.await(1000, TimeUnit.MILLISECONDS));
verify(METER_REGISTRY).counter(eq(MetricsHttpChannelListener.REQUEST_COUNTER_NAME), tagCaptor.capture());
verify(REQUEST_COUNTER).increment();
final Iterable<Tag> tagIterable = tagCaptor.getValue();
final Set<Tag> tags = new HashSet<>();
for (final Tag tag : tagIterable) {
tags.add(tag);
}
assertFalse(tags.contains(Tag.of(MetricsHttpChannelListener.METHOD_TAG, "ANNOY")));
}
}
public static class TestApplication extends Application<Configuration> {
@Override