lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [46/50] [abbrv] lucene-solr:jira/solr-11779: SOLR-12279: Reject invalid 'blockUnknown' values for 'bin/solr auth'
Date Tue, 08 May 2018 21:15:32 GMT
SOLR-12279: Reject invalid 'blockUnknown' values for 'bin/solr auth'


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/6521d86d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6521d86d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6521d86d

Branch: refs/heads/jira/solr-11779
Commit: 6521d86dded91e6666f8d85c22076a748b6c2525
Parents: 445c0aa
Author: Jason Gerlowski <gerlowskija@apache.org>
Authored: Mon May 7 07:01:01 2018 -0400
Committer: Jason Gerlowski <gerlowskija@apache.org>
Committed: Mon May 7 07:41:13 2018 -0400

----------------------------------------------------------------------
 solr/bin-test/test_auth.sh                      | 40 ++++++++++++++++++++
 solr/bin-test/utils/assert.sh                   |  2 +-
 .../src/java/org/apache/solr/util/SolrCLI.java  | 15 ++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6521d86d/solr/bin-test/test_auth.sh
----------------------------------------------------------------------
diff --git a/solr/bin-test/test_auth.sh b/solr/bin-test/test_auth.sh
new file mode 100644
index 0000000..b31a996
--- /dev/null
+++ b/solr/bin-test/test_auth.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+# 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.
+
+source bin-test/utils/assert.sh
+
+function solr_unit_test_before() {
+  bin/solr auth disable > /dev/null 2>&1
+}
+
+function solr_test_auth_rejects_blockUnknown_option_with_invalid_boolean() {
+  local auth_cmd="bin/solr auth enable -type basicAuth -credentials anyUser:anyPass -blockUnknown
ture"
+  local expected_output="Argument [blockUnknown] must be either true or false, but was [ture]"
+  local actual_output; actual_output=$($auth_cmd)
+
+  assert_cmd_failed "$auth_cmd" || return 1
+  assert_output_contains "$actual_output" "$expected_output" || return 1
+}
+
+function solr_test_auth_rejects_updateIncludeFileOnly_option_with_invalid_boolean() {
+  local auth_cmd="bin/solr auth enable -type basicAuth -credentials anyUser:anyPass -updateIncludeFileOnly
ture"
+  local expected_output="Argument [updateIncludeFileOnly] must be either true or false, but
was [ture]"
+  local actual_output; actual_output=$($auth_cmd)
+
+  assert_cmd_failed "$auth_cmd" || return 1
+  assert_output_contains "$actual_output" "$expected_output" || return 1
+}
+

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6521d86d/solr/bin-test/utils/assert.sh
----------------------------------------------------------------------
diff --git a/solr/bin-test/utils/assert.sh b/solr/bin-test/utils/assert.sh
index a4bd56d..3f83b43 100644
--- a/solr/bin-test/utils/assert.sh
+++ b/solr/bin-test/utils/assert.sh
@@ -46,7 +46,7 @@ function assert_output_contains() {
   local actual_output="$1"
   local needle="$2"
 
-  if echo "$actual_output" | grep -q "$needle"; then
+  if [[ "$actual_output" == *"$needle"* ]]; then
     return $ASSERT_SUCCESS
   fi
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6521d86d/solr/core/src/java/org/apache/solr/util/SolrCLI.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/util/SolrCLI.java b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
index 784ccbe..9c7970e 100644
--- a/solr/core/src/java/org/apache/solr/util/SolrCLI.java
+++ b/solr/core/src/java/org/apache/solr/util/SolrCLI.java
@@ -72,6 +72,7 @@ import org.apache.commons.exec.Executor;
 import org.apache.commons.exec.OS;
 import org.apache.commons.exec.environment.EnvironmentUtils;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.BooleanUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -3781,6 +3782,17 @@ public class SolrCLI {
       };
     }
 
+    private void ensureArgumentIsValidBooleanIfPresent(CommandLine cli, String argName) {
+      if (cli.hasOption(argName)) {
+        final String value = cli.getOptionValue(argName);
+        final Boolean parsedBoolean = BooleanUtils.toBooleanObject(value);
+        if (parsedBoolean == null) {
+          echo("Argument [" + argName + "] must be either true or false, but was [" + value
+ "]");
+          exit(1);
+        }
+      }
+    }
+
     @Override
     public int runTool(CommandLine cli) throws Exception {
       raiseLogLevelUnlessVerbose(cli);
@@ -3789,6 +3801,9 @@ public class SolrCLI {
         return 1;
       }
 
+      ensureArgumentIsValidBooleanIfPresent(cli, "blockUnknown");
+      ensureArgumentIsValidBooleanIfPresent(cli, "updateIncludeFileOnly");
+
       String type = cli.getOptionValue("type", "basicAuth");
       switch (type) {
         case "basicAuth":


Mime
View raw message