Skip to content

Commit

Permalink
Merge branch 'master' into scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
prbprbprb authored Oct 28, 2024
2 parents fcf9e94 + 6e1d23a commit bdf57f4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
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
10 changes: 8 additions & 2 deletions openjdk/src/test/java/org/conscrypt/NativeRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@

package org.conscrypt;

import junit.framework.TestCase;
import static org.junit.Assert.fail;

public class NativeRefTest extends TestCase {
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class NativeRefTest {
@Test
public void test_zeroContextThrowsNullPointException() {
try {
new NativeRef(0) {
Expand Down
11 changes: 9 additions & 2 deletions openjdk/src/test/java/org/conscrypt/OpenSSLKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

package org.conscrypt;

import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

import junit.framework.TestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

public class OpenSSLKeyTest extends TestCase {
@RunWith(JUnit4.class)
public class OpenSSLKeyTest {
static final String RSA_PUBLIC_KEY =
"-----BEGIN PUBLIC KEY-----\n" +
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3G7PGpfZx68wTY9eLb4b\n" +
Expand Down Expand Up @@ -84,6 +89,7 @@ public class OpenSSLKeyTest extends TestCase {
"13e6825df950a3bd4509f9d3b12da304fe5b00c443ff33326b8bfb3fe111fd4b" +
"8872822c7f2832dafa0fe10d9aba22310849e978e51c8aa9da7bc1c07511d883", 16);

@Test
public void test_fromPublicKeyPemInputStream() throws Exception {
ByteArrayInputStream is = new ByteArrayInputStream(RSA_PUBLIC_KEY.getBytes(StandardCharsets.UTF_8));
OpenSSLKey key = OpenSSLKey.fromPublicKeyPemInputStream(is);
Expand All @@ -92,6 +98,7 @@ public void test_fromPublicKeyPemInputStream() throws Exception {
assertEquals(RSA_PUBLIC_EXPONENT, publicKey.getPublicExponent());
}

@Test
public void test_fromPrivateKeyPemInputStream() throws Exception {
ByteArrayInputStream is = new ByteArrayInputStream(RSA_PRIVATE_KEY.getBytes(StandardCharsets.UTF_8));
OpenSSLKey key = OpenSSLKey.fromPrivateKeyPemInputStream(is);
Expand Down

0 comments on commit bdf57f4

Please sign in to comment.