| #!/bin/bash |
| # |
| # ============LICENSE_START======================================================= |
| # Copyright (C) 2022 Nordix Foundation. |
| # ================================================================================ |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| # SPDX-License-Identifier: Apache-2.0 |
| # ============LICENSE_END========================================================= |
| # |
| 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="" |
| CERT="MIICnTCCAYUCBgF/iApKsDANBgkqhkiG9w0BAQsFADASMRAwDgYDVQQDDAdzdGVwLWNhMB4XDTIyMDMxNDEwNDU1MFoXDTMyMDMxNDEwNDczMFowEjEQMA4GA1UEAwwHc3RlcC1jYTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAIreIwbXPJPUDNaljbmI7WQRQqjSVjtSqcLGiUuZKl5HTXIFgWwF5IAstw4hUDs+zGu2xrGvJ6+pzUi0q8gj/ddrYZmR5degJKK/g8FLrFIiq4nIyCYM9WuQZDIe0Hkk4aTa+TJnJ609LuRvJMR8nK/sz+/FOLmcZJgcD5KTcECRIvzBcHzIUxl/Q6wjRl9+tFBlZMS1pDcKlb06YnkJIpawG/3vnl62aU5CKDJrKq0wcQiaWrpmo0eWy+EK3qMPar1AdaJWM5tgOz8uA+AlQtKMv6vRUBseERuU0n6kFLGIpzeO/dvTDuZ43LYLr9x5uJHpj+IYyHbA9lZt62GL/icCAwEAATANBgkqhkiG9w0BAQsFAAOCAQEAYUUzFbXMaIu8ARVOTRdNgrtSAz498CPe2k/ZiGcGAjvfrgmF1nzbE/8yzuKu+x/fdooCE+0rhwH1h9yb43NaKQ59uN/g7tmSm3G4lUwXS04c6g1F5UR0+Bk1QwnhZsUNQZ14gtYSK+P9DOggskF+wHyknTD5KD0tfJJ+qv6wKFZuNXKcXq4vC+s691R3SZjKaNtaoNgdWqb+T/kIEECB3DLA7Hn2ZqrdqDWdvHDuaMDVHnrBuddQaEfrrXU2R4NuA0KenYhAfs9H1HM8M6V3+KNP0C04ngsIjRsGcwJmqK7dHs4k+fXr95KD0IpRkqEuYIIFrsNWPa/A1gwMiTLdpw==" |
| |
| function get_token |
| { |
| local prefix="${1}" |
| url="http://192.168.49.2:31560/auth/realms" |
| # echo $url |
| TOKEN=$(curl -s -X POST $url/hwrealm/protocol/openid-connect/token -H \ |
| "Content-Type: application/x-www-form-urlencoded" -d client_secret=g4kqnQU5urU04OCxoWaGEGdwynFHLhqJ \ |
| -d 'grant_type=client_credentials' -d client_id=step-ca) |
| 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/hwrealm/protocol/openid-connect/token -H \ |
| "Content-Type: application/x-www-form-urlencoded" \ |
| -d code=$CERT \ |
| -d 'grant_type=authorization_code' -d client_id=step-ca) |
| 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 "-----------------------------------------------------------------------" |