test: 添加证书编号

main
13009 2024-06-18 17:59:39 +08:00
parent bbf70c87ea
commit 23d682431d
4 changed files with 27 additions and 211 deletions

View File

@ -14,6 +14,9 @@ public interface Signer {
*/
SignatureResult sign(String message);
/**
* @return
*/
String getCertificateSerial();
/**

View File

@ -14,4 +14,9 @@ public interface Validator {
*
*/
void validate(HttpRequest request, OriginalResponse response, Channel channel);
/**
*
*/
void validate(HttpRequest newRequest);
}

View File

@ -1,5 +1,6 @@
package com.czcb.scfs.api.core.cipher;
import com.czcb.scfs.api.core.Channel;
import com.czcb.scfs.api.core.DefaultChannel;
import com.czcb.scfs.api.core.KeyText;
import com.czcb.scfs.api.core.Profile;
@ -95,7 +96,9 @@ class DefaultValidatorTest {
.statusCode(200)
.build();
defaultValidator.isInvalidHttpCode(response);
Assertions.assertDoesNotThrow(() -> {
defaultValidator.isInvalidHttpCode(response);
});
}
@Test
@ -240,10 +243,12 @@ class DefaultValidatorTest {
.statusCode(200)
.build();
ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, new DefaultChannel.Builder()
Channel channel = new DefaultChannel.Builder()
.channelNo("1010")
.appNo("1111")
.build()));
.build();
ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, channel));
Assertions.assertEquals("校验失败, 签名[X-SCFS-Signature]不存在, Request-Id=123456789, HttpResponseBody=123", validationException.getLocalizedMessage());
}
@ -265,10 +270,12 @@ class DefaultValidatorTest {
.statusCode(200)
.build();
ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, new DefaultChannel.Builder()
Channel channel = new DefaultChannel.Builder()
.channelNo("1010")
.appNo("1111")
.build()));
.build();
ValidationException validationException = Assertions.assertThrows(ValidationException.class, () -> defaultValidator.validateResponseSignature(response, channel));
Assertions.assertEquals("校验失败, 签名[X-SCFS-Signature=MTIzNDU2Nzg5]校验未通过, Request-Id=123456789, HttpResponseBody=123", validationException.getLocalizedMessage());
}

View File

@ -2,6 +2,7 @@ package com.czcb.scfs.spring.boot.starter;
import com.czcb.scfs.api.core.cipher.StoreType;
import com.czcb.scfs.api.core.http.LogLevel;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.HashMap;
@ -12,6 +13,7 @@ import java.util.Map;
* @author wangwei
* @since 2.0.0
*/
@Data
@ConfigurationProperties(prefix = "scfs.api-gateway")
public class ScfsApiGatewayProperties {
/**
@ -38,46 +40,7 @@ public class ScfsApiGatewayProperties {
*/
private Httpclient httpclient = new Httpclient();
public Boolean getOnline() {
return online;
}
public void setOnline(Boolean online) {
this.online = online;
}
public String getHost() {
return host;
}
public Channel getChannel() {
return channel;
}
public void setChannel(Channel channel) {
this.channel = channel;
}
public void setHost(String host) {
this.host = host;
}
public Httpclient getHttpclient() {
return httpclient;
}
public void setHttpclient(Httpclient httpclient) {
this.httpclient = httpclient;
}
public Cipher getCipher() {
return cipher;
}
public void setCipher(Cipher cipher) {
this.cipher = cipher;
}
@Data
public static class Channel {
/**
*
@ -89,23 +52,9 @@ public class ScfsApiGatewayProperties {
*/
private String appNo;
public String getChannelNo() {
return channelNo;
}
public void setChannelNo(String channelNo) {
this.channelNo = channelNo;
}
public String getAppNo() {
return appNo;
}
public void setAppNo(String appNo) {
this.appNo = appNo;
}
}
@Data
public static class Cipher {
/**
* ()
@ -126,39 +75,9 @@ public class ScfsApiGatewayProperties {
*/
private List<String> certificate;
public StoreType getStoreType() {
return storeType;
}
public void setStoreType(StoreType storeType) {
this.storeType = storeType;
}
public String getChannelPrivateKey() {
return channelPrivateKey;
}
public void setChannelPrivateKey(String channelPrivateKey) {
this.channelPrivateKey = channelPrivateKey;
}
public String getChannelCertificateSerial() {
return channelCertificateSerial;
}
public void setChannelCertificateSerial(String channelCertificateSerial) {
this.channelCertificateSerial = channelCertificateSerial;
}
public List<String> getCertificate() {
return certificate;
}
public void setCertificate(List<String> certificate) {
this.certificate = certificate;
}
}
@Data
public static class Httpclient {
/**
* basic
@ -184,46 +103,7 @@ public class ScfsApiGatewayProperties {
*/
private Map<String, String> headers = new HashMap<>();
public LogLevel getLogLevel() {
return logLevel;
}
public void setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
}
public Boolean getCompressionEnabled() {
return compressionEnabled;
}
public void setCompressionEnabled(Boolean compressionEnabled) {
this.compressionEnabled = compressionEnabled;
}
public ConnPool getConnPool() {
return connPool;
}
public void setConnPool(ConnPool connPool) {
this.connPool = connPool;
}
public Proxy getProxy() {
return proxy;
}
public void setProxy(Proxy proxy) {
this.proxy = proxy;
}
public Map<String, String> getHeaders() {
return headers;
}
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
@Data
public static class Proxy {
/**
*
@ -250,56 +130,9 @@ public class ScfsApiGatewayProperties {
* http
*/
private String scheme = "http";
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getPort() {
return port;
}
public void setPort(String port) {
this.port = port;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getScheme() {
return scheme;
}
public void setScheme(String scheme) {
this.scheme = scheme;
}
}
@Data
public static class ConnPool {
/**
*
@ -317,38 +150,6 @@ public class ScfsApiGatewayProperties {
* socket 60
*/
private Integer socketTimeout = 60;
public int getMaxRequests() {
return maxRequests;
}
public void setMaxRequests(Integer maxRequests) {
this.maxRequests = maxRequests;
}
public int getMaxRequestPerHost() {
return maxRequestPerHost;
}
public void setMaxRequestPerHost(Integer maxRequestPerHost) {
this.maxRequestPerHost = maxRequestPerHost;
}
public Integer getConnectTimeout() {
return connectTimeout;
}
public void setConnectTimeout(Integer connectTimeout) {
this.connectTimeout = connectTimeout;
}
public Integer getSocketTimeout() {
return socketTimeout;
}
public void setSocketTimeout(Integer socketTimeout) {
this.socketTimeout = socketTimeout;
}
}
}
}