Merge "Sample consumer to get kafka broker from ICS"
[nonrtric.git] / service-exposure / rp_test.sh
1 #!/bin/bash
2 #
3 # ============LICENSE_START=======================================================
4 #  Copyright (C) 2022 Nordix Foundation.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #      http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
20 #
21 INGRESS_HOST=$(minikube ip)
22 INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
23 TESTS=0
24 PASSED=0
25 FAILED=0
26 TEST_TS=$(date +%F-%T)
27 TOKEN=""
28 ACCESS_TOKEN=""
29 REFRESH_TOKEN=""
30
31 function get_token
32 {
33     local prefix="${1}"
34     url="http://192.168.49.2:31560/auth/realms"
35          TOKEN=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
36                  "Content-Type: application/x-www-form-urlencoded" -d client_secret=OwTCeahULA21G5TfEVMLG1iMloGiyH3i \
37                  -d 'grant_type=client_credentials' -d client_id=provider-cli)
38         echo "TOKEN: $TOKEN"
39         ACCESS_TOKEN=$(echo $TOKEN | jq -r '.access_token')
40         REFRESH_TOKEN=$(echo $TOKEN | jq -r '.refresh_token')
41     echo $ACCESS_TOKEN
42 }
43
44 function run_test
45 {
46     local prefix="${1}" type=${2} msg="${3}" data=${4}
47     TESTS=$((TESTS+1))
48     echo "Test ${TESTS}: Testing $type /${prefix}"
49     get_token $prefix
50     url=$INGRESS_HOST:$INGRESS_PORT"/"$prefix
51     #echo $url
52     result=$(curl -s -X ${type} -H "Content-type: application/json" -H "Authorization: Bearer $ACCESS_TOKEN" $url)
53     echo $result
54     if [ "$result" != "$msg" ]; then
55             echo "FAIL"
56             FAILED=$((FAILED+1))
57     else
58             echo "PASS"
59             PASSED=$((PASSED+1))
60     fi
61     echo ""
62 }
63
64
65 run_test "rapp-provider" "GET" "Hello World!" ""
66
67 echo
68 echo "-----------------------------------------------------------------------"
69 echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED"
70 echo "Date: $TEST_TS"
71 echo "-----------------------------------------------------------------------"