mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 11:46:53 +00:00
Fix ProxyProtocolHandlerTest resource leak
Also replace AbstractLeakDetectionTest with netty LeakPresenceExtension
This commit is contained in:
1 parent
771fecd396
commit
c5ae3963b5
5 files changed
+54
-41
No files matched your search
-25
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright 2026 Signal Messenger, LLC
|
||||
* SPDX License Identifier: AGPL 3.0 only
|
||||
*/
|
||||
package org.whispersystems.textsecuregcm.grpc.net;
|
||||
|
||||
import io.netty.util.ResourceLeakDetector;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
public abstract class AbstractLeakDetectionTest {
|
||||
|
||||
private static ResourceLeakDetector.Level originalResourceLeakDetectorLevel;
|
||||
|
||||
@BeforeAll
|
||||
static void setLeakDetectionLevel() {
|
||||
originalResourceLeakDetectorLevel = ResourceLeakDetector.getLevel();
|
||||
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void restoreLeakDetectionLevel() {
|
||||
ResourceLeakDetector.setLevel(originalResourceLeakDetectorLevel);
|
||||
}
|
||||
}
|
||||
+4
-1
@@ -11,9 +11,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import io.netty.channel.WriteBufferWaterMark;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import io.netty.util.test.LeakPresenceExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
class H2FrameProxyHandlerTest extends AbstractLeakDetectionTest {
|
||||
@ExtendWith(LeakPresenceExtension.class)
|
||||
class H2FrameProxyHandlerTest {
|
||||
@Test
|
||||
void proxyWritabilityChanged() {
|
||||
final EmbeddedChannel target = new EmbeddedChannel();
|
||||
|
||||
+4
-1
@@ -49,6 +49,7 @@ import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.test.LeakPresenceExtension;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -68,11 +69,13 @@ import javax.annotation.Nullable;
|
||||
import javax.net.ssl.SSLException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
import org.junitpioneer.jupiter.cartesian.CartesianTest;
|
||||
|
||||
class OmnibusH2ServerTest extends AbstractLeakDetectionTest {
|
||||
@ExtendWith(LeakPresenceExtension.class)
|
||||
class OmnibusH2ServerTest {
|
||||
private static final String KEYSTORE_PASSWORD = "password";
|
||||
|
||||
// Paths that start with PREFIX should go to the prefix backend, everything else to default.
|
||||
|
||||
+39
-14
@@ -14,40 +14,65 @@ import io.netty.handler.codec.haproxy.HAProxyMessage;
|
||||
import io.netty.handler.codec.haproxy.HAProxyMessageEncoder;
|
||||
import io.netty.handler.codec.haproxy.HAProxyProtocolVersion;
|
||||
import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.test.LeakPresenceExtension;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
class ProxyProtocolHandlerTest extends AbstractLeakDetectionTest {
|
||||
private static final HAProxyMessage PROXY_MESSAGE = new HAProxyMessage(
|
||||
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY,
|
||||
HAProxyProxiedProtocol.TCP4, "10.0.0.1", "10.0.0.2", 1234, 5678);
|
||||
@ExtendWith(LeakPresenceExtension.class)
|
||||
class ProxyProtocolHandlerTest {
|
||||
|
||||
private static final HAProxyProtocolVersion PROTOCOL_VERSION = HAProxyProtocolVersion.V2;
|
||||
private static final String SOURCE_ADDRESS = "10.0.0.1";
|
||||
private static final String DESTINATION_ADDRESS = "10.0.0.2";
|
||||
|
||||
private static HAProxyMessage proxyMessage() {
|
||||
return new HAProxyMessage(
|
||||
PROTOCOL_VERSION, HAProxyCommand.PROXY,
|
||||
HAProxyProxiedProtocol.TCP4, SOURCE_ADDRESS, DESTINATION_ADDRESS, 1234, 5678);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendHeader() {
|
||||
final HAProxyMessage proxyMessage = proxyMessage();
|
||||
final EmbeddedChannel encoder = new EmbeddedChannel(HAProxyMessageEncoder.INSTANCE);
|
||||
encoder.writeOutbound(PROXY_MESSAGE.retain());
|
||||
encoder.writeOutbound(proxyMessage);
|
||||
final ByteBuf ppv2Bytes = encoder.readOutbound();
|
||||
|
||||
final EmbeddedChannel ch = new EmbeddedChannel(new ProxyProtocolHandler());
|
||||
ch.writeInbound(ppv2Bytes);
|
||||
final HAProxyMessage actual = ch.readInbound();
|
||||
assertEquals(PROXY_MESSAGE.protocolVersion(), actual.protocolVersion());
|
||||
assertEquals(PROXY_MESSAGE.sourceAddress(), actual.sourceAddress());
|
||||
try {
|
||||
assertEquals(PROTOCOL_VERSION, actual.protocolVersion());
|
||||
assertEquals(SOURCE_ADDRESS, actual.sourceAddress());
|
||||
} finally {
|
||||
ReferenceCountUtil.release(actual);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendHeaderSlowly() {
|
||||
final HAProxyMessage proxyMessage = proxyMessage();
|
||||
final EmbeddedChannel encoder = new EmbeddedChannel(HAProxyMessageEncoder.INSTANCE);
|
||||
encoder.writeOutbound(PROXY_MESSAGE.retain());
|
||||
final ByteBuf ppv2Bytes = encoder.readOutbound();
|
||||
encoder.writeOutbound(proxyMessage);
|
||||
|
||||
final EmbeddedChannel ch = new EmbeddedChannel(new ProxyProtocolHandler());
|
||||
while (ppv2Bytes.isReadable()) {
|
||||
assertNull(ch.readInbound());
|
||||
ch.writeInbound(ppv2Bytes.readBytes(1));
|
||||
final ByteBuf ppv2Bytes = encoder.readOutbound();
|
||||
try {
|
||||
while (ppv2Bytes.isReadable()) {
|
||||
assertNull(ch.readInbound());
|
||||
ch.writeInbound(ppv2Bytes.readBytes(1));
|
||||
}
|
||||
} finally {
|
||||
ReferenceCountUtil.release(ppv2Bytes);
|
||||
}
|
||||
|
||||
final HAProxyMessage actual = ch.readInbound();
|
||||
assertEquals(PROXY_MESSAGE.protocolVersion(), actual.protocolVersion());
|
||||
assertEquals(PROXY_MESSAGE.sourceAddress(), actual.sourceAddress());
|
||||
try {
|
||||
assertEquals(PROTOCOL_VERSION, actual.protocolVersion());
|
||||
assertEquals(SOURCE_ADDRESS, actual.sourceAddress());
|
||||
} finally {
|
||||
ReferenceCountUtil.release(actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user