blob: e3a7110c4f3d1d2fa75f301426d02e069620b8f7 [file] [log] [blame]
ktimoneyf27b5132022-03-07 16:48:47 +00001#!/bin/bash
2INGRESS_HOST=$(minikube ip)
3INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
4TESTS=0
5PASSED=0
6FAILED=0
7TEST_TS=$(date +%F-%T)
8TOKEN=""
9ACCESS_TOKEN=""
10REFRESH_TOKEN=""
11
12function get_token
13{
14 local prefix="${1}"
15 url="http://192.168.49.2:31560/auth/realms"
16 # echo $url
17 TOKEN=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
ktimoney90fcec92022-04-29 15:46:50 +010018 "Content-Type: application/x-www-form-urlencoded" -d client_secret=OwTCeahULA21G5TfEVMLG1iMloGiyH3i \
ktimoneyf27b5132022-03-07 16:48:47 +000019 -d 'grant_type=client_credentials' -d client_id=provider-cli)
20 echo "TOKEN: $TOKEN"
21 ACCESS_TOKEN=$(echo $TOKEN | jq -r '.access_token')
22 #echo "ACCESS_TOKEN: $ACCESS_TOKEN"
23 REFRESH_TOKEN=$(echo $TOKEN | jq -r '.refresh_token')
24 #echo "REFRESH_TOKEN: $REFRESH_TOKEN"
ktimoney90fcec92022-04-29 15:46:50 +010025 # TOKEN2=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
26 # "Content-Type: application/x-www-form-urlencoded" -d client_secret= \
27 # -d refresh_token=$REFRESH_TOKEN \
28 # -d 'grant_type=refresh_token' -d client_id=provider-cli)
ktimoneyf27b5132022-03-07 16:48:47 +000029 #echo "TOKEN2 = $TOKEN2"
30 #ACCESS_TOKEN=""
ktimoney90fcec92022-04-29 15:46:50 +010031 echo $ACCESS_TOKEN
ktimoneyf27b5132022-03-07 16:48:47 +000032}
33
34function run_test
35{
36 local prefix="${1}" type=${2} msg="${3}" data=${4}
37 TESTS=$((TESTS+1))
38 echo "Test ${TESTS}: Testing $type /${prefix}"
39 get_token $prefix
40 url=$INGRESS_HOST:$INGRESS_PORT"/"$prefix
41 #echo $url
42 result=$(curl -s -X ${type} -H "Content-type: application/json" -H "Authorization: Bearer $ACCESS_TOKEN" $url)
43 echo $result
44 if [ "$result" != "$msg" ]; then
45 echo "FAIL"
46 FAILED=$((FAILED+1))
47 else
48 echo "PASS"
49 PASSED=$((PASSED+1))
50 fi
51 echo ""
52}
53
54
55run_test "rapp-provider" "GET" "Hello World!" ""
56
57echo
58echo "-----------------------------------------------------------------------"
59echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED"
60echo "Date: $TEST_TS"
61echo "-----------------------------------------------------------------------"