blob: c1d07a289871318692d3818927ea2b4fe13d20d2 [file] [log] [blame]
ktimoneyf27b5132022-03-07 16:48:47 +00001#!/bin/bash
ktimoney3570d5a2022-05-24 13:54:55 +01002#
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#
ktimoneyf27b5132022-03-07 16:48:47 +000021INGRESS_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{
33 local prefix="${1}"
34 url="http://192.168.49.2:31560/auth/realms"
35 # echo $url
36 TOKEN=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
ktimoney90fcec92022-04-29 15:46:50 +010037 "Content-Type: application/x-www-form-urlencoded" -d client_secret=OwTCeahULA21G5TfEVMLG1iMloGiyH3i \
ktimoneyf27b5132022-03-07 16:48:47 +000038 -d 'grant_type=client_credentials' -d client_id=provider-cli)
39 echo "TOKEN: $TOKEN"
40 ACCESS_TOKEN=$(echo $TOKEN | jq -r '.access_token')
41 #echo "ACCESS_TOKEN: $ACCESS_TOKEN"
42 REFRESH_TOKEN=$(echo $TOKEN | jq -r '.refresh_token')
43 #echo "REFRESH_TOKEN: $REFRESH_TOKEN"
ktimoney90fcec92022-04-29 15:46:50 +010044 # TOKEN2=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
45 # "Content-Type: application/x-www-form-urlencoded" -d client_secret= \
46 # -d refresh_token=$REFRESH_TOKEN \
47 # -d 'grant_type=refresh_token' -d client_id=provider-cli)
ktimoneyf27b5132022-03-07 16:48:47 +000048 #echo "TOKEN2 = $TOKEN2"
49 #ACCESS_TOKEN=""
ktimoney90fcec92022-04-29 15:46:50 +010050 echo $ACCESS_TOKEN
ktimoneyf27b5132022-03-07 16:48:47 +000051}
52
53function run_test
54{
55 local prefix="${1}" type=${2} msg="${3}" data=${4}
56 TESTS=$((TESTS+1))
57 echo "Test ${TESTS}: Testing $type /${prefix}"
58 get_token $prefix
59 url=$INGRESS_HOST:$INGRESS_PORT"/"$prefix
60 #echo $url
61 result=$(curl -s -X ${type} -H "Content-type: application/json" -H "Authorization: Bearer $ACCESS_TOKEN" $url)
62 echo $result
63 if [ "$result" != "$msg" ]; then
64 echo "FAIL"
65 FAILED=$((FAILED+1))
66 else
67 echo "PASS"
68 PASSED=$((PASSED+1))
69 fi
70 echo ""
71}
72
73
74run_test "rapp-provider" "GET" "Hello World!" ""
75
76echo
77echo "-----------------------------------------------------------------------"
78echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED"
79echo "Date: $TEST_TS"
80echo "-----------------------------------------------------------------------"