Skip to content

Commit

Permalink
fix(接口测试): 修复无效证书初始化问题
Browse files Browse the repository at this point in the history
Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
  • Loading branch information
fit2-zhao committed Nov 23, 2023
1 parent ac0cc2c commit 1268b1f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
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
*/
Expand Down Expand Up @@ -105,12 +100,6 @@ public void testStarted(String host) {
// 加载认证文件
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)) {
Expand All @@ -124,11 +113,6 @@ public void testStarted(String host) {
SSLManager.keyMap.put(resourceId, dto);
}

/*SSLManager.getInstance().configureKeystore(Boolean.parseBoolean(preload),
startIndexAsInt,
endIndexAsInt,
clientCertAliasVarName, in, password);*/

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,6 @@ protected 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();
Expand All @@ -381,16 +378,22 @@ public static synchronized SSLManager getInstance() {
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;
}

Expand Down

0 comments on commit 1268b1f

Please sign in to comment.