From b2fcbc31d1a0e7ed47a358ba438e2278386546d3 Mon Sep 17 00:00:00 2001 From: 13009 Date: Tue, 20 Feb 2024 18:04:19 +0800 Subject: [PATCH] =?UTF-8?q?jacoco=20=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/core/cipher/DefaultSignatureTest.java | 30 ++++++++++ .../api/core/http/DefaultHttpProfileTest.java | 55 +++++++++++++++++++ .../scfs/api/core/http/HttpResponseTest.java | 31 +++++++++++ .../czcb/scfs/api/core/http/ProxyTest.java | 12 ++++ .../scfs/api/core/http/client/TestSigner.java | 2 +- .../api/core/http/client/TestVerifier.java | 2 +- 6 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultSignatureTest.java create mode 100644 scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/DefaultHttpProfileTest.java diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultSignatureTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultSignatureTest.java new file mode 100644 index 0000000..ae4e4dd --- /dev/null +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/cipher/DefaultSignatureTest.java @@ -0,0 +1,30 @@ +package com.czcb.scfs.api.core.cipher; + +import com.czcb.scfs.api.core.KeyText; +import com.czcb.scfs.api.core.http.client.TestSigner; +import com.czcb.scfs.api.core.http.client.TestVerifier; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.List; + +class DefaultSignatureTest { + + @Test + void getCertificateProvider() { + List certificates = new ArrayList<>(); + certificates.add(KeyText.loadTestRSA()); + CertificateProvider provider = new LocalCertificateProvider(certificates); + + Signer signer = new TestSigner(KeyText.loadTestPrivateKeyRSA()); + Verifier verifier = new TestVerifier(provider); + DefaultSignature signature = new DefaultSignature(provider, signer, verifier); + + Assertions.assertNotNull(signature.getCertificateProvider()); + Assertions.assertNotNull(signature.getSigner()); + Assertions.assertNotNull(signature.getCredential()); + Assertions.assertNotNull(signature.getVerifier()); + } +} \ No newline at end of file diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/DefaultHttpProfileTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/DefaultHttpProfileTest.java new file mode 100644 index 0000000..67ebca2 --- /dev/null +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/DefaultHttpProfileTest.java @@ -0,0 +1,55 @@ +package com.czcb.scfs.api.core.http; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +class DefaultHttpProfileTest { + + @Test + void getHeaders() { + Map data = new HashMap<>(); + data.put("key", "123456"); + DefaultHttpProfile httpProfile = new DefaultHttpProfile.Builder() + .headers(data) + .compressionEnabled(true) + .online(true) + .logEnabled(true) + .host("http://10.133.129.74:8761/") + .build(); + + Assertions.assertNotNull(httpProfile.getHeaders()); + Assertions.assertEquals("123456", httpProfile.getHeaders().get("key")); + Assertions.assertEquals("http://10.133.129.74:8761/", httpProfile.getHost()); + + Assertions.assertTrue(httpProfile.compressionEnabled()); + Assertions.assertTrue(httpProfile.online()); + Assertions.assertTrue(httpProfile.logEnabled()); + } + + @Test + void getConnPool() { + DefaultHttpProfile httpProfile = new DefaultHttpProfile.Builder() + .connPool(new ConnPool.Builder() + .connectTimeout(10002) + .build()) + .build(); + + Assertions.assertNotNull(httpProfile.getConnPool()); + Assertions.assertEquals(10002, httpProfile.getConnPool().getConnectTimeout()); + } + + @Test + void getProxy() { + DefaultHttpProfile httpProfile = new DefaultHttpProfile.Builder() + .proxy(new Proxy.Builder() + .host("192.168.0.11") + .build()) + .build(); + + Assertions.assertNotNull(httpProfile.getProxy()); + Assertions.assertEquals("192.168.0.11", httpProfile.getProxy().getHost()); + } +} \ No newline at end of file diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/HttpResponseTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/HttpResponseTest.java index cbbd51f..382a08e 100644 --- a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/HttpResponseTest.java +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/HttpResponseTest.java @@ -85,4 +85,35 @@ class HttpResponseTest { Assertions.assertArrayEquals("123456".getBytes(StandardCharsets.UTF_8), httpResponse.getOriginalBody()); } + + @Test + void getServiceResponse() { + HttpResponse httpResponse = new HttpResponse.Builder() + .originalResponse(new OriginalResponse.Builder() + .request(new HttpRequest.Builder() + .httpMethod(HttpMethod.POST) + .url("/xx") + .headers(new HttpHeaders()) + .build()) + .build()) + .originalBody("123456") + .build(); + + Assertions.assertArrayEquals("123456".getBytes(StandardCharsets.UTF_8), httpResponse.getOriginalBody()); + + httpResponse = new HttpResponse.Builder() + .originalResponse(new OriginalResponse.Builder() + .request(new HttpRequest.Builder() + .httpMethod(HttpMethod.POST) + .url("/xx") + .headers(new HttpHeaders()) + .body(new EncryptRequestBody.Builder().build()) + .build()) + .build()) + .serviceResponseType(null) + .originalBody("123456") + .build(); + + Assertions.assertTrue(httpResponse.getResponseBody() instanceof UnkownResponseBody); + } } \ No newline at end of file diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/ProxyTest.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/ProxyTest.java index 2f318cf..52ba7cf 100644 --- a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/ProxyTest.java +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/ProxyTest.java @@ -20,6 +20,17 @@ class ProxyTest { assertThatJson("{\"enabled\":true,\"host\":\"123\",\"port\":\"1000\",\"username\":\"name\",\"password\":\"123\",\"scheme\":\"http\"}") .isEqualTo(proxy); + + proxy = new Proxy.Builder() + .port("1000") + .disabled() + .username("name") + .password("123") + .host("123") + .build(); + + assertThatJson("{\"enabled\":false,\"host\":\"123\",\"port\":\"1000\",\"username\":\"name\",\"password\":\"123\",\"scheme\":\"http\"}") + .isEqualTo(proxy); } @Test @@ -72,4 +83,5 @@ class ProxyTest { .build(); Assertions.assertEquals("https", proxy.getScheme()); } + } \ No newline at end of file diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestSigner.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestSigner.java index 4256dfc..995e787 100644 --- a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestSigner.java +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestSigner.java @@ -13,7 +13,7 @@ public class TestSigner extends AbstractSigner { /** * @param privateKey API私钥 */ - protected TestSigner(PrivateKey privateKey) { + public TestSigner(PrivateKey privateKey) { super("SHA256withRSA", "SHA256withRSA", privateKey, null); } } diff --git a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestVerifier.java b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestVerifier.java index bece6df..381ef38 100644 --- a/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestVerifier.java +++ b/scfs-api-core/src/test/java/com/czcb/scfs/api/core/http/client/TestVerifier.java @@ -11,7 +11,7 @@ public class TestVerifier extends AbstractVerifier { /** * @param certificateProvider 验签使用的证书管理器,非空 */ - protected TestVerifier(CertificateProvider certificateProvider) { + public TestVerifier(CertificateProvider certificateProvider) { super("SHA256withRSA", certificateProvider, null); } }