Migrate codec-haproxy tests to JUnit 5 (#11308)
Motivation: JUnit 5 is more expressive, extensible, and composable in many ways, and it's better able to run tests in parallel. Modifications: Use JUnit5 in codec-smtp tests Result: Related to https://github.com/netty/netty/issues/10757
This commit is contained in:
parent
e9a8eaeb18
commit
187c6015b4
@ -27,13 +27,14 @@ import io.netty.channel.SimpleChannelInboundHandler;
|
|||||||
import io.netty.channel.local.LocalAddress;
|
import io.netty.channel.local.LocalAddress;
|
||||||
import io.netty.channel.local.LocalChannel;
|
import io.netty.channel.local.LocalChannel;
|
||||||
import io.netty.channel.local.LocalServerChannel;
|
import io.netty.channel.local.LocalServerChannel;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HAProxyIntegrationTest {
|
public class HAProxyIntegrationTest {
|
||||||
|
|
||||||
|
@ -23,23 +23,25 @@ import io.netty.handler.codec.ProtocolDetectionState;
|
|||||||
import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.AddressFamily;
|
import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.AddressFamily;
|
||||||
import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.TransportProtocol;
|
import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol.TransportProtocol;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.function.Executable;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static io.netty.buffer.Unpooled.*;
|
import static io.netty.buffer.Unpooled.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
public class HAProxyMessageDecoderTest {
|
public class HAProxyMessageDecoderTest {
|
||||||
@Rule
|
|
||||||
public ExpectedException exceptionRule = ExpectedException.none();
|
|
||||||
|
|
||||||
private EmbeddedChannel ch;
|
private EmbeddedChannel ch;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
ch = new EmbeddedChannel(new HAProxyMessageDecoder());
|
ch = new EmbeddedChannel(new HAProxyMessageDecoder());
|
||||||
}
|
}
|
||||||
@ -107,70 +109,121 @@ public class HAProxyMessageDecoderTest {
|
|||||||
assertTrue(msg.release());
|
assertTrue(msg.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testV1NoUDP() {
|
public void testV1NoUDP() {
|
||||||
String header = "PROXY UDP4 192.168.0.1 192.168.0.11 56324 443\r\n";
|
final String header = "PROXY UDP4 192.168.0.1 192.168.0.11 56324 443\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testInvalidPort() {
|
public void testInvalidPort() {
|
||||||
String header = "PROXY TCP4 192.168.0.1 192.168.0.11 80000 443\r\n";
|
final String header = "PROXY TCP4 192.168.0.1 192.168.0.11 80000 443\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testInvalidIPV4Address() {
|
public void testInvalidIPV4Address() {
|
||||||
String header = "PROXY TCP4 299.168.0.1 192.168.0.11 56324 443\r\n";
|
final String header = "PROXY TCP4 299.168.0.1 192.168.0.11 56324 443\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testInvalidIPV6Address() {
|
public void testInvalidIPV6Address() {
|
||||||
String header = "PROXY TCP6 r001:0db8:85a3:0000:0000:8a2e:0370:7334 1050:0:0:0:5:600:300c:326b 56324 443\r\n";
|
final String header =
|
||||||
|
"PROXY TCP6 r001:0db8:85a3:0000:0000:8a2e:0370:7334 1050:0:0:0:5:600:300c:326b 56324 443\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testInvalidProtocol() {
|
public void testInvalidProtocol() {
|
||||||
String header = "PROXY TCP7 192.168.0.1 192.168.0.11 56324 443\r\n";
|
final String header = "PROXY TCP7 192.168.0.1 192.168.0.11 56324 443\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testMissingParams() {
|
public void testMissingParams() {
|
||||||
String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324\r\n";
|
final String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testTooManyParams() {
|
public void testTooManyParams() {
|
||||||
String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 443 123\r\n";
|
final String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 443 123\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testInvalidCommand() {
|
public void testInvalidCommand() {
|
||||||
String header = "PING TCP4 192.168.0.1 192.168.0.11 56324 443\r\n";
|
final String header = "PING TCP4 192.168.0.1 192.168.0.11 56324 443\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testInvalidEOL() {
|
public void testInvalidEOL() {
|
||||||
String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 443\nGET / HTTP/1.1\r\n";
|
final String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 443\nGET / HTTP/1.1\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testHeaderTooLong() {
|
public void testHeaderTooLong() {
|
||||||
String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 " +
|
final String header = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 " +
|
||||||
"00000000000000000000000000000000000000000000000000000000000000000443\r\n";
|
"00000000000000000000000000000000000000000000000000000000000000000443\r\n";
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
ch.writeInbound(copiedBuffer(header, CharsetUtil.US_ASCII));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailSlowHeaderTooLong() {
|
public void testFailSlowHeaderTooLong() {
|
||||||
EmbeddedChannel slowFailCh = new EmbeddedChannel(new HAProxyMessageDecoder(false));
|
final EmbeddedChannel slowFailCh = new EmbeddedChannel(new HAProxyMessageDecoder(false));
|
||||||
try {
|
try {
|
||||||
String headerPart1 = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 " +
|
String headerPart1 = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 " +
|
||||||
"000000000000000000000000000000000000000000000000000000000000000000000443";
|
"000000000000000000000000000000000000000000000000000000000000000000000443";
|
||||||
@ -179,13 +232,15 @@ public class HAProxyMessageDecoderTest {
|
|||||||
String headerPart2 = "more header data";
|
String headerPart2 = "more header data";
|
||||||
// Should not throw exception
|
// Should not throw exception
|
||||||
assertFalse(slowFailCh.writeInbound(copiedBuffer(headerPart2, CharsetUtil.US_ASCII)));
|
assertFalse(slowFailCh.writeInbound(copiedBuffer(headerPart2, CharsetUtil.US_ASCII)));
|
||||||
String headerPart3 = "end of header\r\n";
|
final String headerPart3 = "end of header\r\n";
|
||||||
|
|
||||||
int discarded = headerPart1.length() + headerPart2.length() + headerPart3.length() - 2;
|
int discarded = headerPart1.length() + headerPart2.length() + headerPart3.length() - 2;
|
||||||
// Should throw exception
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
exceptionRule.expect(HAProxyProtocolException.class);
|
@Override
|
||||||
exceptionRule.expectMessage("over " + discarded);
|
public void execute() {
|
||||||
assertFalse(slowFailCh.writeInbound(copiedBuffer(headerPart3, CharsetUtil.US_ASCII)));
|
slowFailCh.writeInbound(copiedBuffer(headerPart3, CharsetUtil.US_ASCII));
|
||||||
|
}
|
||||||
|
}, "over " + discarded);
|
||||||
} finally {
|
} finally {
|
||||||
assertFalse(slowFailCh.finishAndReleaseAll());
|
assertFalse(slowFailCh.finishAndReleaseAll());
|
||||||
}
|
}
|
||||||
@ -193,13 +248,16 @@ public class HAProxyMessageDecoderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailFastHeaderTooLong() {
|
public void testFailFastHeaderTooLong() {
|
||||||
EmbeddedChannel fastFailCh = new EmbeddedChannel(new HAProxyMessageDecoder(true));
|
final EmbeddedChannel fastFailCh = new EmbeddedChannel(new HAProxyMessageDecoder(true));
|
||||||
try {
|
try {
|
||||||
String headerPart1 = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 " +
|
final String headerPart1 = "PROXY TCP4 192.168.0.1 192.168.0.11 56324 " +
|
||||||
"000000000000000000000000000000000000000000000000000000000000000000000443";
|
"000000000000000000000000000000000000000000000000000000000000000000000443";
|
||||||
exceptionRule.expect(HAProxyProtocolException.class); // Should throw exception, fail fast
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
exceptionRule.expectMessage("over " + headerPart1.length());
|
@Override
|
||||||
assertFalse(fastFailCh.writeInbound(copiedBuffer(headerPart1, CharsetUtil.US_ASCII)));
|
public void execute() {
|
||||||
|
fastFailCh.writeInbound(copiedBuffer(headerPart1, CharsetUtil.US_ASCII));
|
||||||
|
}
|
||||||
|
}, "over " + headerPart1.length());
|
||||||
} finally {
|
} finally {
|
||||||
assertFalse(fastFailCh.finishAndReleaseAll());
|
assertFalse(fastFailCh.finishAndReleaseAll());
|
||||||
}
|
}
|
||||||
@ -639,7 +697,7 @@ public class HAProxyMessageDecoderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testV2WithSslTLVs() throws Exception {
|
public void testV2WithSslTLVs() {
|
||||||
ch = new EmbeddedChannel(new HAProxyMessageDecoder());
|
ch = new EmbeddedChannel(new HAProxyMessageDecoder());
|
||||||
|
|
||||||
final byte[] bytes = {
|
final byte[] bytes = {
|
||||||
@ -834,9 +892,9 @@ public class HAProxyMessageDecoderTest {
|
|||||||
assertTrue(msg.release());
|
assertTrue(msg.release());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testV2InvalidProtocol() {
|
public void testV2InvalidProtocol() {
|
||||||
byte[] header = new byte[28];
|
final byte[] header = new byte[28];
|
||||||
header[0] = 0x0D; // Binary Prefix
|
header[0] = 0x0D; // Binary Prefix
|
||||||
header[1] = 0x0A; // -----
|
header[1] = 0x0A; // -----
|
||||||
header[2] = 0x0D; // -----
|
header[2] = 0x0D; // -----
|
||||||
@ -872,12 +930,17 @@ public class HAProxyMessageDecoderTest {
|
|||||||
header[26] = 0x01; // Destination Port
|
header[26] = 0x01; // Destination Port
|
||||||
header[27] = (byte) 0xbb; // -----
|
header[27] = (byte) 0xbb; // -----
|
||||||
|
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header));
|
ch.writeInbound(copiedBuffer(header));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testV2MissingParams() {
|
public void testV2MissingParams() {
|
||||||
byte[] header = new byte[26];
|
final byte[] header = new byte[26];
|
||||||
header[0] = 0x0D; // Binary Prefix
|
header[0] = 0x0D; // Binary Prefix
|
||||||
header[1] = 0x0A; // -----
|
header[1] = 0x0A; // -----
|
||||||
header[2] = 0x0D; // -----
|
header[2] = 0x0D; // -----
|
||||||
@ -910,12 +973,17 @@ public class HAProxyMessageDecoderTest {
|
|||||||
header[24] = (byte) 0xdc; // Source Port
|
header[24] = (byte) 0xdc; // Source Port
|
||||||
header[25] = 0x04; // -----
|
header[25] = 0x04; // -----
|
||||||
|
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header));
|
ch.writeInbound(copiedBuffer(header));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testV2InvalidCommand() {
|
public void testV2InvalidCommand() {
|
||||||
byte[] header = new byte[28];
|
final byte[] header = new byte[28];
|
||||||
header[0] = 0x0D; // Binary Prefix
|
header[0] = 0x0D; // Binary Prefix
|
||||||
header[1] = 0x0A; // -----
|
header[1] = 0x0A; // -----
|
||||||
header[2] = 0x0D; // -----
|
header[2] = 0x0D; // -----
|
||||||
@ -951,12 +1019,17 @@ public class HAProxyMessageDecoderTest {
|
|||||||
header[26] = 0x01; // Destination Port
|
header[26] = 0x01; // Destination Port
|
||||||
header[27] = (byte) 0xbb; // -----
|
header[27] = (byte) 0xbb; // -----
|
||||||
|
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header));
|
ch.writeInbound(copiedBuffer(header));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testV2InvalidVersion() {
|
public void testV2InvalidVersion() {
|
||||||
byte[] header = new byte[28];
|
final byte[] header = new byte[28];
|
||||||
header[0] = 0x0D; // Binary Prefix
|
header[0] = 0x0D; // Binary Prefix
|
||||||
header[1] = 0x0A; // -----
|
header[1] = 0x0A; // -----
|
||||||
header[2] = 0x0D; // -----
|
header[2] = 0x0D; // -----
|
||||||
@ -992,14 +1065,19 @@ public class HAProxyMessageDecoderTest {
|
|||||||
header[26] = 0x01; // Destination Port
|
header[26] = 0x01; // Destination Port
|
||||||
header[27] = (byte) 0xbb; // -----
|
header[27] = (byte) 0xbb; // -----
|
||||||
|
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header));
|
ch.writeInbound(copiedBuffer(header));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = HAProxyProtocolException.class)
|
@Test
|
||||||
public void testV2HeaderTooLong() {
|
public void testV2HeaderTooLong() {
|
||||||
ch = new EmbeddedChannel(new HAProxyMessageDecoder(0));
|
ch = new EmbeddedChannel(new HAProxyMessageDecoder(0));
|
||||||
|
|
||||||
byte[] header = new byte[248];
|
final byte[] header = new byte[248];
|
||||||
header[0] = 0x0D; // Binary Prefix
|
header[0] = 0x0D; // Binary Prefix
|
||||||
header[1] = 0x0A; // -----
|
header[1] = 0x0A; // -----
|
||||||
header[2] = 0x0D; // -----
|
header[2] = 0x0D; // -----
|
||||||
@ -1035,8 +1113,13 @@ public class HAProxyMessageDecoderTest {
|
|||||||
header[26] = 0x01; // Destination Port
|
header[26] = 0x01; // Destination Port
|
||||||
header[27] = (byte) 0xbb; // -----
|
header[27] = (byte) 0xbb; // -----
|
||||||
|
|
||||||
|
assertThrows(HAProxyProtocolException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
ch.writeInbound(copiedBuffer(header));
|
ch.writeInbound(copiedBuffer(header));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testV2IncompleteHeader() {
|
public void testV2IncompleteHeader() {
|
||||||
|
@ -17,11 +17,12 @@
|
|||||||
package io.netty.handler.codec.haproxy;
|
package io.netty.handler.codec.haproxy;
|
||||||
|
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class HAProxySSLTLVTest {
|
public class HAProxySSLTLVTest {
|
||||||
|
|
||||||
|
@ -23,7 +23,8 @@ import io.netty.channel.embedded.EmbeddedChannel;
|
|||||||
import io.netty.handler.codec.haproxy.HAProxyTLV.Type;
|
import io.netty.handler.codec.haproxy.HAProxyTLV.Type;
|
||||||
import io.netty.util.ByteProcessor;
|
import io.netty.util.ByteProcessor;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.function.Executable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -31,7 +32,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.haproxy.HAProxyConstants.*;
|
import static io.netty.handler.codec.haproxy.HAProxyConstants.*;
|
||||||
import static io.netty.handler.codec.haproxy.HAProxyMessageEncoder.*;
|
import static io.netty.handler.codec.haproxy.HAProxyMessageEncoder.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||||
|
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;
|
||||||
|
|
||||||
public class HaProxyMessageEncoderTest {
|
public class HaProxyMessageEncoderTest {
|
||||||
|
|
||||||
@ -356,49 +361,79 @@ public class HaProxyMessageEncoderTest {
|
|||||||
assertFalse(ch.finish());
|
assertFalse(ch.finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testInvalidIpV4Address() {
|
public void testInvalidIpV4Address() {
|
||||||
String invalidIpv4Address = "192.168.0.1234";
|
final String invalidIpv4Address = "192.168.0.1234";
|
||||||
|
assertThrows(IllegalArgumentException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new HAProxyMessage(
|
new HAProxyMessage(
|
||||||
HAProxyProtocolVersion.V1, HAProxyCommand.PROXY, HAProxyProxiedProtocol.TCP4,
|
HAProxyProtocolVersion.V1, HAProxyCommand.PROXY, HAProxyProxiedProtocol.TCP4,
|
||||||
invalidIpv4Address, "192.168.0.11", 56324, 443);
|
invalidIpv4Address, "192.168.0.11", 56324, 443);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testInvalidIpV6Address() {
|
public void testInvalidIpV6Address() {
|
||||||
String invalidIpv6Address = "2001:0db8:85a3:0000:0000:8a2e:0370:73345";
|
final String invalidIpv6Address = "2001:0db8:85a3:0000:0000:8a2e:0370:73345";
|
||||||
|
assertThrows(IllegalArgumentException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new HAProxyMessage(
|
new HAProxyMessage(
|
||||||
HAProxyProtocolVersion.V1, HAProxyCommand.PROXY, HAProxyProxiedProtocol.TCP6,
|
HAProxyProtocolVersion.V1, HAProxyCommand.PROXY, HAProxyProxiedProtocol.TCP6,
|
||||||
invalidIpv6Address, "1050:0:0:0:5:600:300c:326b", 56324, 443);
|
invalidIpv6Address, "1050:0:0:0:5:600:300c:326b", 56324, 443);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testInvalidUnixAddress() {
|
public void testInvalidUnixAddress() {
|
||||||
String invalidUnixAddress = new String(new byte[UNIX_ADDRESS_BYTES_LENGTH + 1]);
|
final String invalidUnixAddress = new String(new byte[UNIX_ADDRESS_BYTES_LENGTH + 1]);
|
||||||
|
assertThrows(IllegalArgumentException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new HAProxyMessage(
|
new HAProxyMessage(
|
||||||
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
||||||
invalidUnixAddress, "/var/run/dst.sock", 0, 0);
|
invalidUnixAddress, "/var/run/dst.sock", 0, 0);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test
|
||||||
public void testNullUnixAddress() {
|
public void testNullUnixAddress() {
|
||||||
|
assertThrows(NullPointerException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new HAProxyMessage(
|
new HAProxyMessage(
|
||||||
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
||||||
null, null, 0, 0);
|
null, null, 0, 0);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testLongUnixAddress() {
|
public void testLongUnixAddress() {
|
||||||
String longUnixAddress = new String(new char[109]).replace("\0", "a");
|
final String longUnixAddress = new String(new char[109]).replace("\0", "a");
|
||||||
|
assertThrows(IllegalArgumentException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new HAProxyMessage(
|
new HAProxyMessage(
|
||||||
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
||||||
"source", longUnixAddress, 0, 0);
|
"source", longUnixAddress, 0, 0);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testInvalidUnixPort() {
|
public void testInvalidUnixPort() {
|
||||||
|
assertThrows(IllegalArgumentException.class, new Executable() {
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
new HAProxyMessage(
|
new HAProxyMessage(
|
||||||
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
HAProxyProtocolVersion.V2, HAProxyCommand.PROXY, HAProxyProxiedProtocol.UNIX_STREAM,
|
||||||
"/var/run/src.sock", "/var/run/dst.sock", 80, 443);
|
"/var/run/src.sock", "/var/run/dst.sock", 80, 443);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user