ktimoney | f27b513 | 2022-03-07 16:48:47 +0000 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | INGRESS_HOST=$(minikube ip) |
| 3 | INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}') |
| 4 | TESTS=0 |
| 5 | PASSED=0 |
| 6 | FAILED=0 |
| 7 | TEST_TS=$(date +%F-%T) |
| 8 | TOKEN="" |
| 9 | ACCESS_TOKEN="" |
| 10 | REFRESH_TOKEN="" |
| 11 | |
| 12 | function 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 | |
| 34 | function 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 | |
| 55 | run_test "rapp-provider" "GET" "Hello World!" "" |
| 56 | |
| 57 | echo |
| 58 | echo "-----------------------------------------------------------------------" |
| 59 | echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED" |
| 60 | echo "Date: $TEST_TS" |
| 61 | echo "-----------------------------------------------------------------------" |