mirror of https://github.com/grpc/grpc-java.git
Move TLS certificates.
- Move certificates to src/main/resources folder. - Update the code that loads the certificates to make use of Java's resources API.
This commit is contained in:
parent
303482ad3c
commit
44574944b9
|
|
@ -216,10 +216,8 @@ public class TestServiceClient {
|
|||
SslContext sslContext = null;
|
||||
if (useTestCa) {
|
||||
try {
|
||||
String dir = "integration-testing/certs";
|
||||
sslContext = SslContext.newClientContext(
|
||||
new File(dir + "/ca.pem"));
|
||||
} catch (SSLException ex) {
|
||||
sslContext = SslContext.newClientContext(Util.loadCert("ca.pem"));
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,10 +134,8 @@ public class TestServiceServer {
|
|||
executor = Executors.newSingleThreadScheduledExecutor();
|
||||
SslContext sslContext = null;
|
||||
if (useTls) {
|
||||
String dir = "integration-testing/certs";
|
||||
sslContext = SslContext.newServerContext(
|
||||
new File(dir + "/server1.pem"),
|
||||
new File(dir + "/server1.key"));
|
||||
sslContext = SslContext.newServerContext(Util.loadCert("server1.pem"),
|
||||
Util.loadCert("server1.key"));
|
||||
}
|
||||
server = NettyServerBuilder.forPort(port)
|
||||
.sslContext(sslContext)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,12 @@ import io.grpc.proto.ProtoUtils;
|
|||
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -54,9 +59,8 @@ public class Util {
|
|||
* Picks an unused port.
|
||||
*/
|
||||
public static int pickUnusedPort() {
|
||||
ServerSocket serverSocket = null;
|
||||
try {
|
||||
serverSocket = new ServerSocket(0);
|
||||
ServerSocket serverSocket = new ServerSocket(0);
|
||||
int port = serverSocket.getLocalPort();
|
||||
serverSocket.close();
|
||||
return port;
|
||||
|
|
@ -65,6 +69,29 @@ public class Util {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a file from the resources folder.
|
||||
*
|
||||
* @param name name of a file in src/main/resources/certs.
|
||||
*/
|
||||
public static File loadCert(String name) throws IOException {
|
||||
InputStream in = Util.class.getResourceAsStream("/certs/" + name);
|
||||
File tmpFile = File.createTempFile(name, "");
|
||||
tmpFile.deleteOnExit();
|
||||
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(tmpFile));
|
||||
try {
|
||||
int b;
|
||||
while ((b = in.read()) != -1) {
|
||||
writer.write(b);
|
||||
}
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
return tmpFile;
|
||||
}
|
||||
|
||||
public static void assertEquals(MessageLite expected, MessageLite actual) {
|
||||
if (expected == null || actual == null) {
|
||||
Assert.assertEquals(expected, actual);
|
||||
|
|
|
|||
Loading…
Reference in New Issue