https访问方式修改

This commit is contained in:
lu7213 committed 2026-11-06 21:47:17 -05:00
1 parent 7202f0783a
commit 21a23c9f55
5 files changed
+139 -2

No files matched your search

@@ -3,6 +3,14 @@ package com.ruoyi.system.chain;
import org.junit.Test;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import org.springframework.core.io.DefaultResourceLoader;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
@@ -25,11 +33,45 @@ public class ChainExecutorClientTest {
}
}
@Test
public void loadsLocalExecutorCertificateWithoutChangingGlobalTrust() throws Exception {
Path directory = Files.createTempDirectory("executor-tls-");
Path keys = directory.resolve("server.p12");
Path certificate = directory.resolve("server.pem");
try {
String binary = System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("win")
? "keytool.exe" : "keytool";
Path tool = Paths.get(System.getProperty("java.home"), "bin", binary);
if (!Files.exists(tool)) tool = Paths.get(System.getProperty("java.home"), "..", "bin", binary);
Process generate = new ProcessBuilder(tool.toString(), "-genkeypair", "-alias", "executor", "-keyalg", "RSA",
"-keysize", "2048", "-validity", "1", "-dname", "CN=127.0.0.1", "-ext", "SAN=ip:127.0.0.1",
"-keystore", keys.toString(), "-storetype", "PKCS12", "-storepass", "test-pass-123")
.redirectErrorStream(true).redirectOutput(directory.resolve("generate.log").toFile()).start();
if (!generate.waitFor(30, TimeUnit.SECONDS) || generate.exitValue() != 0) fail("测试证书生成失败");
Process export = new ProcessBuilder(tool.toString(), "-exportcert", "-rfc", "-alias", "executor",
"-keystore", keys.toString(), "-storetype", "PKCS12", "-storepass", "test-pass-123",
"-file", certificate.toString()).redirectErrorStream(true)
.redirectOutput(directory.resolve("export.log").toFile()).start();
if (!export.waitFor(30, TimeUnit.SECONDS) || export.exitValue() != 0) fail("测试证书导出失败");
assertNotNull(ChainExecutorTls.socketFactory(certificate.toUri().toString(), new DefaultResourceLoader()));
} finally {
Files.deleteIfExists(certificate); Files.deleteIfExists(keys);
Files.deleteIfExists(directory.resolve("generate.log")); Files.deleteIfExists(directory.resolve("export.log"));
Files.deleteIfExists(directory);
}
}
@Test(expected = IllegalArgumentException.class)
public void rejectsRemoteCertificateLocation() throws Exception {
ChainExecutorTls.socketFactory("https://untrusted.example/cert.pem", new DefaultResourceLoader());
}
private ChainExecutorClient client(String url) throws Exception {
ChainExecutorClient client = new ChainExecutorClient();
set(client, "enabled", true);
set(client, "url", url);
set(client, "token", "test-only-token-012345678901234567890");
set(client, "tlsCertificateLocation", "");
return client;
}