geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbawas...@apache.org
Subject [3/5] incubator-geode git commit: Add test for GEODE-83
Date Mon, 27 Jul 2015 18:29:58 GMT
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 <vgavrilov@pivotal.io>
Authored: Tue Jul 14 17:13:40 2015 -0700
Committer: Vito Gavrilov <vgavrilov@pivotal.io>
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


Mime
View raw message