From db15c6dcd602644de2b0782abd6a29801c1b3a2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= Date: Mon, 28 Oct 2024 16:36:41 +1100 Subject: [PATCH] Move AddressUtilsTest to JUnit4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ThiƩbaud Weksteen --- .../java/org/conscrypt/AddressUtilsTest.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java b/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java index b210c0aee..59aba1521 100644 --- a/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java +++ b/openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java @@ -16,40 +16,54 @@ package org.conscrypt; -import junit.framework.TestCase; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** * Test for AddressUtils */ -public class AddressUtilsTest extends TestCase { +@RunWith(JUnit4.class) +public class AddressUtilsTest { + @Test public void test_isValidSniHostname_Success() throws Exception { assertTrue(AddressUtils.isValidSniHostname("www.google.com")); } + @Test public void test_isValidSniHostname_NotFQDN_Failure() throws Exception { assertFalse(AddressUtils.isValidSniHostname("www")); } + @Test public void test_isValidSniHostname_Localhost_Success() throws Exception { assertTrue(AddressUtils.isValidSniHostname("LOCALhost")); } + @Test public void test_isValidSniHostname_IPv4_Failure() throws Exception { assertFalse(AddressUtils.isValidSniHostname("192.168.0.1")); } + @Test public void test_isValidSniHostname_IPv6_Failure() throws Exception { assertFalse(AddressUtils.isValidSniHostname("2001:db8::1")); } + @Test public void test_isValidSniHostname_TrailingDot() throws Exception { assertFalse(AddressUtils.isValidSniHostname("www.google.com.")); } + @Test public void test_isValidSniHostname_NullByte() throws Exception { assertFalse(AddressUtils.isValidSniHostname("www\0.google.com")); } + @Test public void test_isLiteralIpAddress_IPv4_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("127.0.0.1")); assertTrue(AddressUtils.isLiteralIpAddress("255.255.255.255")); @@ -58,6 +72,7 @@ public void test_isLiteralIpAddress_IPv4_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("254.249.190.094")); } + @Test public void test_isLiteralIpAddress_IPv4_ExtraCharacters_Failure() throws Exception { assertFalse(AddressUtils.isLiteralIpAddress("127.0.0.1a")); assertFalse(AddressUtils.isLiteralIpAddress(" 255.255.255.255")); @@ -68,12 +83,14 @@ public void test_isLiteralIpAddress_IPv4_ExtraCharacters_Failure() throws Except assertFalse(AddressUtils.isLiteralIpAddress("192.168.2.1%eth0")); } + @Test public void test_isLiteralIpAddress_IPv4_NumbersTooLarge_Failure() throws Exception { assertFalse(AddressUtils.isLiteralIpAddress("256.255.255.255")); assertFalse(AddressUtils.isLiteralIpAddress("255.255.255.256")); assertFalse(AddressUtils.isLiteralIpAddress("192.168.1.260")); } + @Test public void test_isLiteralIpAddress_IPv6_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("::1")); assertTrue(AddressUtils.isLiteralIpAddress("2001:Db8::1")); @@ -85,6 +102,7 @@ public void test_isLiteralIpAddress_IPv6_Success() throws Exception { assertTrue(AddressUtils.isLiteralIpAddress("2001:cdba::3257:9652%int2.3!")); } + @Test public void test_isLiteralIpAddress_IPv6_Failure() throws Exception { assertFalse(AddressUtils.isLiteralIpAddress(":::1")); assertFalse(AddressUtils.isLiteralIpAddress("::11111"));