diff options
-rwxr-xr-x | kud/tests/negative_tests/_test_functions.sh | 346 | ||||
-rwxr-xr-x | kud/tests/negative_tests/_test_variables_setup.sh | 95 | ||||
-rw-r--r-- | kud/tests/negative_tests/readme.txt | 19 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_all_final.sh | 29 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_all_intents.sh | 122 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_composite_app.sh | 95 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_controllers.sh | 94 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_deployment_intent_group.sh | 135 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_generic_placement_intent.sh | 111 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_generic_placement_intent_app.sh | 134 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_multipart.sh | 95 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_profile.sh | 101 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_profile_apps.sh | 109 | ||||
-rwxr-xr-x | kud/tests/negative_tests/test_project.sh | 75 |
14 files changed, 1560 insertions, 0 deletions
diff --git a/kud/tests/negative_tests/_test_functions.sh b/kud/tests/negative_tests/_test_functions.sh new file mode 100755 index 00000000..f4e9472d --- /dev/null +++ b/kud/tests/negative_tests/_test_functions.sh @@ -0,0 +1,346 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Additional functions to run negative tests + +set -o errexit +set -o nounset +set -o pipefail + +FUNCTIONS_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")" +my_directory=$(dirname $PWD) + +source /etc/environment +source ${my_directory}/negative_tests/_test_variables_setup.sh +source ${my_directory}/_common_test.sh +source ${my_directory}/_functions.sh +source ${my_directory}/_common.sh + +function call_api_negative { + #Runs curl with passed flags and provides + #additional error handling and debug information + + #Function outputs server response body + #and performs validation of http_code + + local status + local curl_response_file="$(mktemp -p /tmp)" + local curl_common_flags=(-s -w "%{http_code}" -o "${curl_response_file}") + local command=(curl "${curl_common_flags[@]}" "$@") + + echo "[INFO] Running '${command[@]}'" >&2 + if ! status="$("${command[@]}")"; then + echo "[ERROR] Internal curl error! '$status'" >&2 + cat "${curl_response_file}" + rm "${curl_response_file}" + return 2 + else + echo "[INFO] Server replied with status: ${status}" >&2 + cat "${curl_response_file}" + rm "${curl_response_file}" + return_status=$status + fi +} + + +function delete_resource_negative { + #Issues DELETE http call to provided endpoint + #and further validates by following GET request + + call_api_negative -X DELETE "$1" + #! call_api -X GET "$1" >/dev/null +} + +function get_resource_negative { + #! call_api_negative -X GET "$1" >/dev/null + ! call_api_negative -X GET "$1" + echo $return_status +} + + +# Create a test rpoject +# EOF must start as first chracter in a line for cat to identify the end +function create_project { + project_name="test_project" + project_description="test_project_description" + userData1="user1" + userData2="user2" + print_msg "Registering project" + payload="$(cat <<EOF + { + "metadata": { + "name": "${project_name}", + "description": "${project_description}", + "userData1": "${userData1}", + "userData2": "${userData2}" + } + } +EOF + )" + call_api -d "${payload}" "${base_url}/projects" +} + +function create_composite_app { + + project_name="test_project" + composite_app_name="test_composite_app_collection" + composite_app_description="test_project_description" + composite_app_version="test_composite_app_version" + userData1="user1" + userData2="user2" + + print_msg "Registering composite-app" + payload="$(cat <<EOF + { + "metadata": { + "name": "${composite_app_name}", + "description": "${composite_app_description}", + "userData1": "${userData1}", + "userData2": "${userData2}" + }, + "spec":{ + "version":"${composite_app_version}" + } + } +EOF + )" + call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps" +} + +function delete_all { + + delete_resource_negative "${base_url}/controllers/${genericPlacementIntent}" + delete_resource_negative "${base_url}/controllers/${hpaIntent}" + delete_resource_negative "${base_url}/controllers/${trafficIntent}" + delete_resource_negative "${base_url}/controllers/${CostBasedIntent}" + delete_resource_negative "${base_url}/controllers/${OVNintent}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents/${intentToBeAddedinDeploymentIntentGroup}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents/${appIntentNameForApp2}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents/${appIntentNameForApp1}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles/${sub_composite_profile_name2}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles/${sub_composite_profile_name1}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps/${app2_name}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps/${app1_name}" + delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}" + delete_resource_negative "${base_url}/projects/${project_name}" +} + +function create_app { + app_helm_path="$CSAR_DIR/$csar_id/$1" + app_name=$2 + app_desc=$3 + userData1="user1" + userData2="user2" + project_name="test_project" + composite_app_name="test_composite_app_collection" + composite_app_version="test_composite_app_version" + + print_msg "Making app entry in the database" + payload="$(cat <<EOF + { + "metadata": { + "name": "${app_name}", + "description": "${app_desc}", + "userData1": "${userData1}", + "userData2": "${userData2}" + } + } +EOF + )" + + call_api -F "metadata=$payload" \ + -F "file=@$app_helm_path" \ + "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps" +} + +# BEGIN: Register the main composite-profile +function create_main_composite_profile { + print_msg "Registering the main composite-profile" + payload="$(cat <<EOF + { + "metadata":{ + "name":"${main_composite_profile_name}", + "description":"${main_composite_profile_description}", + "userData1":"${userData1}", + "userData2":"${userData2}" + } + } +EOF + )" + call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles" +} + +function create_profile_app { + + sub_composite_profile_name=$1 + app_name=$2 + app_profile_path="$CSAR_DIR/$csar_id/$3" + + print_msg "Registering profile with app1(collectd)" + payload="$(cat <<EOF + { + "metadata":{ + "name":"${sub_composite_profile_name}", + "description":"${sub_composite_profile_description}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "app-name": "${app_name}" + } + } +EOF + )" + + call_api -F "metadata=$payload" \ + -F "file=@$app_profile_path" \ + "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles" +} + +# BEGIN: Register GenericPlacementIntents with the database +function create_generic_placement_intent_app1 { + print_msg "Registering GenericPlacementIntent for app1" + payload="$(cat <<EOF + { + "metadata":{ + "name":"${genericPlacementIntentName}", + "description":"${genericPlacementIntentDesc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "logical-cloud":"${logicalCloud}" + } + } +EOF + )" + call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents" +} + +# BEGIN: Adding placement intent for each app in the composite app. +function create_placement_intent_app { + appIntentNameForApp=$1 + appIntentForAppDesc=$2 + app_name=$3 + + print_msg "Adding placement intent for app" + payload="$(cat <<EOF + { + "metadata":{ + "name":"${appIntentNameForApp}", + "description":"${appIntentForAppDesc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "app-name":"${app_name}", + "intent":{ + "allOf":[ + { "provider-name":"${providerName1}", + "cluster-name":"${clusterName1}" + }, + { + "provider-name":"${providerName2}", + "cluster-name":"${clusterName2}" + }, + { + "anyOf":[ + { + "provider-name":"${providerName1}", + "cluster-label-name":"${clusterLabelName1}" + }, + { + "provider-name":"${providerName2}", + "cluster-label-name":"${clusterLabelName2}" + } + ] + } + ] + } + } +} +EOF + )" + call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents" +} + +# BEGIN: Registering DeploymentIntentGroup in the database +function create_deployment_intent_group { +print_msg "Registering DeploymentIntentGroup" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${deploymentIntentGroupName}", + "description":"${deploymentIntentGroupNameDesc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "profile":"${main_composite_profile_name}", + "version":"${releaseName}", + "override-values":[ + { + "app-name":"${app1_name}", + "values": + { + "collectd_prometheus.service.targetPort":"9104" + } + }, + { + "app-name":"${app2_name}", + "values": + { + "prometheus.service.nameOfPort":"WebPort9090" + } + } + ] + } +} +EOF +)" +call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups" +} + +function create_adding_all_intents_to_deployment_intent_group { +# BEGIN: Adding intents to an intent group +print_msg "Adding all the intents to the deploymentIntent group" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${intentToBeAddedinDeploymentIntentGroup}", + "description":"${intentToBeAddedinDeploymentIntentGroupDesc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "intent":{ + "${genericPlacementIntent}":"${genericPlacementIntentName}", + "${hpaIntent}" : "${hpaControllerIntentName}", + "${trafficIntent}" : "${trafficControllerIntentName}", + "${CostBasedIntent}" : "${CostBasedIntentName}", + "${OVNintent}" : "${OVNintentName}" + } + } +} +EOF +)" +call_api -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents" +# END: Adding intents to an intent group +} + diff --git a/kud/tests/negative_tests/_test_variables_setup.sh b/kud/tests/negative_tests/_test_variables_setup.sh new file mode 100755 index 00000000..1630c039 --- /dev/null +++ b/kud/tests/negative_tests/_test_variables_setup.sh @@ -0,0 +1,95 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +base_url=${base_url:-"http://localhost:9015/v2"} +kubeconfig_path="$HOME/.kube/config" +csar_id=cb009bfe-bbee-11e8-9766-525400435678 + +project_name="test_project" +project_description="test_project_description" +userData1="user1" +userData2="user2" + +composite_app_name="test_composite_app_collection" +composite_app_description="test_project_description" +composite_app_version="test_composite_app_version" +app1_helm_path="$CSAR_DIR/$csar_id/collectd.tar.gz" +app2_helm_path="$CSAR_DIR/$csar_id/prometheus-operator.tar.gz" +app1_profile_path="$CSAR_DIR/$csar_id/collectd_profile.tar.gz" +app2_profile_path="$CSAR_DIR/$csar_id/prometheus-operator_profile.tar.gz" + +app1_name="collectd" +app2_name="prometheus" +app1_desc="collectd_desc" +app2_desc="prometheus_desc" + +main_composite_profile_name="main_composite_profile" +sub_composite_profile_name1="test_composite_profile1" +sub_composite_profile_name2="test_composite_profile2" +main_composite_profile_description="main_composite_profile_description" +sub_composite_profile_description="sub_composite_profile_description" + +genericPlacementIntentName="test_gen_placement_intent1" +genericPlacementIntentDesc="test_gen_placement_intent_desc" +logicalCloud="logical_cloud_name" + +appIntentNameForApp1="appIntentForApp1" +appIntentForApp1Desc="AppIntentForApp1Desc" +appIntentNameForApp2="appIntentForApp2" +appIntentForApp2Desc="AppIntentForApp2Desc" +providerName1="cluster_provider1" +providerName2="cluster_provider2" +clusterName1="clusterName1" +clusterName2="clusterName2" +clusterLabelName1="clusterLabel1" +clusterLabelName2="clusterLabel2" + +deploymentIntentGroupName="test_deployment_intent_group" +deploymentIntentGroupNameDesc="test_deployment_intent_group_desc" +releaseName="test" +intentToBeAddedinDeploymentIntentGroup="name_of_intent_to_be_added_in_deployment_group" +intentToBeAddedinDeploymentIntentGroupDesc="desc_of_intent_to_be_added_in_deployment_group" +hpaIntentName="hpaIntentName" +trafficIntentName="trafficIntentName" + +chart_name="edgex" +profile_name="test_profile" +release_name="test-release" +namespace="plugin-tests-namespace" +cloud_region_id="kud" +cloud_region_owner="localhost" + + +# Controllers +genericPlacementIntent="genericPlacementIntent" +OVNintent="OVNintent" +OVNintentName="OVNintentName" +OVNHostName="OVNHostName" +OVNPort="9027" +CostBasedIntent="costBasedIntent" +CostBasedIntentName="CostBasedIntentName" +CostBasedHostName="OVNHostName" +CostBasedPort="9028" +hpaIntent="hpaIntent" +trafficIntent="trafficIntent" +gpcHostName="gpcHostName" +gpcPort="9029" +hpaControllerIntentName="hpaControllerIntentName" +hpaHostName="hpaHostName" +hpaPort="9030" +trafficControllerIntentName="trafficControllerIntentName" +trafficHostName="trafficHostName" +trafficPort="9031" diff --git a/kud/tests/negative_tests/readme.txt b/kud/tests/negative_tests/readme.txt new file mode 100644 index 00000000..d6cdcdce --- /dev/null +++ b/kud/tests/negative_tests/readme.txt @@ -0,0 +1,19 @@ +These negative tests that validate EMCO open APIs with various invalid +inputs can be run individually or all together. + +Step 1: + cd k8s/src/orchestrator/scripts + start-dev.sh + ctrl z + bg + +Step 2: + cd k8s/kud/tests/negative_tests + ./test_all_final.sh + +OR + +Step 2: + cd k8s/kud/tests/negative_tests + ./test_<name>.sh + example: ./test_project.sh diff --git a/kud/tests/negative_tests/test_all_final.sh b/kud/tests/negative_tests/test_all_final.sh new file mode 100755 index 00000000..c986e03b --- /dev/null +++ b/kud/tests/negative_tests/test_all_final.sh @@ -0,0 +1,29 @@ + +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script to run all the tests at once + +./test_all_intents.sh +./test_composite_app.sh +./test_deployment_intent_group.sh +./test_controllers.sh +./test_generic_placement_intent_app.sh +./test_generic_placement_intent.sh +./test_multipart.sh +./test_profile_apps.sh +./test_profile.sh +./test_project.sh diff --git a/kud/tests/negative_tests/test_all_intents.sh b/kud/tests/negative_tests/test_all_intents.sh new file mode 100755 index 00000000..1f2f721f --- /dev/null +++ b/kud/tests/negative_tests/test_all_intents.sh @@ -0,0 +1,122 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_all_intents.sh +# Purpose: To ascertain whether or not the POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I have assigned. + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Setup +install_deps +populate_CSAR_composite_app_helm "$csar_id" + +# clean up +delete_all + +# Create project +create_project + +# Create composite app +create_composite_app + +create_app "collectd.tar.gz" "collectd" "collectd_desc" +create_app "prometheus-operator.tar.gz" "prometheus" "prometheus_desc" + +create_main_composite_profile + +create_profile_app "test_composite_profile1" "collectd" "collectd_profile.tar.gz" +create_profile_app "test_composite_profile2" "prometheus" "prometheus-operator_profile.tar.gz" + +create_generic_placement_intent_app1 + +create_placement_intent_app "appIntentForApp1" "AppIntentForApp1Desc" "collectd" +create_placement_intent_app "appIntentForApp2" "AppIntentForApp2Desc" "prometheus" + +create_deployment_intent_group + +# BEGIN: Adding intents to an intent group +print_msg "Adding all the intents to the deploymentIntent group" +intentToBeAddedinDeploymentIntentGroup="" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${intentToBeAddedinDeploymentIntentGroup}", + "description":"${intentToBeAddedinDeploymentIntentGroupDesc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "intent":{ + "${genericPlacementIntent}":"${genericPlacementIntentName}", + "${hpaIntent}" : "${hpaControllerIntentName}", + "${trafficIntent}" : "${trafficControllerIntentName}", + "${CostBasedIntent}" : "${CostBasedIntentName}", + "${OVNintent}" : "${OVNintentName}" + } + } +} +EOF +)" + +# Test-1 +# register null intenttoBeAddedinDeploymentIntentGroup +call_api_negative -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents" + +if [ $return_status == 405 ] ;then + print_msg "Test:all_intents post with null all_intents name. Expected = 405, Actual = $return_status PASSED" +else + print_msg "Test:all_intents-post with null all_intents name. Expected = 405, Actual = $return_status FAILED" +fi + +# Test-2 +# delete null intenttoBeAddedinDeploymentIntentGroup +intentToBeAddedinDeploymentIntentGroup="" +print_msg "Deleting intentToBeAddedinDeploymentIntentGroup" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents/${intentToBeAddedinDeploymentIntentGroup}" +if [ $return_status == 404 ] ;then + print_msg "Test:all_intents-delete with null all_intents name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:all_intents-delete with null all_intents name. Expected = 404, Actual = $return_status FAILED" +fi + +# Test-3 +# get null intenttoBeAddedinDeploymentIntentGroup +intentToBeAddedinDeploymentIntentGroup="" +print_msg "Deleting intentToBeAddedinDeploymentIntentGroup" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}/intents/${intentToBeAddedinDeploymentIntentGroup}" + +if [ $return_status == 404 ] ;then + print_msg "Test:all_intents-get with null all_intents name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:all_intents-get with null all_intents name. Expected = 404, Actual = $return_status FAILED" +fi + +delete_all +# END diff --git a/kud/tests/negative_tests/test_composite_app.sh b/kud/tests/negative_tests/test_composite_app.sh new file mode 100755 index 00000000..8656a1d8 --- /dev/null +++ b/kud/tests/negative_tests/test_composite_app.sh @@ -0,0 +1,95 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_composite_app.sh +# Purpose: To ascertain whether or not POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I assigned + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Clean up +delete_all + +# Register project +create_project + +# TEST-1 +# Register a null composite app +composite_app_name="" +composite_app_description="test_project_description" +composite_app_version="test_composite_app_version" +userData1="user1" +userData2="user2" + +print_msg "Registering composite-app" +payload="$(cat <<EOF +{ + "metadata": { + "name": "${composite_app_name}", + "description": "${composite_app_description}", + "userData1": "${userData1}", + "userData2": "${userData2}" + }, + "spec":{ + "version":"${composite_app_version}" + } +} +EOF +)" +call_api_negative -d "${payload}" "${base_url}/projects/${project_name}/composite-apps" +if [ $return_status == 405 ] ;then +print_msg "Test: composite application post expected value = 405 actual value = $return_status PASSED" +else +print_msg "Test: composite application post expected value = 405 actual value = $return_status FAILED" +fi + +# TEST-2 +# Delete a non existing composite app +composite_app_name="" +print_msg "Deleting ${composite_app_name}/${composite_app_version}" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}" +if [ $return_status == 400 ] ;then +print_msg "Test: composite application delete expected value = 400 actual value = $return_status PASSED" +else +print_msg "Test: composite application delete expected value = 400 actual value = $return_status FAILED" +fi + +# Test-3 +# Delete a non existing composite app +composite_app_name="" +print_msg "Deleting ${composite_app_name}/${composite_app_version}" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}" +if [ $return_status == 400 ] ;then +print_msg "Test: composite application get expected value = 400 actual value = $return_status PASSED" +else +print_msg "Test: composite application get expected value = 400 actual value = $return_status FAILED" +fi + +delete_all +#END diff --git a/kud/tests/negative_tests/test_controllers.sh b/kud/tests/negative_tests/test_controllers.sh new file mode 100755 index 00000000..20e6bda0 --- /dev/null +++ b/kud/tests/negative_tests/test_controllers.sh @@ -0,0 +1,94 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_controllers.sh +# Purpose: to determine whether or not cost based, HPA, traffic, and OVN controllers work. + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Setup +install_deps + +# Clean up +delete_all + +#testing costBased placement controller +print_msg "Adding CostBased placement controller" +CostBasedIntent="" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${CostBasedIntent}", + "description":"${CostBasedIntentName}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "host": "${CostBasedHostName}", + "port": ${CostBasedPort}, + "type": "placement", + "priority": 3 + } +} +EOF +)" + +# Test-1 +# register null CostBasedIntent +call_api_negative -d "${payload}" "${base_url}/controllers" +if [ $return_status == 405 ] ;then + print_msg "Test:cost_based_controller-post-1 with null cost_based_controller name. Expected = 405, Actual = $return_status PASSED" +else + print_msg "Test:cost_based_controller-post1 with null cost_based_controller name. Expected = 405, Actual = $return_status FAILED" +fi + +# Test-2 +# delete null CostBasedIntent +CostBasedIntent="" +print_msg "Deleting controller ${CostBasedIntent}" +delete_resource_negative "${base_url}/controllers/${CostBasedIntent}" +if [ $return_status == 400 ] ;then + print_msg "Test:cost_based_controller-delete-1 with null project name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:cost_based_controller-delete-1 with null project name. Expected = 400, Actual = $return_status FAILED" +fi + +# Test-3 +# get null CostBasedIntent +CostBasedIntent="" +print_msg "getting controller ${CostBasedIntent}" +get_resource_negative "${base_url}/controllers/${CostBasedIntent}" +if [ $return_status == 404 ] ;then + print_msg "Test:cost_based_controller-get-1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:cost_based_controller-get-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + +delete_all +#END diff --git a/kud/tests/negative_tests/test_deployment_intent_group.sh b/kud/tests/negative_tests/test_deployment_intent_group.sh new file mode 100755 index 00000000..402a0b1d --- /dev/null +++ b/kud/tests/negative_tests/test_deployment_intent_group.sh @@ -0,0 +1,135 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_deployment_intent_group.sh +# Purpose: To ascertain whether or not the POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I have assigned. + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Setup +install_deps +populate_CSAR_composite_app_helm "$csar_id" + +# Cleanup +delete_all + +# Register project +create_project + +# Register composite-app +create_composite_app + +# Create entries for app1&app2 in the database +create_app "collectd.tar.gz" "collectd" "collectd_desc" +create_app "prometheus-operator.tar.gz" "prometheus" "prometheus_desc" + +# Register the main composite-profile +create_main_composite_profile + +# Adding profile to each of the two apps - app1(collectd) and app2(prometheus) +create_profile_app "test_composite_profile1" "collectd" "collectd_profile.tar.gz" +create_profile_app "test_composite_profile2" "prometheus" "prometheus-operator_profile.tar.gz" + +# Register GenericPlacementIntents with the database +create_generic_placement_intent_app1 + +# Adding placement intent for each app in the composite app. +create_placement_intent_app "appIntentForApp1" "AppIntentForApp1Desc" "collectd" +create_placement_intent_app "appIntentForApp2" "AppIntentForApp2Desc" "prometheus" + +# BEGIN: Registering DeploymentIntentGroup in the database +print_msg "Registering DeploymentIntentGroup" + +deploymentIntentGroupName="" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${deploymentIntentGroupName}", + "description":"${deploymentIntentGroupNameDesc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "profile":"${main_composite_profile_name}", + "version":"${releaseName}", + "override-values":[ + { + "app-name":"${app1_name}", + "values": + { + "collectd_prometheus.service.targetPort":"9104" + } + }, + { + "app-name":"${app2_name}", + "values": + { + "prometheus.service.nameOfPort":"WebPort9090" + } + } + ] + } +} +EOF +)" + +# Test-1 +# register null deploymentIntentGroupName +call_api_negative -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups" +if [ $return_status == 405 ] ;then + print_msg "Test:deployment_intent_group post-1 with null name. Expected = 405, Actual = $return_status PASSED" +else + print_msg "Test:deployment_intent_group post1 with null name. Expected = 405, Actual = $return_status FAILED" +fi + +# Test-2 +# delete null deploymentIntentGroupName +deploymentIntentGroupName="" +print_msg "Deleting ${deploymentIntentGroupName}" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}" +if [ $return_status == 404 ] ;then + print_msg "Test:deployment_intent_group-delete-1 with null name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:deployment_intent_group-delete-1 with null name. Expected = 404, Actual = $return_status FAILED" +fi + +# Test-3 +# get null deploymentIntentGroupName +deploymentIntentGroupName="" +print_msg "Getting ${deploymentIntentGroupName}" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/deployment-intent-groups/${deploymentIntentGroupName}" +if [ $return_status == 404 ] ;then + print_msg "Test:deployment_intent_group-get-1 with null name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:deployment_intent_group-get-1 with null name. Expected = 404, Actual = $return_status FAILED" +fi + +delete_all +#END diff --git a/kud/tests/negative_tests/test_generic_placement_intent.sh b/kud/tests/negative_tests/test_generic_placement_intent.sh new file mode 100755 index 00000000..708180f8 --- /dev/null +++ b/kud/tests/negative_tests/test_generic_placement_intent.sh @@ -0,0 +1,111 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_generic_placement_intent.sh +# Purpose: To ascertain whether or not the POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I have assigned. + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +install_deps +populate_CSAR_composite_app_helm "$csar_id" + +# Cleanup +delete_all + +# Register project +create_project + +# Register composite-app +create_composite_app + +# Create entries for app1&app2 in the database +create_app "collectd.tar.gz" "collectd" "collectd_desc" +create_app "prometheus-operator.tar.gz" "prometheus" "prometheus_desc" + +# Register the main composite-profile +create_main_composite_profile + +# Adding profile to each of the two apps - app1(collectd) and app2(prometheus) +create_profile_app "test_composite_profile1" "collectd" "collectd_profile.tar.gz" +create_profile_app "test_composite_profile2" "prometheus" "prometheus-operator_profile.tar.gz" + +# Register GenericPlacementIntents with the database +print_msg "Registering GenericPlacementIntent for app1" + +genericPlacementIntentName="" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${genericPlacementIntentName}", + "description":"${genericPlacementIntentDesc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "logical-cloud":"${logicalCloud}" + } +} +EOF +)" + +# Test-1 +# register a null genericPlacementIntentName +call_api_negative -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents" +if [ $return_status == 405 ] ;then + print_msg "Test:generic_placement_intent_post1 with null project name. Expected = 405, Actual = $return_status PASSED" +else + print_msg "Test:generic_placement_intent post-1 with null project name. Expected = 405, Actual = $return_status FAILED" +fi + +# Test-2 +# delete a null genericPlacementIntentName +genericPlacementIntentName="" +print_msg "Deleting ${genericPlacementIntentName}" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}" +if [ $return_status == 404 ] ;then + print_msg "Test:generic_placement_intent delete1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:generic_placement_intent_ delete-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + +# Test-2 +# get a null genericPlacementIntentName +genericPlacementIntentName="" +print_msg "Deleting ${genericPlacementIntentName}" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}" +if [ $return_status == 404 ] ;then + print_msg "Test:generic_placement_intent get1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:generic_placement_intent_ get-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + +delete_all +#END + diff --git a/kud/tests/negative_tests/test_generic_placement_intent_app.sh b/kud/tests/negative_tests/test_generic_placement_intent_app.sh new file mode 100755 index 00000000..23e7dd00 --- /dev/null +++ b/kud/tests/negative_tests/test_generic_placement_intent_app.sh @@ -0,0 +1,134 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_generic_placement_intent_app.sh +# Purpose: To ascertain whether or not the POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I have assigned. + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Setup +install_deps +populate_CSAR_composite_app_helm "$csar_id" + +# Clean up +delete_all + +# Register project +create_project + +# Register composite-app +create_composite_app + +# Create entries for app1&app2 in the database +create_app "collectd.tar.gz" "collectd" "collectd_desc" +create_app "prometheus-operator.tar.gz" "prometheus" "prometheus_desc" + +# Register the main composite-profile +create_main_composite_profile + +# Adding profile to each of the two apps - app1(collectd) and app2(prometheus) +create_profile_app "test_composite_profile1" "collectd" "collectd_profile.tar.gz" +create_profile_app "test_composite_profile2" "prometheus" "prometheus-operator_profile.tar.gz" + +# Register GenericPlacementIntents with the database +create_generic_placement_intent_app1 + +# Adding placement intent for each app in the composite app. +print_msg "Adding placement intent for app1(collectd)" +appIntentNameForApp1="" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${appIntentNameForApp1}", + "description":"${appIntentForApp1Desc}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "app-name":"${app1_name}", + "intent":{ + "allOf":[ + { "provider-name":"${providerName1}", + "cluster-name":"${clusterName1}" + }, + { + "provider-name":"${providerName2}", + "cluster-name":"${clusterName2}" + }, + { + "anyOf":[ + { + "provider-name":"${providerName1}", + "cluster-label-name":"${clusterLabelName1}" + }, + { + "provider-name":"${providerName2}", + "cluster-label-name":"${clusterLabelName2}" + } + ] + } + ] + } + } +} +EOF +)" + +# Test-1 +# register with null va;ue +call_api_negative -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents" +if [ $return_status == 400 ] ;then + print_msg "Test:generic_placement_intent_app-post1 with null project name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:generic_placement_intent_app post-1 with null project name. Expected = 400, Actual = $return_status FAILED" +fi + +# Test-2 +# delete a mull +print_msg "Deleting ${appIntentNameForApp1}" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents/${appIntentNameForApp1}" +if [ $return_status == 400 ] ;then + print_msg "Test:generic_placement_intent_app-delete1 with null project name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:generic_placement_intent_app delete-1 with null project name. Expected = 400, Actual = $return_status FAILED" +fi + +# Test-3 +# get a null +print_msg "Deleting ${appIntentNameForApp1}" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/generic-placement-intents/${genericPlacementIntentName}/app-intents/${appIntentNameForApp1}" +if [ $return_status == 400 ] ;then + print_msg "Test:generic_placement_intent_app-get1 with null project name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:generic_placement_intent_app get-1 with null project name. Expected = 400, Actual = $return_status FAILED" +fi + +delete_all +#END diff --git a/kud/tests/negative_tests/test_multipart.sh b/kud/tests/negative_tests/test_multipart.sh new file mode 100755 index 00000000..7f4a84be --- /dev/null +++ b/kud/tests/negative_tests/test_multipart.sh @@ -0,0 +1,95 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_multipart.sh +# Purpose: To ascertain whether or not POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I assigned + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Cleanup +delete_all + +# Register project +create_project + +# Register composite-app +create_composite_app + +# Create entries for app1&app2 in the database +print_msg "Making app entry in the database" +payload="$(cat <<EOF +{ + "metadata": { + "name": "${app1_name}", + "description": "${app1_desc}", + "userData1": "${userData1}", + "userData2": "${userData2}" + } +} +EOF +)" + +# Test-1 +# registering null app1_helm_path +app1_helm_path="" + +call_api_negative -F "metadata=$payload" \ + -F "file=@$app1_helm_path" \ + "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps" +if [ $return_status == 400 ] ;then + print_msg "Test:multipart-post-1 with null name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:multipart pos-1 with null name. Expected = 400, Actual = $return_status FAILED" +fi + +# Test-2 +# deleting a null app name +app1_name="" +print_msg "Deleting ${app1_name}" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps/${app1_name}" +if [ $return_status == 400 ] ;then + print_msg "Test:multipart delete-1 with null name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:multipart delete-1 with null name. Expected = 400, Actual = $return_status FAILED" +fi + +# Test-3 +# geting a null app name +app1_name="" +print_msg "getting ${app1_name}" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/apps/${app1_name}" +if [ $return_status == 400 ] ;then + print_msg "Test:multipart get-1 with null name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:multipart get-1 with null name. Expected = 400, Actual = $return_status FAILED" +fi + +delete_all +#END diff --git a/kud/tests/negative_tests/test_profile.sh b/kud/tests/negative_tests/test_profile.sh new file mode 100755 index 00000000..c5002d50 --- /dev/null +++ b/kud/tests/negative_tests/test_profile.sh @@ -0,0 +1,101 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_profile.sh +# Purpose: To ascertain whether or not POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I assigned + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Setup +install_deps +populate_CSAR_composite_app_helm "$csar_id" + +# Cleanup +delete_all + +# Register project +create_project + +# Register composite-app +create_composite_app + +# Create entries for app1&app2 in the database +create_app "collectd.tar.gz" "collectd" "collectd_desc" +create_app "prometheus-operator.tar.gz" "prometheus" "prometheus_desc" + +# TEST-1 null composite app name +# BEGIN: Register the main composite-profile +print_msg "Registering the main composite-profile" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${main_composite_profile_name}", + "description":"${main_composite_profile_description}", + "userData1":"${userData1}", + "userData2":"${userData2}" + } +} +EOF +)" + +# Test-1 +# registering a null composite_app_name +composite_app_name="" +call_api_negative -d "${payload}" "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles" +if [ $return_status == 405 ] ;then + print_msg "Test:profile post-1 with null project name. Expected = 405, Actual = $return_status PASSED" +else + print_msg "Test:profile post-1 with null project name. Expected = 405, Actual = $return_status FAILED" +fi + +# TEST-2 +# deleting null composite profile name +main_composite_profile_name="" +print_msg "Deleting ${main_composite_profile_name}" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}" +if [ $return_status == 404 ] ;then + print_msg "Test:profile delete-1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:profile delete-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + +# TEST-3 +# getting null main composite profile name +main_composite_profile_name="" +print_msg "Deleting ${main_composite_profile_name}" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}" +if [ $return_status == 404 ] ;then + print_msg "Test:profile get-1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:profile get-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + +delete_all +#END diff --git a/kud/tests/negative_tests/test_profile_apps.sh b/kud/tests/negative_tests/test_profile_apps.sh new file mode 100755 index 00000000..ca8c6454 --- /dev/null +++ b/kud/tests/negative_tests/test_profile_apps.sh @@ -0,0 +1,109 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_profile_apps.sh +# Purpose: To ascertain whether or not the POST/DELETE/GET API is able to register a null name +# Description, userdata1, and userdata2 have values that I have assigned. + +set -o errexit +set -o nounset +set -o pipefail + +source _test_functions.sh + +if [ ${1:+1} ]; then + if [ "$1" == "--external" ]; then + master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \ + awk -F ":" '{print $2}' | awk -F "//" '{print $2}') + onap_svc_node_port=30498 + base_url="http://$master_ip:$onap_svc_node_port/v1" + fi +fi + +# Setup +install_deps +populate_CSAR_composite_app_helm "$csar_id" + +# Clean up +delete_all + +# Register project +create_project + +# Register composite-app +create_composite_app + +# Create entries for app1&app2 in the database +create_app "collectd.tar.gz" "collectd" "collectd_desc" +create_app "prometheus-operator.tar.gz" "prometheus" "prometheus_desc" + +# Register the main composite-profile +create_main_composite_profile + + +# TEST-1 null main composite profile name +# BEGIN : Adding profile to each of the two apps - app1(collectd) and app2(prometheus) +print_msg "Registering profile with app1(collectd)" +payload="$(cat <<EOF +{ + "metadata":{ + "name":"${sub_composite_profile_name1}", + "description":"${sub_composite_profile_description}", + "userData1":"${userData1}", + "userData2":"${userData2}" + }, + "spec":{ + "app-name": "${app1_name}" + } +} +EOF +)" + +main_composite_profile_name="" + +call_api_negative -F "metadata=$payload" \ + -F "file=@$app1_profile_path" \ + "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles" +if [ $return_status == 405 ] ;then + print_msg "Test:profile app post-1 with null project name. Expected = 405, Actual = $return_status PASSED" +else + print_msg "Test:profile app post-1 with null project name. Expected = 405, Actual = $return_status FAILED" +fi + +# TEST-2 +# delete null sub composite profile name +sub_composite_profile_name1="" +print_msg "Deleting ${sub_composite_profile_name1}" +delete_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles/${sub_composite_profile_name1}" +if [ $return_status == 404 ] ;then + print_msg "Test:profile app delete-1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:profile app delete-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + + +# TEST-3 +# null get sub composite profile name +print_msg "Deleting ${sub_composite_profile_name1}" +get_resource_negative "${base_url}/projects/${project_name}/composite-apps/${composite_app_name}/${composite_app_version}/composite-profiles/${main_composite_profile_name}/profiles/${sub_composite_profile_name1}" +if [ $return_status == 404 ] ;then + print_msg "Test:profile app get-1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:profile app get-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + +delete_all +#END diff --git a/kud/tests/negative_tests/test_project.sh b/kud/tests/negative_tests/test_project.sh new file mode 100755 index 00000000..3ddfb283 --- /dev/null +++ b/kud/tests/negative_tests/test_project.sh @@ -0,0 +1,75 @@ +# /* +# * Copyright 2020 Intel Corporation, Inc +# * +# * 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. +# */ + +# Script name: ./test_project.sh +# Purpose: Verify if POST/DELETE/GET API calls succeed with invalid/null name +# Expected Results: POST api should fail and return code as documented (example:400) + +source _test_functions.sh + +# TEST-1 Registering null project name +print_msg "Registering project with null project_name" +project_name="" +payload="$(cat <<EOF +{ + "metadata": { + "name": "${project_name}", + "description": "${project_description}", + "userData1": "${userData1}", + "userData2": "${userData2}" + } +} +EOF +)" +call_api_negative -d "${payload}" "${base_url}/projects" +if [ $return_status == 400 ] ;then + print_msg "Test:project-post with null project name. Expected = 400, Actual = $return_status PASSED" +else + print_msg "Test:project-post with null project name. Expected = 400, Actual = $return_status FAILED" +fi + +# TEST-2 Delete a null project +project_name="" +print_msg "Deleting ${project_name}" +delete_resource_negative "${base_url}/projects/${project_name}" +if [ $return_status == 404 ] ;then + print_msg "Test:project-delete-1 with null project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:project-delete-1 with null project name. Expected = 404, Actual = $return_status FAILED" +fi + +# TEST-3 Delete a non existing project +project_name="foo" +print_msg "Deleting ${project_name}" +delete_resource_negative "${base_url}/projects/${project_name}" +if [ $return_status == 404 ] ;then + print_msg "Test:project-delete-2 with invalid project name. Expected = 404, Actual = $return_status PASSED" +else + print_msg "Test:project-delete-2 with invalid project name. Expected = 404, Actual = $return_status FAILED" +fi + +# TEST-4 Get an invalid project +project_name="foo" +get_resource_negative "${base_url}/projects/${project_name}" +if [ $return_status == 404 ] ;then + print_msg "Test:project-get with null project name. Expected = 404, \ + Actual = $return_status PASSED" +else + print_msg "Test:project-get with null project name. Expected = 404, \ + Actual = $return_status FAILED" +fi + +# END |