fix(接口测试): 修复无效证书初始化问题

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2023-11-23 10:56:48 +08:00 committed by Craftsman
parent ac0cc2c4a2
commit 1268b1f8fc
2 changed files with 10 additions and 23 deletions

View File

@ -27,11 +27,6 @@ import org.apache.jorphan.util.JMeterStopTestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* Configure Keystore
*/
@ -105,12 +100,6 @@ public class KeystoreConfig extends ConfigTestElement implements TestBean, TestS
// 加载认证文件
String path = this.getPropertyAsString("MS-KEYSTORE-FILE-PATH");
String password = this.getPropertyAsString("MS-KEYSTORE-FILE-PASSWORD");
InputStream in = null;
try {
in = new FileInputStream(new File(path));
} catch (IOException e) {
log.error(e.getMessage());
}
// 获取请求上的资源ID
String resourceId = this.getPropertyAsString("MS-RESOURCE-ID");
if (StringUtils.isNotBlank(resourceId)) {
@ -124,11 +113,6 @@ public class KeystoreConfig extends ConfigTestElement implements TestBean, TestS
SSLManager.keyMap.put(resourceId, dto);
}
/*SSLManager.getInstance().configureKeystore(Boolean.parseBoolean(preload),
startIndexAsInt,
endIndexAsInt,
clientCertAliasVarName, in, password);*/
}
/**

View File

@ -367,9 +367,6 @@ public abstract class SSLManager {
* @return the singleton {@link SSLManager}
*/
public static synchronized SSLManager getInstance() {
if (null == SSLManager.manager) {
SSLManager.manager = new JsseSSLManager(null);
}
try {
// 重新加载认证文件
JMeterContext threadContext = JMeterContextService.getContext();
@ -381,16 +378,22 @@ public abstract class SSLManager {
SSLManager.manager = new JsseSSLManager(null);
SSLManager.manager.keyStore = null;
// 加载认证文件
InputStream in = new FileInputStream(new File(dto.getPath()));
SSLManager.manager.configureKeystore(Boolean.parseBoolean(dto.getPreload()), dto.getStartIndex(),
dto.getEndIndex(), dto.getClientCertAliasVarName(), in, dto.getPwd());
log.info("加载认证文件完成 {}", resourceId);
try (InputStream in = new FileInputStream(new File(dto.getPath()))) {
SSLManager.manager.configureKeystore(Boolean.parseBoolean(dto.getPreload()), dto.getStartIndex(),
dto.getEndIndex(), dto.getClientCertAliasVarName(), in, dto.getPwd());
log.info("加载认证文件完成 {}", resourceId);
}
}
}
} catch (Exception e) {
log.error("证书处理失败{}", e.getMessage());
}
// 初始化证书对象
if (null == SSLManager.manager) {
SSLManager.manager = new JsseSSLManager(null);
}
return SSLManager.manager;
}