|
20 | 20 | import io.grpc.netty.shaded.io.netty.buffer.ByteBuf; |
21 | 21 | import io.grpc.netty.shaded.io.netty.buffer.Unpooled; |
22 | 22 | import io.grpc.netty.shaded.io.netty.handler.codec.haproxy.HAProxyTLV; |
23 | | -import java.net.URISyntaxException; |
| 23 | +import java.io.File; |
| 24 | +import java.io.IOException; |
| 25 | +import java.io.InputStream; |
24 | 26 | import java.nio.charset.StandardCharsets; |
25 | | -import java.nio.file.Paths; |
| 27 | +import java.nio.file.Files; |
| 28 | +import java.nio.file.StandardCopyOption; |
26 | 29 | import org.apache.rocketmq.proxy.config.ConfigurationManager; |
27 | 30 | import org.apache.rocketmq.proxy.config.ProxyConfig; |
28 | 31 | import org.junit.After; |
@@ -78,17 +81,21 @@ public void testLoadSslContextWithWrongPassword() throws Exception { |
78 | 81 | ProxyAndTlsProtocolNegotiator.loadSslContext(); |
79 | 82 | } |
80 | 83 |
|
81 | | - private void configureTls(String keyFile, String certFile, String password) throws URISyntaxException { |
| 84 | + private void configureTls(String keyFile, String certFile, String password) throws IOException { |
82 | 85 | ProxyConfig proxyConfig = ConfigurationManager.getProxyConfig(); |
83 | 86 | proxyConfig.setTlsTestModeEnable(false); |
84 | 87 | proxyConfig.setTlsKeyPath(getCertsPath(keyFile)); |
85 | 88 | proxyConfig.setTlsCertPath(getCertsPath(certFile)); |
86 | 89 | proxyConfig.setTlsKeyPassword(password); |
87 | 90 | } |
88 | 91 |
|
89 | | - private static String getCertsPath(String fileName) throws URISyntaxException { |
90 | | - return Paths.get(ProxyAndTlsProtocolNegotiatorTest.class |
91 | | - .getClassLoader().getResource("certs/" + fileName).toURI()) |
92 | | - .toAbsolutePath().toString(); |
| 92 | + private static String getCertsPath(String fileName) throws IOException { |
| 93 | + File tempFile = File.createTempFile(fileName, null); |
| 94 | + tempFile.deleteOnExit(); |
| 95 | + try (InputStream is = ProxyAndTlsProtocolNegotiatorTest.class |
| 96 | + .getClassLoader().getResourceAsStream("certs/" + fileName)) { |
| 97 | + Files.copy(is, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); |
| 98 | + } |
| 99 | + return tempFile.getAbsolutePath(); |
93 | 100 | } |
94 | 101 | } |
0 commit comments