Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A357418572 for ; Mon, 27 Jul 2015 18:30:07 +0000 (UTC) Received: (qmail 68061 invoked by uid 500); 27 Jul 2015 18:30:04 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 68029 invoked by uid 500); 27 Jul 2015 18:30:04 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 68019 invoked by uid 99); 27 Jul 2015 18:30:04 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2015 18:30:04 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 2146E1911F1 for ; Mon, 27 Jul 2015 18:30:04 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id wAlpFxc-ciad for ; Mon, 27 Jul 2015 18:29:56 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id D51FF23133 for ; Mon, 27 Jul 2015 18:29:56 +0000 (UTC) Received: (qmail 67866 invoked by uid 99); 27 Jul 2015 18:29:56 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Jul 2015 18:29:56 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7CEBBE050A; Mon, 27 Jul 2015 18:29:56 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sbawaskar@apache.org To: commits@geode.incubator.apache.org Date: Mon, 27 Jul 2015 18:29:58 -0000 Message-Id: <917a8fef8fe94b3da122d00d314abe51@git.apache.org> In-Reply-To: <646a02291a2e40fcac0bf7c64631a6b9@git.apache.org> References: <646a02291a2e40fcac0bf7c64631a6b9@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/5] incubator-geode git commit: Add test for GEODE-83 Add test for GEODE-83 Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/b185d5b4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/b185d5b4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/b185d5b4 Branch: refs/heads/develop Commit: b185d5b46b4e815c61b7edb0f7ba64f9627428de Parents: 111d615 Author: Vito Gavrilov Authored: Tue Jul 14 17:13:40 2015 -0700 Committer: Vito Gavrilov Committed: Tue Jul 21 14:32:13 2015 -0700 ---------------------------------------------------------------------- .../gemstone/gemfire/redis/AuthJUnitTest.java | 116 +++++++++++++++++++ 1 file changed, 116 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b185d5b4/gemfire-core/src/test/java/com/gemstone/gemfire/redis/AuthJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/redis/AuthJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/redis/AuthJUnitTest.java new file mode 100644 index 0000000..ece74bb --- /dev/null +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/redis/AuthJUnitTest.java @@ -0,0 +1,116 @@ +package com.gemstone.gemfire.redis; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.util.Random; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import redis.clients.jedis.Jedis; +import redis.clients.jedis.exceptions.JedisDataException; + +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.GemFireCache; +import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; +import com.gemstone.gemfire.internal.AvailablePortHelper; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; + +@Category(IntegrationTest.class) +public class AuthJUnitTest { + + private static final String PASSWORD = "pwd"; + Jedis jedis; + GemFireRedisServer server; + GemFireCache cache; + Random rand; + int port; + + int runs = 150; + + @Before + public void setUp() throws IOException { + rand = new Random(); + port = AvailablePortHelper.getRandomAvailableTCPPort(); + this.jedis = new Jedis("localhost", port, 100000); + } + + @After + public void tearDown() throws InterruptedException { + server.shutdown(); + cache.close(); + } + private void setupCacheWithPassword() { + CacheFactory cf = new CacheFactory(); + cf.set("log-level", "error"); + cf.set("mcast-port", "0"); + cf.set("locators", ""); + cf.set("redis-password", PASSWORD); + cache = cf.create(); + server = new GemFireRedisServer("localhost", port); + server.start(); + } + + @Test + public void testAuthConfig() { + setupCacheWithPassword(); + InternalDistributedSystem iD = (InternalDistributedSystem) cache.getDistributedSystem(); + assert(iD.getConfig().getRedisPassword().equals(PASSWORD)); + } + + @Test + public void testAuthRejectAccept() { + setupCacheWithPassword(); + Exception ex = null; + try { + jedis.auth("wrongpwd"); + } catch (JedisDataException e) { + ex = e; + } + assertNotNull(ex); + + String res = jedis.auth(PASSWORD); + assertEquals(res, "OK"); + } + + @Test + public void testAuthNoPwd() { + CacheFactory cf = new CacheFactory(); + cf.set("log-level", "error"); + cf.set("mcast-port", "0"); + cf.set("locators", ""); + cache = cf.create(); + server = new GemFireRedisServer("localhost", port); + server.start(); + + Exception ex = null; + try { + jedis.auth(PASSWORD); + } catch (JedisDataException e) { + ex = e; + } + assertNotNull(ex); + } + + @Test + public void testAuthAcceptRequests() { + setupCacheWithPassword(); + Exception ex = null; + try { + jedis.set("foo", "bar"); + } catch (JedisDataException e) { + ex = e; + } + assertNotNull(ex); + + String res = jedis.auth(PASSWORD); + assertEquals(res, "OK"); + + jedis.set("foo", "bar"); // No exception + } + +} \ No newline at end of file