blob: e3a7110c4f3d1d2fa75f301426d02e069620b8f7 [file] [log] [blame]
#!/bin/bash
INGRESS_HOST=$(minikube ip)
INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
TESTS=0
PASSED=0
FAILED=0
TEST_TS=$(date +%F-%T)
TOKEN=""
ACCESS_TOKEN=""
REFRESH_TOKEN=""
function get_token
{
local prefix="${1}"
url="http://192.168.49.2:31560/auth/realms"
# echo $url
TOKEN=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
"Content-Type: application/x-www-form-urlencoded" -d client_secret=OwTCeahULA21G5TfEVMLG1iMloGiyH3i \
-d 'grant_type=client_credentials' -d client_id=provider-cli)
echo "TOKEN: $TOKEN"
ACCESS_TOKEN=$(echo $TOKEN | jq -r '.access_token')
#echo "ACCESS_TOKEN: $ACCESS_TOKEN"
REFRESH_TOKEN=$(echo $TOKEN | jq -r '.refresh_token')
#echo "REFRESH_TOKEN: $REFRESH_TOKEN"
# TOKEN2=$(curl -s -X POST $url/provider/protocol/openid-connect/token -H \
# "Content-Type: application/x-www-form-urlencoded" -d client_secret= \
# -d refresh_token=$REFRESH_TOKEN \
# -d 'grant_type=refresh_token' -d client_id=provider-cli)
#echo "TOKEN2 = $TOKEN2"
#ACCESS_TOKEN=""
echo $ACCESS_TOKEN
}
function run_test
{
local prefix="${1}" type=${2} msg="${3}" data=${4}
TESTS=$((TESTS+1))
echo "Test ${TESTS}: Testing $type /${prefix}"
get_token $prefix
url=$INGRESS_HOST:$INGRESS_PORT"/"$prefix
#echo $url
result=$(curl -s -X ${type} -H "Content-type: application/json" -H "Authorization: Bearer $ACCESS_TOKEN" $url)
echo $result
if [ "$result" != "$msg" ]; then
echo "FAIL"
FAILED=$((FAILED+1))
else
echo "PASS"
PASSED=$((PASSED+1))
fi
echo ""
}
run_test "rapp-provider" "GET" "Hello World!" ""
echo
echo "-----------------------------------------------------------------------"
echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED"
echo "Date: $TEST_TS"
echo "-----------------------------------------------------------------------"