You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2016/03/02 22:22:11 UTC
incubator-geode git commit: GEODE-17: Clean up some tests with better
matchers
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-17-2 406a80f80 -> ca89bcc05
GEODE-17: Clean up some tests with better matchers
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/ca89bcc0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/ca89bcc0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/ca89bcc0
Branch: refs/heads/feature/GEODE-17-2
Commit: ca89bcc05320e35db0b3a371e5d8d369d373af63
Parents: 406a80f
Author: Jens Deppe <jd...@pivotal.io>
Authored: Wed Mar 2 13:21:45 2016 -0800
Committer: Jens Deppe <jd...@pivotal.io>
Committed: Wed Mar 2 13:21:45 2016 -0800
----------------------------------------------------------------------
.../management/DistributedSystemMXBean.java | 1 -
.../internal/cli/commands/DataCommands.java | 1 -
...erationForRegionCommandsIntegrationTest.java | 8 +--
.../internal/security/JSONAuthorization.java | 15 ++++-
...JSONAuthorizationDetailsIntegrationTest.java | 70 +++++++-------------
.../internal/security/testUserMultipleRole.json | 2 +-
6 files changed, 39 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ca89bcc0/geode-core/src/main/java/com/gemstone/gemfire/management/DistributedSystemMXBean.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/DistributedSystemMXBean.java b/geode-core/src/main/java/com/gemstone/gemfire/management/DistributedSystemMXBean.java
index 14b7b3c..9bd84f0 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/DistributedSystemMXBean.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/DistributedSystemMXBean.java
@@ -27,7 +27,6 @@ import com.gemstone.gemfire.distributed.DistributedSystem;
import com.gemstone.gemfire.management.internal.security.Resource;
import com.gemstone.gemfire.management.internal.security.ResourceConstants;
import com.gemstone.gemfire.management.internal.security.ResourceOperation;
-import com.gemstone.gemfire.management.internal.security.ResourceOperationContext.ResourceOperationCode;
/**
* MBean that provides access to information and management operations for a
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ca89bcc0/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommands.java b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommands.java
index 35aa445..f091fd5 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommands.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/cli/commands/DataCommands.java
@@ -79,7 +79,6 @@ import com.gemstone.gemfire.management.internal.cli.shell.Gfsh;
import com.gemstone.gemfire.management.internal.security.Resource;
import com.gemstone.gemfire.management.internal.security.ResourceConstants;
import com.gemstone.gemfire.management.internal.security.ResourceOperation;
-import com.gemstone.gemfire.management.internal.security.ResourceOperationContext.ResourceOperationCode;
/**
*
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ca89bcc0/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
index e8620aa..85dbee1 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/AuthorizeOperationForRegionCommandsIntegrationTest.java
@@ -91,15 +91,9 @@ public class AuthorizeOperationForRegionCommandsIntegrationTest {
}
}
- @Ignore("Test was never implemented")
- @Test
- public void testInheritRole() {
- }
-
@Test
public void testAuthorizeOperationWithRegionOperations() throws Exception {
- String json = readFile(TestUtil.getResourcePath(getClass(), "auth3.json"));
- JSONAuthorization authorization = new JSONAuthorization(json);
+ JSONAuthorization authorization = new JSONAuthorization("auth3.json");
authorization.init(new JMXPrincipal("tushark"), null, null);
checkAccessControlMBean();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ca89bcc0/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
index 2148edd..8f9aa92 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorization.java
@@ -27,6 +27,7 @@ import com.gemstone.gemfire.security.AccessControl;
import com.gemstone.gemfire.security.AuthenticationFailedException;
import com.gemstone.gemfire.security.Authenticator;
import com.gemstone.gemfire.security.NotAuthorizedException;
+import com.gemstone.gemfire.util.test.TestUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -42,6 +43,8 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import static org.jgroups.util.Util.readFile;
+
public class JSONAuthorization implements AccessControl, Authenticator {
public static class Role{
@@ -128,7 +131,8 @@ public class JSONAuthorization implements AccessControl, Authenticator {
return json;
}
- public JSONAuthorization(String json) throws IOException, JSONException{
+ public JSONAuthorization(String jsonFileName) throws IOException, JSONException{
+ String json = readFile(TestUtil.getResourcePath(getClass(), jsonFileName));
readSecurityDescriptor(json);
}
@@ -304,4 +308,13 @@ public class JSONAuthorization implements AccessControl, Authenticator {
}
+ private String readFile(String name) throws IOException, JSONException {
+ File file = new File(name);
+ FileReader reader = new FileReader(file);
+ char[] buffer = new char[(int) file.length()];
+ reader.read(buffer);
+ String json = new String(buffer);
+ reader.close();
+ return json;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ca89bcc0/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
index 877f34e..955e64b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/security/JSONAuthorizationDetailsIntegrationTest.java
@@ -16,20 +16,19 @@
*/
package com.gemstone.gemfire.management.internal.security;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Map;
-
-import org.json.JSONException;
+import com.gemstone.gemfire.management.internal.security.JSONAuthorization.User;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import com.gemstone.gemfire.management.internal.security.JSONAuthorization.User;
-import com.gemstone.gemfire.util.test.TestUtil;
-import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import java.util.Arrays;
+import java.util.Map;
+
+import static org.hamcrest.Matchers.hasItems;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
/**
* Tests JSONAuthorization with JSON loaded from files.
@@ -39,8 +38,7 @@ public class JSONAuthorizationDetailsIntegrationTest {
@Test
public void testSimpleUserAndRole() throws Exception {
- String json = readFile(TestUtil.getResourcePath(getClass(), "testSimpleUserAndRole.json"));
- new JSONAuthorization(json); // static side effect
+ new JSONAuthorization("testSimpleUserAndRole.json");
Map<String, User> acl = JSONAuthorization.getAcl();
assertNotNull(acl);
assertEquals(1, acl.size());
@@ -55,8 +53,7 @@ public class JSONAuthorizationDetailsIntegrationTest {
@Test
public void testUserAndRoleRegionServerGroup() throws Exception {
- String json = readFile(TestUtil.getResourcePath(getClass(), "testUserAndRoleRegionServerGroup.json"));
- new JSONAuthorization(json); // static side effect
+ new JSONAuthorization("testUserAndRoleRegionServerGroup.json");
Map<String, User> acl = JSONAuthorization.getAcl();
assertNotNull(acl);
@@ -75,8 +72,7 @@ public class JSONAuthorizationDetailsIntegrationTest {
@Test
public void testUserMultipleRole() throws Exception {
- String json = readFile(TestUtil.getResourcePath(getClass(), "testUserMultipleRole.json"));
- new JSONAuthorization(json); // static side effect
+ new JSONAuthorization("testUserMultipleRole.json");
Map<String, User> acl = JSONAuthorization.getAcl();
assertNotNull(acl);
@@ -97,19 +93,19 @@ public class JSONAuthorizationDetailsIntegrationTest {
assertEquals(7, role.permissions.length);
assertEquals("sysMonitors", role.name);
- assertTrue(contains(role.permissions, "CMD_EXORT_LOGS"));
- assertTrue(contains(role.permissions, "CMD_STACK_TRACES"));
- assertTrue(contains(role.permissions, "CMD_GC"));
- assertTrue(contains(role.permissions, "CMD_NETSTAT"));
- assertTrue(contains(role.permissions, "CMD_SHOW_DEADLOCKS"));
- assertTrue(contains(role.permissions, "CMD_SHOW_LOG"));
- assertTrue(contains(role.permissions, "SHOW_METRICS"));
+ assertThat(Arrays.asList(role.permissions), hasItems(
+ "CMD_EXPORT_LOGS",
+ "CMD_STACK_TRACES",
+ "CMD_GC",
+ "CMD_NETSTAT",
+ "CMD_SHOW_DEADLOCKS",
+ "CMD_SHOW_LOG",
+ "SHOW_METRICS"));
}
@Test
public void testInheritRole() throws Exception {
- String json = readFile(TestUtil.getResourcePath(getClass(), "testInheritRole.json"));
- new JSONAuthorization(json); // static side effect
+ new JSONAuthorization("testInheritRole.json");
Map<String, User> acl = JSONAuthorization.getAcl();
assertNotNull(acl);
@@ -138,26 +134,6 @@ public class JSONAuthorizationDetailsIntegrationTest {
assertEquals("adminSG2", admin2.roles[0].name);
assertEquals("SG2", admin2.roles[0].serverGroup);
assertEquals(2, admin2.roles[0].permissions.length);
- assertTrue(contains(admin2.roles[0].permissions, "CHANGE_LOG_LEVEL"));
- assertTrue(contains(admin2.roles[0].permissions, "CMD_SHUTDOWN"));
- }
-
- private String readFile(String name) throws IOException, JSONException {
- File file = new File(name);
- FileReader reader = new FileReader(file);
- char[] buffer = new char[(int) file.length()];
- reader.read(buffer);
- String json = new String(buffer);
- reader.close();
- return json;
- }
-
- private boolean contains(String[] permissions, String string) {
- for (String str : permissions) {
- if (str.equals(string)) {
- return true;
- }
- }
- return false;
+ assertThat(Arrays.asList(admin2.roles[0].permissions), hasItems("CHANGE_LOG_LEVEL", "CMD_SHUTDOWN"));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ca89bcc0/geode-core/src/test/resources/com/gemstone/gemfire/management/internal/security/testUserMultipleRole.json
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/com/gemstone/gemfire/management/internal/security/testUserMultipleRole.json b/geode-core/src/test/resources/com/gemstone/gemfire/management/internal/security/testUserMultipleRole.json
index 4ff5413..a0f3c90 100644
--- a/geode-core/src/test/resources/com/gemstone/gemfire/management/internal/security/testUserMultipleRole.json
+++ b/geode-core/src/test/resources/com/gemstone/gemfire/management/internal/security/testUserMultipleRole.json
@@ -7,7 +7,7 @@
{
"name" : "sysMonitors",
"operationsAllowed" : [
- "CMD_EXORT_LOGS","CMD_STACK_TRACES","CMD_GC","CMD_NETSTAT","CMD_SHOW_DEADLOCKS", "CMD_SHOW_LOG", "SHOW_METRICS"
+ "CMD_EXPORT_LOGS","CMD_STACK_TRACES","CMD_GC","CMD_NETSTAT","CMD_SHOW_DEADLOCKS", "CMD_SHOW_LOG", "SHOW_METRICS"
]
}
],