You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ni...@apache.org on 2018/05/09 09:24:32 UTC
[incubator-servicecomb-saga] 01/05: SCB-342 Updated the
AlphaIntegrationTest with and without SSL
This is an automated email from the ASF dual-hosted git repository.
ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
commit 2af03977969e33f050f0c336e1b8706a375e4456
Author: Willem Jiang <ji...@huawei.com>
AuthorDate: Wed May 9 10:18:36 2018 +0800
SCB-342 Updated the AlphaIntegrationTest with and without SSL
---
.../saga/alpha/server/GrpcServerConfig.java | 8 +--
.../saga/alpha/server/GrpcStartable.java | 3 +-
.../saga/alpha/server/AlphaIntegrationTest.java | 40 +++---------
.../alpha/server/AlphaIntegrationWithSSLTest.java | 72 ++++++++++++++++++++++
4 files changed, 87 insertions(+), 36 deletions(-)
diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java
index ec4d3b1..c14cd0c 100644
--- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java
+++ b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java
@@ -29,7 +29,7 @@ public class GrpcServerConfig {
private int port;
@Value("${alpha.server.ssl.enable:false}")
- private boolean enable;
+ private boolean sslEnable;
@Value("${alpha.server.ssl.cert:server.cert}")
private String cert;
@@ -37,7 +37,7 @@ public class GrpcServerConfig {
@Value("${alpha.server.ssl.key:server.key}")
private String key;
- @Value("${alpha.server.ssl.enable:false}")
+ @Value("${alpha.server.ssl.sslEnable:false}")
private boolean mutalAuth;
@Value("${alpha.server.ssl.clientCert:client.cert}")
@@ -51,8 +51,8 @@ public class GrpcServerConfig {
return port;
}
- public boolean isEnable() {
- return enable;
+ public boolean isSslEnable() {
+ return sslEnable;
}
public String getCert() {
diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcStartable.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcStartable.java
index 803cd2d..9a2133c 100644
--- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcStartable.java
+++ b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcStartable.java
@@ -25,7 +25,6 @@ import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.net.InetSocketAddress;
import java.util.Arrays;
-import java.util.List;
import java.util.Properties;
import javax.net.ssl.SSLException;
@@ -49,7 +48,7 @@ class GrpcStartable implements ServerStartable {
GrpcStartable(GrpcServerConfig serverConfig, BindableService... services) {
ServerBuilder<?> serverBuilder;
- if (serverConfig.isEnable()){
+ if (serverConfig.isSslEnable()){
serverBuilder = NettyServerBuilder.forAddress(
new InetSocketAddress(serverConfig.getHost(), serverConfig.getPort()));
diff --git a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java
index 45b268b..aa0036f 100644
--- a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java
+++ b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java
@@ -65,6 +65,7 @@ import org.hamcrest.core.Is;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -74,30 +75,21 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.google.protobuf.ByteString;
import io.grpc.ManagedChannel;
-import io.grpc.ManagedChannelBuilder;
-import io.grpc.netty.GrpcSslContexts;
-import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.stub.StreamObserver;
-import io.netty.handler.ssl.SslContext;
-import io.netty.handler.ssl.SslContextBuilder;
-import io.netty.handler.ssl.SslProvider;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {AlphaApplication.class, AlphaConfig.class},
properties = {
"alpha.server.host=0.0.0.0",
- "alpha.server.port=8090", "alpha.event.pollingInterval=1",
- "alpha.server.ssl.enable=true", "alpha.server.ssl.cert=src/test/resources/server.crt",
- "alpha.server.ssl.key=src/test/resources/server.pem", "alpha.server.ssl.enableMutualAuth=true",
- "alpha.server.ssl.clientCert=src/test/resources/client.crt"})
+ "alpha.server.ssl.enable=false",
+ "alpha.server.port=8090",
+ "alpha.event.pollingInterval=1"
+ })
public class AlphaIntegrationTest {
private static final int port = 8090;
- private static final ManagedChannel clientChannel = NettyChannelBuilder.forAddress("localhost", port)
- .negotiationType(NegotiationType.TLS)
- .sslContext(getSslContext())
- .build();
+ protected static ManagedChannel clientChannel;
private final TxEventServiceStub asyncStub = TxEventServiceGrpc.newStub(clientChannel);
private final TxEventServiceBlockingStub blockingStub = TxEventServiceGrpc.newBlockingStub(clientChannel);
@@ -150,23 +142,11 @@ public class AlphaIntegrationTest {
private final CompensationStreamObserver compensateResponseObserver = new CompensationStreamObserver(
this::onCompensation);
- private static SslContext getSslContext(){
- ClassLoader classLoader = AlphaIntegrationTest.class.getClassLoader();
- SslContext sslContext = null;
- try {
- sslContext = GrpcSslContexts.forClient().sslProvider(SslProvider.OPENSSL)
- .protocols("TLSv1.2","TLSv1.1")
- .ciphers(Arrays.asList("ECDHE-RSA-AES128-GCM-SHA256",
- "ECDHE-RSA-AES256-GCM-SHA384",
- "ECDHE-ECDSA-AES128-SHA256"))
- .trustManager(new File(classLoader.getResource("ca.crt").getFile()))
- .keyManager(new File(classLoader.getResource("client.crt").getFile()),
- new File(classLoader.getResource("client.pem").getFile())).build();
- } catch (SSLException e) {
- e.printStackTrace();
- }
- return sslContext;
+ @BeforeClass
+ public static void setupClientChannel() throws Exception {
+ clientChannel = NettyChannelBuilder.forAddress("localhost", port).usePlaintext().build();
}
+
@AfterClass
public static void tearDown() throws Exception {
clientChannel.shutdown();
diff --git a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationWithSSLTest.java b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationWithSSLTest.java
new file mode 100644
index 0000000..5c05d18
--- /dev/null
+++ b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationWithSSLTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.servicecomb.saga.alpha.server;
+
+import java.io.File;
+import java.util.Arrays;
+import javax.net.ssl.SSLException;
+
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import io.grpc.netty.GrpcSslContexts;
+import io.grpc.netty.NegotiationType;
+import io.grpc.netty.NettyChannelBuilder;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslProvider;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = {AlphaApplication.class, AlphaConfig.class},
+ properties = {
+ "alpha.server.host=0.0.0.0",
+ "alpha.server.port=8090", "alpha.event.pollingInterval=1",
+ "alpha.server.ssl.enable=true", "alpha.server.ssl.cert=src/test/resources/server.crt",
+ "alpha.server.ssl.key=src/test/resources/server.pem", "alpha.server.ssl.enableMutualAuth=true",
+ "alpha.server.ssl.clientCert=src/test/resources/client.crt"})
+public class AlphaIntegrationWithSSLTest extends AlphaIntegrationTest {
+ private static final int port = 8090;
+
+ @BeforeClass
+ public static void setupClientChannel() throws Exception {
+ clientChannel = NettyChannelBuilder.forAddress("localhost", port)
+ .negotiationType(NegotiationType.TLS)
+ .sslContext(getSslContext())
+ .build();
+ }
+
+ private static SslContext getSslContext(){
+ ClassLoader classLoader = AlphaIntegrationWithSSLTest.class.getClassLoader();
+ SslContext sslContext = null;
+ try {
+ sslContext = GrpcSslContexts.forClient().sslProvider(SslProvider.OPENSSL)
+ .protocols("TLSv1.2","TLSv1.1")
+ .ciphers(Arrays.asList("ECDHE-RSA-AES128-GCM-SHA256",
+ "ECDHE-RSA-AES256-GCM-SHA384",
+ "ECDHE-ECDSA-AES128-SHA256"))
+ .trustManager(new File(classLoader.getResource("ca.crt").getFile()))
+ .keyManager(new File(classLoader.getResource("client.crt").getFile()),
+ new File(classLoader.getResource("client.pem").getFile())).build();
+ } catch (SSLException e) {
+ e.printStackTrace();
+ }
+ return sslContext;
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
ningjiang@apache.org.