blob: 20eca218add443b83e80bcd2cea40c98b0a09a9c [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 \
18 "Content-Type: application/x-www-form-urlencoded" -d client_secret=to6qrqxLj0mwHKS8e3E7s1zzDHsNg1Ua \
19 -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"
25 TOKEN2=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
26 "Content-Type: application/x-www-form-urlencoded" -d client_secret=to6qrqxLj0mwHKS8e3E7s1zzDHsNg1Ua \
27 -d refresh_token=$REFRESH_TOKEN \
28 -d 'grant_type=refresh_token' -d client_id=provider-cli)
29 #echo "TOKEN2 = $TOKEN2"
30 #ACCESS_TOKEN=""
31 #echo $ACCESS_TOKEN
32}
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 "-----------------------------------------------------------------------"