You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2019/09/12 09:04:56 UTC

[GitHub] [ignite] Jokser commented on a change in pull request #6799: IGNITE-11094 Add SSL support for ignite zookeeper SPI

Jokser commented on a change in pull request #6799: IGNITE-11094 Add SSL support for ignite zookeeper SPI
URL: https://github.com/apache/ignite/pull/6799#discussion_r323631399
 
 

 ##########
 File path: modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSslTest.java
 ##########
 @@ -0,0 +1,109 @@
+/*
+ * 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.ignite.spi.discovery.zk.internal;
+
+import java.nio.file.Paths;
+import java.util.function.Function;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+/**
+ * Base class for Zookeeper SPI discovery tests in this package. It is intended to provide common overrides for
+ * superclass methods to be shared by all subclasses.
+ */
+public class ZookeeperDiscoverySpiSslTest extends ZookeeperDiscoverySpiTestBase {
+    /** Ignite home. */
+    private static final String IGNITE_HOME = U.getIgniteHome();
+
+    /** Resource path. */
+    private static final Function<String, String> rsrcPath = rsrc -> Paths.get(
+        IGNITE_HOME == null ? "." : IGNITE_HOME,
+        "modules",
+        "core",
+        "src",
+        "test",
+        "resources",
+        rsrc
+    ).toString();
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        sslEnabled = true;
+
+        setupSystemProperties();
+
+        super.beforeTest();
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    @Test
+    public void testIgniteSsl() throws Exception {
+        System.setProperty("zookeeper.clientCnxnSocket", "org.apache.zookeeper.ClientCnxnSocketNetty");
+
+        IgniteEx ignite = startGrids(2);
+
+        assertEquals(2, ignite.cluster().topologyVersion());
+    }
+
+    /**
+     * @throws Exception if failed.
+     */
+    @Test
+    public void testIgniteNoSsl() throws Exception {
+        sslEnabled = false;
+
+        System.setProperty("zookeeper.clientCnxnSocket", "org.apache.zookeeper.ClientCnxnSocketNetty");
+
+        GridTestUtils.assertThrowsAnyCause(log,
+            () -> startGrids(2),
+            IgniteCheckedException.class,
+            "Failed to start SPI: ZookeeperDiscoverySpi");
+    }
+
+    /**
+     * Setup system properties.
+     */
+    private void setupSystemProperties() {
+        System.setProperty("zookeeper.serverCnxnFactory", "org.apache.zookeeper.server.NettyServerCnxnFactory");
+        System.setProperty("zookeeper.client.secure", "true");
+        System.setProperty("zookeeper.ssl.keyStore.location", rsrcPath.apply("/server.jks"));
+        System.setProperty("zookeeper.ssl.keyStore.password", "123456");
+        System.setProperty("zookeeper.ssl.trustStore.location", rsrcPath.apply("/trust.jks"));
+        System.setProperty("zookeeper.ssl.trustStore.password", "123456");
+        System.setProperty("zookeeper.ssl.hostnameVerification", "false");
+    }
+
+    /**
+     * Cleanup system properties.
+     */
+    private void clearSystemProperties() {
+        System.setProperty("zookeeper.clientCnxnSocket", "");
 
 Review comment:
   System.clearProperty can be used instead.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services