summaryrefslogtreecommitdiffstats
path: root/framework
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2017-08-01 19:56:00 +0530
committerKanagaraj Manickam <kanagaraj.manickam@huawei.com>2017-08-10 05:33:38 +0000
commit2741f49b3b5e92c5c31f44133fd458c4f15b5479 (patch)
treee232e671e11d664787802144532407cae3e08d06 /framework
parent4e2d92bc6c5ae4499f8a583f9b80a1a9172e0c17 (diff)
Populate default param based on no-auth
Based on no-auth customise the default parameter for onap-command. e.g. If "no-auth = true" then command should not add default parameter "onap-username, onap-password, msb-url and no-auth". Issue-Id: CLI-22 Change-Id: Ic9228feb1deb7e6f24eb9b9f0c8f15fd45364e94 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'framework')
-rw-r--r--framework/src/main/java/org/onap/cli/fw/OnapCommand.java19
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/Constants.java6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java22
-rw-r--r--framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java62
-rw-r--r--framework/src/main/resources/default_input_parameters.yaml2
-rw-r--r--framework/src/main/resources/onap.properties8
-rw-r--r--framework/src/main/resources/schema-refresh.yaml6
-rw-r--r--framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java10
-rw-r--r--framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java55
-rw-r--r--framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java39
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java4
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java12
-rw-r--r--framework/src/test/resources/onap.properties8
-rw-r--r--framework/src/test/resources/sample-test-exclude-param.yaml4
-rw-r--r--framework/src/test/resources/sample-test-include-exclude.yaml5
-rw-r--r--framework/src/test/resources/sample-test-include-param.yaml2
-rw-r--r--framework/src/test/resources/sample-test-invalid-exclude-noauth.yaml6
-rw-r--r--framework/src/test/resources/sample-test-invalid-include-noauth.yaml6
-rw-r--r--framework/src/test/resources/sample-test-schema-auth-required.yaml14
20 files changed, 253 insertions, 39 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
index 6cee09de..13e67fc6 100644
--- a/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/OnapCommand.java
@@ -29,6 +29,7 @@ import org.onap.cli.fw.error.OnapCommandInvalidResultAttributeScope;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
import org.onap.cli.fw.error.OnapCommandInvalidSchemaVersion;
import org.onap.cli.fw.error.OnapCommandNotInitialized;
+import org.onap.cli.fw.error.OnapCommandParameterMissing;
import org.onap.cli.fw.error.OnapCommandParameterNameConflict;
import org.onap.cli.fw.error.OnapCommandParameterOptionConflict;
import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
@@ -42,6 +43,7 @@ import org.onap.cli.fw.utils.OnapCommandUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* Onap Command.
@@ -184,7 +186,22 @@ public abstract class OnapCommand {
*/
protected void validate() throws OnapCommandException {
for (OnapCommandParameter param : this.getParameters()) {
- param.validate();
+ try {
+ param.validate();
+ } catch (OnapCommandParameterMissing e) {
+ if (OnapCommandConfg.getExcludeParamsForNoAuthEnableExternalCmd().contains(param.getName())) {
+ OnapCommandParameter noAuthParam = this.getParameters().stream().filter(p -> p.getName()
+ .equalsIgnoreCase(Constants.DEFAULT_PARAMETER_OUTPUT_NO_AUTH)).findFirst().get();
+
+ if ("true".equalsIgnoreCase(noAuthParam.getValue().toString())) {
+ continue;
+ }
+ }
+ throw e;
+ } catch (OnapCommandException e) {
+ throw e;
+ }
+
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
index 8886de55..5f95518c 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/Constants.java
@@ -106,6 +106,10 @@ public class Constants {
public static final String ONAP_CLI_VERSION = "cli.version";
public static final String HTTP_API_KEY_USE_COOKIES = "http.api_key_use_cookies";
public static final String HTTP_X_AUTH_TOKEN = "http.x_auth_token";
+ public static final String EXCLUDE_PARAMS_INTERNAL_CMD = "cli.exclude_params_internal_cmd";
+ public static final String NO_AUTH_DISABLE_INCLUDE_PARAMS_EXTERNAL_CMD = "cli.no_auth_disable_include_params_external_cmd";
+ public static final String NO_AUTH_ENABLE_EXCLUDE_PARAMS_EXTERNAL_CMD = "cli.no_auth_enable_exclude_params_external_cmd";
+ public static final String NO_AUTH_ENABLE_INCLUDE_PARAMS_EXTERNAL_CMD = "cli.no_auth_enable_include_params_external_cmd";
// Used while printing the column name during PORTRAIT mode print
public static final String PORTRAINT_COLUMN_NAME_PROPERTY = "property";
@@ -148,7 +152,7 @@ public class Constants {
public static final String DEFAULT_SCHEMA_FILE_NAME = "default_input_parameters.yaml";
// Error message
- public static final String SCHEMA_INVALID_DEFAULT_PARAMS_SECTION = "Invalid default parameter section";
+ public static final String SCHEMA_INVALID_DEFAULT_PARAMS_SECTION = "Invalid default_parameter section";
public static final String SCHEMA_FILE_EMPTY = "The schema file cann't be null or empty";
public static final String SCHEMA_FILE_WRONG_EXTN = "Schema file should be '.yaml' extension";
public static final String SCHEMA_FILE_NOT_EXIST = "Schema file doesn't exist";
diff --git a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
index bcfd6dfb..c2682cae 100644
--- a/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
+++ b/framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConfg.java
@@ -17,7 +17,10 @@
package org.onap.cli.fw.conf;
import java.io.IOException;
+import java.util.Arrays;
import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
/**
* Onap command constants.
@@ -88,4 +91,23 @@ public final class OnapCommandConfg {
return prps.getProperty(Constants.AUTH_SERVICE);
}
+ public static Set<String> getExcludeParamsForInternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.EXCLUDE_PARAMS_INTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
+
+ public static Set<String> getIncludeParamsForNoAuthDisableExternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.NO_AUTH_DISABLE_INCLUDE_PARAMS_EXTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
+
+ public static Set<String> getExcludeParamsForNoAuthEnableExternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.NO_AUTH_ENABLE_EXCLUDE_PARAMS_EXTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
+
+ public static Set<String> getIncludeParamsForNoAuthEnableExternalCmd() {
+ return Arrays.stream(prps.getProperty(Constants.NO_AUTH_ENABLE_INCLUDE_PARAMS_EXTERNAL_CMD)
+ .split(",")).map(String::trim).collect(Collectors.toSet());
+ }
}
diff --git a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java
index 4ebf04d3..7dc4374e 100644
--- a/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java
+++ b/framework/src/main/java/org/onap/cli/fw/error/OnapCommandInvalidDefaultParameter.java
@@ -30,6 +30,6 @@ public class OnapCommandInvalidDefaultParameter extends OnapCommandException {
* @param invalidParamsList message
*/
public OnapCommandInvalidDefaultParameter(List<String> invalidParamsList) {
- super("0x0024", "Invalid default parameter: " + invalidParamsList.toString());
+ super("0x0024", "Invalid default_parameter: " + invalidParamsList.toString());
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index 1ad588de..1a5aba0f 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -25,6 +25,7 @@ import org.onap.cli.fw.ad.OnapService;
import org.onap.cli.fw.cmd.OnapHttpCommand;
import org.onap.cli.fw.cmd.OnapSwaggerCommand;
import org.onap.cli.fw.conf.Constants;
+import org.onap.cli.fw.conf.OnapCommandConfg;
import org.onap.cli.fw.error.OnapCommandDiscoveryFailed;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandHelpFailed;
@@ -175,6 +176,42 @@ public class OnapCommandUtils {
}
}
+ private static void processNoAuth(Set<String> parameterSet, final OnapCommand cmd, final List<String> includeParams,
+ final List<String> excludeParams) throws OnapCommandInvalidDefaultParameter {
+ // processing for no-auth type
+ if (cmd.getService() != null) {
+ List<String> includeAuthParams = new ArrayList();
+ List<String> excludeAuthParams = new ArrayList<>();
+ boolean noAuth = cmd.getService().isNoAuth();
+
+ if (cmd.isCommandInternal()) {
+ excludeAuthParams.addAll(OnapCommandConfg.getExcludeParamsForInternalCmd());
+ } else {
+ if (noAuth) {
+ includeAuthParams.addAll(OnapCommandConfg.getIncludeParamsForNoAuthEnableExternalCmd());
+ excludeAuthParams.addAll(OnapCommandConfg.getExcludeParamsForNoAuthEnableExternalCmd());
+ } else {
+ includeAuthParams.addAll(OnapCommandConfg.getIncludeParamsForNoAuthDisableExternalCmd());
+ }
+ }
+
+ List<String> invalidExclude = excludeAuthParams.stream().filter(includeParams::contains)
+ .collect(Collectors.toList());
+
+ List<String> invalidInclude = includeAuthParams.stream().filter(excludeParams::contains)
+ .filter(p->!includeParams.contains(p)).collect(Collectors.toList());
+
+ if (!invalidExclude.isEmpty() || !invalidInclude.isEmpty()) {
+ throw new OnapCommandInvalidDefaultParameter(Stream.concat(invalidExclude.stream(), invalidInclude.stream())
+ .collect(Collectors.toList()));
+ }
+
+
+ parameterSet.addAll(includeAuthParams);
+ parameterSet.removeAll(excludeAuthParams);
+ }
+ }
+
private static void parseSchema(OnapCommand cmd,
final Map<String, ?> values,
final List<String> defaultParamNames) throws OnapCommandException {
@@ -222,6 +259,8 @@ public class OnapCommandUtils {
} else if (Constants.DEFAULT_PARAMETERS.equals(key)) {
Map<String, List<String>> defParameters = (Map) values.get(Constants.DEFAULT_PARAMETERS);
+ List<String> includeParams = new ArrayList<>();
+ List<String> excludeParams = new ArrayList<>();
if (values.containsKey(Constants.DEFAULT_PARAMETERS) && defParameters == null) {
// if default parameter section is available then it must have either include
@@ -229,22 +268,25 @@ public class OnapCommandUtils {
throw new OnapCommandInvalidSchema(Constants.SCHEMA_INVALID_DEFAULT_PARAMS_SECTION);
}
+
if (defParameters != null) {
// validate default parameters
- List<String> includeParams = defParameters.containsKey(Constants.DEFAULT_PARAMETERS_INCLUDE) ?
- defParameters.get(Constants.DEFAULT_PARAMETERS_INCLUDE) : new ArrayList<>();
+ if (defParameters.containsKey(Constants.DEFAULT_PARAMETERS_INCLUDE)) {
+ includeParams = defParameters.get(Constants.DEFAULT_PARAMETERS_INCLUDE);
+ }
List<String> invInclude = includeParams.stream()
.filter(p -> !defaultParamNames.contains(p))
.collect(Collectors.toList());
- List<String> excludeParams = defParameters.containsKey(Constants.DEFAULT_PARAMETERS_EXCLUDE) ?
- defParameters.get(Constants.DEFAULT_PARAMETERS_EXCLUDE) : new ArrayList<>();
+ if (defParameters.containsKey(Constants.DEFAULT_PARAMETERS_EXCLUDE)) {
+ excludeParams = defParameters.get(Constants.DEFAULT_PARAMETERS_EXCLUDE);
+ }
- List<String> invExclude = excludeParams.stream()
- .filter(p -> !defaultParamNames.contains(p))
+ List<String> invExclude = excludeParams.stream().filter(p -> !defaultParamNames.contains(p))
.collect(Collectors.toList());
+
if (!invExclude.isEmpty() || !invInclude.isEmpty()) {
throw new OnapCommandInvalidDefaultParameter(Stream.concat(invInclude.stream(), invExclude.stream())
.collect(Collectors.toList()));
@@ -253,14 +295,14 @@ public class OnapCommandUtils {
if (!includeParams.isEmpty()) {
filteredDefaultParams.addAll(includeParams);
} else if (!excludeParams.isEmpty()) {
- defaultParamNames.stream().filter(p -> !excludeParams.contains(p))
+ List<String> finalExcludeParams = excludeParams;
+ defaultParamNames.stream().filter(p -> !finalExcludeParams.contains(p))
.forEach(filteredDefaultParams::add);
}
} else {
filteredDefaultParams.addAll(defaultParamNames);
-
}
-
+ processNoAuth(filteredDefaultParams, cmd, includeParams, excludeParams);
} else if (Constants.PARAMETERS.equals(key)) {
List<Map<String, String>> parameters = (List) values.get(key);
@@ -570,7 +612,7 @@ public class OnapCommandUtils {
if (param.isDefaultValueAnEnv()) {
optSecondCol += defaultMsg + "read from environment variable " + param.getEnvVarNameFromDefaultValue()
+ ".";
- } else if (param.getDefaultValue() != null && !param.getDefaultValue().isEmpty()) {
+ } else if (param.getDefaultValue() != null && !((String)param.getDefaultValue()).isEmpty()) {
optSecondCol += defaultMsg + param.getDefaultValue() + ".";
}
diff --git a/framework/src/main/resources/default_input_parameters.yaml b/framework/src/main/resources/default_input_parameters.yaml
index f1e299eb..4f0d419c 100644
--- a/framework/src/main/resources/default_input_parameters.yaml
+++ b/framework/src/main/resources/default_input_parameters.yaml
@@ -14,11 +14,13 @@ parameters:
long_option: onap-password
default_value: ${ONAP_PASSWORD}
is_secured: true
+ is_optional: false
- name: msb-url
type: url
description: Onap MSB url
short_option: m
long_option: msb-url
+ is_optional: false
default_value: ${ONAP_MSB_URL}
- name: help
type: string
diff --git a/framework/src/main/resources/onap.properties b/framework/src/main/resources/onap.properties
index bf1cdae5..b8f08d3b 100644
--- a/framework/src/main/resources/onap.properties
+++ b/framework/src/main/resources/onap.properties
@@ -5,4 +5,10 @@ http.api_key_use_cookies=true
cli.service_name=onap-cli
cli.api_gateway=msb
-cli.auth_service=auth \ No newline at end of file
+cli.auth_service=auth
+
+# service section
+cli.exclude_params_internal_cmd=onap-username,onap-password,msb-url,no-auth
+cli.no_auth_disable_include_params_external_cmd=onap-username,onap-password,msb-url,no-auth
+cli.no_auth_enable_exclude_params_external_cmd=onap-username,onap-password,no-auth
+cli.no_auth_enable_include_params_external_cmd=msb-url \ No newline at end of file
diff --git a/framework/src/main/resources/schema-refresh.yaml b/framework/src/main/resources/schema-refresh.yaml
index ffa32424..f64b0545 100644
--- a/framework/src/main/resources/schema-refresh.yaml
+++ b/framework/src/main/resources/schema-refresh.yaml
@@ -5,12 +5,6 @@ service:
no-auth: true
name: onap-cli
version: 1.0.0
-default_parameters:
- exclude:
- - onap-username
- - onap-password
- - msb-url
- - no-auth
results:
direction: landscape
attributes:
diff --git a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
index 83f3a743..a076eee6 100644
--- a/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/OnapCommandRegistrarTest.java
@@ -16,11 +16,6 @@
package org.onap.cli.fw;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import org.junit.Before;
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
@@ -31,6 +26,11 @@ import org.onap.cli.fw.error.OnapCommandRegistrationFailed;
import java.io.File;
import java.net.URL;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
public class OnapCommandRegistrarTest {
OnapCommandRegistrar registerar;
diff --git a/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java
new file mode 100644
index 00000000..b8ac72ef
--- /dev/null
+++ b/framework/src/test/java/org/onap/cli/fw/TestCommandValidate.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed 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.
+ */
+
+package org.onap.cli.fw;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.cli.fw.error.OnapCommandException;
+import org.onap.cli.fw.error.OnapCommandParameterMissing;
+import org.onap.cli.fw.input.OnapCommandParameter;
+import org.onap.cli.fw.utils.OnapCommandUtils;
+
+public class TestCommandValidate {
+
+ OnapCommand cmd;
+
+ @Before
+ public void before() {
+ cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+ }
+
+ @Test
+ public void testNoAuthArgumentTrue() throws OnapCommandException {
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+
+ OnapCommandParameter noAuthParam = cmd.getParameters().stream().filter(p -> p.getName().equalsIgnoreCase("no-auth")).findFirst().get();
+ noAuthParam.setValue(true);
+ OnapCommandParameter msbParam = cmd.getParameters().stream().filter(p -> p.getName().equalsIgnoreCase("msb-url")).findFirst().get();
+ msbParam.setValue("localhost://msbip:msb:port");
+ cmd.validate();
+ }
+
+ @Test(expected = OnapCommandParameterMissing.class)
+ public void testNoAuthArgFalse() throws OnapCommandException {
+ OnapCommandUtils.loadSchema(cmd, "sample-test-include-param.yaml", true);
+ cmd.validate();
+ }
+}
diff --git a/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
index bd2ad0d1..004bf7cf 100644
--- a/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
+++ b/framework/src/test/java/org/onap/cli/fw/defaultParameter/TestDefaultParameterSection.java
@@ -21,6 +21,7 @@ import org.onap.cli.fw.OnapCommand;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidDefaultParameter;
import org.onap.cli.fw.error.OnapCommandInvalidSchema;
+import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.utils.OnapCommandUtils;
import java.util.List;
@@ -54,9 +55,12 @@ public class TestDefaultParameterSection {
OnapCommandUtils.loadSchema(cmd, "sample-test-exclude-param.yaml", true);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
- assertFalse(parameters.contains("onap-username"));
+ assertTrue(parameters.contains("onap-username"));
assertTrue(parameters.contains("onap-password"));
- assertFalse(parameters.contains("msb-url"));
+ assertTrue(parameters.contains("msb-url"));
+ assertFalse(parameters.contains("long"));
+ assertFalse(parameters.contains("format"));
+ assertTrue(parameters.contains("debug"));
}
@Test
@@ -70,8 +74,8 @@ public class TestDefaultParameterSection {
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
assertTrue(parameters.contains("onap-username"));
- assertFalse(parameters.contains("onap-password"));
- assertFalse(parameters.contains("msb-url"));
+ assertTrue(parameters.contains("onap-password"));
+ assertTrue(parameters.contains("msb-url"));
}
@Test
@@ -84,9 +88,12 @@ public class TestDefaultParameterSection {
OnapCommandUtils.loadSchema(cmd, "onap-test-schema.yaml", true);
List<String> parameters = cmd.getParameters().stream().map(p -> p.getName()).collect(Collectors.toList());
- assertTrue(parameters.contains("onap-username"));
- assertTrue(parameters.contains("onap-password"));
+ assertFalse(parameters.contains("onap-username"));
+ assertFalse(parameters.contains("onap-password"));
assertTrue(parameters.contains("msb-url"));
+ assertTrue(parameters.contains("debug"));
+ assertTrue(parameters.contains("long"));
+ assertTrue(parameters.contains("format"));
}
@Test(expected = OnapCommandInvalidDefaultParameter.class)
@@ -118,4 +125,24 @@ public class TestDefaultParameterSection {
OnapCommandUtils.loadSchema(cmd, "sample-test-import-def-param-false.yaml", true);
}
+
+ @Test(expected = OnapCommandInvalidDefaultParameter.class)
+ public void checkInvalidIncludeNoAuth() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-include-noauth.yaml", true);
+ }
+
+ @Test(expected = OnapCommandInvalidDefaultParameter.class)
+ public void checkInvalidExcludeNoAuth() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommand() {
+ @Override
+ protected void run() throws OnapCommandException {}
+ };
+
+ OnapCommandUtils.loadSchema(cmd, "sample-test-invalid-exclude-noauth.yaml", true);
+ }
}
diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
index 40b07861..604411ed 100644
--- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java
@@ -16,8 +16,6 @@
package org.onap.cli.fw.input;
-import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandInvalidParameterValue;
@@ -26,6 +24,8 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.Assert.assertTrue;
+
public class OnapCommandParameterTest {
@Test
diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
index b74027a0..d01e2e77 100644
--- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
@@ -179,7 +179,17 @@ public class OnapCommandUtilsTest {
OnapCredentials cre = OnapCommandUtils.fromParameters(cmd.getParameters());
assertTrue(cre != null);
Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
- assertTrue(map.size() == 19);
+ assertTrue(map.size() == 16);
+ }
+
+ @Test
+ public void loadOnapCommandSchemaAuthRequiredTest() throws OnapCommandException {
+ OnapCommand cmd = new OnapCommandSample();
+ OnapCommandUtils.loadSchema(cmd, "sample-test-schema-auth-required.yaml", true);
+ assertTrue("sample-test".equals(cmd.getName()));
+
+ Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
+ assertTrue(map.size() == 11);
}
@Test
diff --git a/framework/src/test/resources/onap.properties b/framework/src/test/resources/onap.properties
index beb24a3f..a6c991cd 100644
--- a/framework/src/test/resources/onap.properties
+++ b/framework/src/test/resources/onap.properties
@@ -5,4 +5,10 @@ http.api_key_use_cookies=true
cli.service_name=onap-cli
cli.api_gateway=msb
-cli.auth_service=auth \ No newline at end of file
+cli.auth_service=auth
+
+# service section
+cli.exclude_params_internal_cmd=onap-username,onap-password,msb-url,no-auth
+cli.no_auth_disable_include_params_external_cmd=onap-username,onap-password,msb-url,no-auth
+cli.no_auth_enable_exclude_params_external_cmd=onap-username,onap-password,no-auth
+cli.no_auth_enable_include_params_external_cmd=msb-url
diff --git a/framework/src/test/resources/sample-test-exclude-param.yaml b/framework/src/test/resources/sample-test-exclude-param.yaml
index 3cfb62ac..970a185d 100644
--- a/framework/src/test/resources/sample-test-exclude-param.yaml
+++ b/framework/src/test/resources/sample-test-exclude-param.yaml
@@ -1,5 +1,5 @@
onap_cmd_schema_version: 1.0
default_parameters:
exclude:
- - onap-username
- - msb-url \ No newline at end of file
+ - long
+ - format
diff --git a/framework/src/test/resources/sample-test-include-exclude.yaml b/framework/src/test/resources/sample-test-include-exclude.yaml
index 22d05c47..a1494bfe 100644
--- a/framework/src/test/resources/sample-test-include-exclude.yaml
+++ b/framework/src/test/resources/sample-test-include-exclude.yaml
@@ -2,5 +2,8 @@ onap_cmd_schema_version: 1.0
default_parameters:
include:
- onap-username
+ - onap-password
+ - msb-url
+ - no-auth
exclude:
- - msb-url \ No newline at end of file
+ - long
diff --git a/framework/src/test/resources/sample-test-include-param.yaml b/framework/src/test/resources/sample-test-include-param.yaml
index 0dc76bbc..ecc737c7 100644
--- a/framework/src/test/resources/sample-test-include-param.yaml
+++ b/framework/src/test/resources/sample-test-include-param.yaml
@@ -3,4 +3,4 @@ default_parameters:
include:
- onap-username
- onap-password
- - msb-url \ No newline at end of file
+ - no-auth
diff --git a/framework/src/test/resources/sample-test-invalid-exclude-noauth.yaml b/framework/src/test/resources/sample-test-invalid-exclude-noauth.yaml
new file mode 100644
index 00000000..bad12e60
--- /dev/null
+++ b/framework/src/test/resources/sample-test-invalid-exclude-noauth.yaml
@@ -0,0 +1,6 @@
+onap_cmd_schema_version: 1.0
+service:
+ no-auth: false
+default_parameters:
+ exclude:
+ - onap-username \ No newline at end of file
diff --git a/framework/src/test/resources/sample-test-invalid-include-noauth.yaml b/framework/src/test/resources/sample-test-invalid-include-noauth.yaml
new file mode 100644
index 00000000..c4384ca0
--- /dev/null
+++ b/framework/src/test/resources/sample-test-invalid-include-noauth.yaml
@@ -0,0 +1,6 @@
+onap_cmd_schema_version: 1.0
+service:
+ no-auth: true
+default_parameters:
+ include:
+ - onap-username \ No newline at end of file
diff --git a/framework/src/test/resources/sample-test-schema-auth-required.yaml b/framework/src/test/resources/sample-test-schema-auth-required.yaml
new file mode 100644
index 00000000..4df6445a
--- /dev/null
+++ b/framework/src/test/resources/sample-test-schema-auth-required.yaml
@@ -0,0 +1,14 @@
+onap_cmd_schema_version: 1.0
+name: sample-test
+description: Onap sample command to test the command features
+service:
+ name: sample
+ version: v1
+parameters:
+ - name: bool-param
+ type: bool
+ description: Onap boolean param, by default its always false.
+ short_option: b
+ long_option: bool
+ is_optional: true
+ default_value: false \ No newline at end of file