Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move AddressUtilsTest to JUnit4 #1249

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions openjdk/src/test/java/org/conscrypt/AddressUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand All @@ -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"));
Expand Down
Loading