geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [10/32] geode git commit: GEODE-2950: Adding validation checks on create lucene index parameter names
Date Wed, 31 May 2017 17:01:15 GMT
GEODE-2950: Adding validation checks on create lucene index parameter names

	This closes #532


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/c793f74c
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/c793f74c
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/c793f74c

Branch: refs/heads/feature/GEODE-1279
Commit: c793f74c07c3488ba188ed927144be688bd50b19
Parents: 0dae918
Author: David Anuta <david.r.anuta@gmail.com>
Authored: Wed May 24 16:21:33 2017 -0700
Committer: nabarun <nnag@pivotal.io>
Committed: Thu May 25 11:20:56 2017 -0700

----------------------------------------------------------------------
 .../lucene/internal/LuceneServiceImpl.java      | 15 ++++++++----
 .../functions/LuceneCreateIndexFunction.java    |  6 +++--
 .../cli/LuceneIndexCommandsDUnitTest.java       | 25 ++++++++++++++++----
 3 files changed, 36 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c793f74c/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index 3859804..c0d6266 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -128,7 +128,7 @@ public class LuceneServiceImpl implements InternalLuceneService {
     return getUniqueIndexName(indexName, regionPath) + regionSuffix;
   }
 
-  public static void validateRegionName(String name) {
+  public static void validateCreateIndexCommandParams(String name, boolean isRegionPath)
{
     if (name == null) {
       throw new IllegalArgumentException(
           LocalizedStrings.LocalRegion_NAME_CANNOT_BE_NULL.toLocalizedString());
@@ -140,15 +140,22 @@ public class LuceneServiceImpl implements InternalLuceneService {
 
     if (name.startsWith("__")) {
       throw new IllegalArgumentException(
-          "Region names may not begin with a double-underscore: " + name);
+          "Parameter names may not begin with a double-underscore: " + name);
+    }
+
+    final Pattern NAME_PATTERN;
+    if (isRegionPath) {
+      NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_./]+");
+    } else {
+      NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_.]+");
     }
 
-    final Pattern NAME_PATTERN = Pattern.compile("[aA-zZ0-9-_./]+");
     // Ensure the region only contains valid characters
     Matcher matcher = NAME_PATTERN.matcher(name);
     if (!matcher.matches()) {
       throw new IllegalArgumentException(
-          "Region names may only be alphanumeric and may contain hyphens or underscores:
" + name);
+          "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:
"
+              + name);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/c793f74c/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
index 422b1ef..26ac0e2 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/cli/functions/LuceneCreateIndexFunction.java
@@ -15,7 +15,7 @@
 
 package org.apache.geode.cache.lucene.internal.cli.functions;
 
-import static org.apache.geode.cache.lucene.internal.LuceneServiceImpl.validateRegionName;
+import static org.apache.geode.cache.lucene.internal.LuceneServiceImpl.validateCreateIndexCommandParams;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.geode.cache.Cache;
@@ -67,6 +67,8 @@ public class LuceneCreateIndexFunction extends FunctionAdapter implements
Intern
       memberId = cache.getDistributedSystem().getDistributedMember().getId();
       LuceneService service = LuceneServiceProvider.get(cache);
 
+      validateCreateIndexCommandParams(indexInfo.getIndexName(), false);
+
       String[] fields = indexInfo.getSearchableFieldNames();
       String[] analyzerName = indexInfo.getFieldAnalyzers();
 
@@ -84,7 +86,7 @@ public class LuceneCreateIndexFunction extends FunctionAdapter implements
Intern
         }
       }
 
-      validateRegionName(indexInfo.getRegionPath());
+      validateCreateIndexCommandParams(indexInfo.getRegionPath(), true);
       indexFactory.create(indexInfo.getIndexName(), indexInfo.getRegionPath());
 
       // TODO - update cluster configuration by returning a valid XmlEntity

http://git-wip-us.apache.org/repos/asf/geode/blob/c793f74c/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
index 04359a3..5e9c4f9 100755
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/cli/LuceneIndexCommandsDUnitTest.java
@@ -198,7 +198,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
   }
 
   @Test
-  public void createIndexShouldNotAcceptEmptyRegionNames() {
+  public void createIndexShouldNotAcceptBadIndexOrRegionNames() {
     final VM vm1 = Host.getHost(0).getVM(-1);
     vm1.invoke(() -> {
       getCache();
@@ -210,7 +210,7 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase {
     csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
 
     String resultAsString = executeCommandAndLogResult(csb);
-    assertTrue(resultAsString.contains("Region names may not begin with a double-underscore:"));
+    assertTrue(resultAsString.contains("Parameter names may not begin with a double-underscore:"));
 
     csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
     csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
@@ -218,8 +218,25 @@ public class LuceneIndexCommandsDUnitTest extends CliCommandTestBase
{
     csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
 
     resultAsString = executeCommandAndLogResult(csb);
-    assertTrue(resultAsString
-        .contains("Region names may only be alphanumeric and may contain hyphens or underscores:"));
+    assertTrue(resultAsString.contains(
+        "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:"));
+
+    csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, "\'__\'");
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
+
+    resultAsString = executeCommandAndLogResult(csb);
+    assertTrue(resultAsString.contains("Parameter names may not begin with a double-underscore:"));
+
+    csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
+    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, "\' @@@*%\'");
+    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
+    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
+
+    resultAsString = executeCommandAndLogResult(csb);
+    assertTrue(resultAsString.contains(
+        "Parameter names may only be alphanumeric, though they can contain hyphens or underscores:"));
   }
 
   @Test


Mime
View raw message