Package io.grpc.internal.testing
Class TestUtils
- java.lang.Object
-
- io.grpc.internal.testing.TestUtils
-
public class TestUtils extends java.lang.Object
Internal utility functions useful for writing tests.
-
-
Field Summary
Fields Modifier and Type Field Description private static boolean
conscryptInstallAttempted
static java.lang.String
TEST_SERVER_HOST
-
Constructor Summary
Constructors Modifier Constructor Description private
TestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
installConscryptIfAvailable()
Add Conscrypt to the list of security providers, if it is available.static java.io.File
loadCert(java.lang.String name)
Saves a file from the classpath resources in src/main/resources/certs as a file on the filesystem.static java.security.cert.X509Certificate
loadX509Cert(java.lang.String fileName)
Loads an X.509 certificate from the classpath resources in src/main/resources/certs.static javax.net.ssl.SSLSocketFactory
newSslSocketFactoryForCa(java.security.Provider provider, java.io.File certChainFile)
Creates an SSLSocketFactory which containscertChainFile
as its only root certificate.static java.net.InetSocketAddress
testServerAddress(java.lang.String host, int port)
Creates a newInetSocketAddress
that overrides the host withTEST_SERVER_HOST
.static java.net.InetSocketAddress
testServerAddress(java.net.InetSocketAddress originalSockAddr)
Creates a newInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
.static java.util.List<java.net.InetSocketAddress>
testServerAddresses(java.net.InetSocketAddress... originalSockAddr)
Creates a new list ofInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
.
-
-
-
Field Detail
-
TEST_SERVER_HOST
public static final java.lang.String TEST_SERVER_HOST
- See Also:
- Constant Field Values
-
conscryptInstallAttempted
private static boolean conscryptInstallAttempted
-
-
Method Detail
-
testServerAddress
public static java.net.InetSocketAddress testServerAddress(java.lang.String host, int port)
Creates a newInetSocketAddress
that overrides the host withTEST_SERVER_HOST
.
-
testServerAddress
public static java.net.InetSocketAddress testServerAddress(java.net.InetSocketAddress originalSockAddr)
Creates a newInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
.
-
testServerAddresses
public static java.util.List<java.net.InetSocketAddress> testServerAddresses(java.net.InetSocketAddress... originalSockAddr)
Creates a new list ofInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
.
-
loadCert
public static java.io.File loadCert(java.lang.String name) throws java.io.IOException
Saves a file from the classpath resources in src/main/resources/certs as a file on the filesystem.- Parameters:
name
- name of a file in src/main/resources/certs.- Throws:
java.io.IOException
-
loadX509Cert
public static java.security.cert.X509Certificate loadX509Cert(java.lang.String fileName) throws java.security.cert.CertificateException, java.io.IOException
Loads an X.509 certificate from the classpath resources in src/main/resources/certs.- Parameters:
fileName
- name of a file in src/main/resources/certs.- Throws:
java.security.cert.CertificateException
java.io.IOException
-
installConscryptIfAvailable
public static void installConscryptIfAvailable()
Add Conscrypt to the list of security providers, if it is available. If it appears to be available but fails to load, this method will throw an exception. Since the list of security providers is static, this method does nothing if the provider is not available or succeeded previously.
-
newSslSocketFactoryForCa
public static javax.net.ssl.SSLSocketFactory newSslSocketFactoryForCa(java.security.Provider provider, java.io.File certChainFile) throws java.lang.Exception
Creates an SSLSocketFactory which containscertChainFile
as its only root certificate.- Throws:
java.lang.Exception
-
-