blob: c26f9aef8795d8469c6d623ee775f4d8014bf0b2 [file] [log] [blame]
ktimoney28fa9fb2022-05-30 16:08:27 +01001#!/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#
21INGRESS_HOST=$(minikube ip)
22INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
23TESTS=0
24PASSED=0
25FAILED=0
26TEST_TS=$(date +%F-%T)
27TOKEN=""
28ACCESS_TOKEN=""
29REFRESH_TOKEN=""
30
31function get_token
32{
ktimoney2513eea2022-10-03 15:02:44 +010033 local prefix="${1}"
ktimoney28fa9fb2022-05-30 16:08:27 +010034 url="http://192.168.49.2:31560/auth/realms"
ktimoney28fa9fb2022-05-30 16:08:27 +010035 TOKEN=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
36 "Content-Type: application/x-www-form-urlencoded" -d client_secret=OwTCeahULA21G5TfEVMLG1iMloGiyH3i \
ktimoney2513eea2022-10-03 15:02:44 +010037 -d 'grant_type=client_credentials' -d client_id=provider-cli)
ktimoney28fa9fb2022-05-30 16:08:27 +010038 echo "TOKEN: $TOKEN"
39 ACCESS_TOKEN=$(echo $TOKEN | jq -r '.access_token')
ktimoney28fa9fb2022-05-30 16:08:27 +010040 REFRESH_TOKEN=$(echo $TOKEN | jq -r '.refresh_token')
ktimoney28fa9fb2022-05-30 16:08:27 +010041 echo $ACCESS_TOKEN
42}
43
44function 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
65run_test "rapp-provider" "GET" "Hello World!" ""
66
67echo
68echo "-----------------------------------------------------------------------"
69echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED"
70echo "Date: $TEST_TS"
71echo "-----------------------------------------------------------------------"