Package io.grpc.internal.testing
Class TestUtils
java.lang.Object
io.grpc.internal.testing.TestUtils
Internal utility functions useful for writing tests.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Add Conscrypt to the list of security providers, if it is available.static File
Saves a file from the classpath resources in src/main/resources/certs as a file on the filesystem.static X509Certificate
loadX509Cert
(String fileName) Loads an X.509 certificate from the classpath resources in src/main/resources/certs.static SSLSocketFactory
newSslSocketFactoryForCa
(Provider provider, File certChainFile) Creates an SSLSocketFactory which containscertChainFile
as its only root certificate.static InetSocketAddress
testServerAddress
(String host, int port) Creates a newInetSocketAddress
that overrides the host withTEST_SERVER_HOST
.static InetSocketAddress
testServerAddress
(InetSocketAddress originalSockAddr) Creates a newInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
.static List
<InetSocketAddress> testServerAddresses
(InetSocketAddress... originalSockAddr) Creates a new list ofInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
.
-
Field Details
-
TEST_SERVER_HOST
- See Also:
-
conscryptInstallAttempted
private static boolean conscryptInstallAttempted
-
-
Constructor Details
-
TestUtils
private TestUtils()
-
-
Method Details
-
testServerAddress
Creates a newInetSocketAddress
that overrides the host withTEST_SERVER_HOST
. -
testServerAddress
Creates a newInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
. -
testServerAddresses
Creates a new list ofInetSocketAddress
on localhost that overrides the host withTEST_SERVER_HOST
. -
loadCert
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:
IOException
-
loadX509Cert
public static X509Certificate loadX509Cert(String fileName) throws CertificateException, 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:
CertificateException
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 SSLSocketFactory newSslSocketFactoryForCa(Provider provider, File certChainFile) throws Exception Creates an SSLSocketFactory which containscertChainFile
as its only root certificate.- Throws:
Exception
-