ktimoney | 6be0529 | 2022-03-02 12:53:14 +0000 | [diff] [blame] | 1 | #!/bin/bash |
ktimoney | 3570d5a | 2022-05-24 13:54:55 +0100 | [diff] [blame] | 2 | # |
| 3 | # ============LICENSE_START======================================================= |
| 4 | # Copyright (C) 2022 Nordix Foundation. |
| 5 | # ================================================================================ |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # SPDX-License-Identifier: Apache-2.0 |
| 19 | # ============LICENSE_END========================================================= |
| 20 | # |
ktimoney | 6be0529 | 2022-03-02 12:53:14 +0000 | [diff] [blame] | 21 | INGRESS_HOST=$(minikube ip) |
| 22 | INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}') |
| 23 | TESTS=0 |
| 24 | PASSED=0 |
| 25 | FAILED=0 |
| 26 | TEST_TS=$(date +%F-%T) |
| 27 | TOKEN="" |
ktimoney | 90fcec9 | 2022-04-29 15:46:50 +0100 | [diff] [blame] | 28 | ACCESS_TOKEN="" |
| 29 | REFRESH_TOKEN="" |
| 30 | 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==" |
ktimoney | 6be0529 | 2022-03-02 12:53:14 +0000 | [diff] [blame] | 31 | |
| 32 | function get_token |
| 33 | { |
| 34 | local prefix="${1}" |
| 35 | url="http://192.168.49.2:31560/auth/realms" |
| 36 | # echo $url |
| 37 | TOKEN=$(curl -s -X POST $url/hwrealm/protocol/openid-connect/token -H \ |
ktimoney | 90fcec9 | 2022-04-29 15:46:50 +0100 | [diff] [blame] | 38 | "Content-Type: application/x-www-form-urlencoded" -d client_secret=g4kqnQU5urU04OCxoWaGEGdwynFHLhqJ \ |
| 39 | -d 'grant_type=client_credentials' -d client_id=step-ca) |
| 40 | echo "TOKEN: $TOKEN" |
| 41 | ACCESS_TOKEN=$(echo $TOKEN | jq -r '.access_token') |
| 42 | #echo "ACCESS_TOKEN: $ACCESS_TOKEN" |
| 43 | REFRESH_TOKEN=$(echo $TOKEN | jq -r '.refresh_token') |
| 44 | #echo "REFRESH_TOKEN: $REFRESH_TOKEN" |
| 45 | TOKEN2=$(curl -s -X POST $url/hwrealm/protocol/openid-connect/token -H \ |
| 46 | "Content-Type: application/x-www-form-urlencoded" \ |
| 47 | -d code=$CERT \ |
| 48 | -d 'grant_type=authorization_code' -d client_id=step-ca) |
| 49 | echo "TOKEN2 = $TOKEN2" |
| 50 | #ACCESS_TOKEN="" |
| 51 | #echo $ACCESS_TOKEN |
ktimoney | 6be0529 | 2022-03-02 12:53:14 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | function run_test |
| 55 | { |
| 56 | local prefix="${1}" type=${2} msg="${3}" data=${4} |
| 57 | TESTS=$((TESTS+1)) |
| 58 | echo "Test ${TESTS}: Testing $type /${prefix}" |
| 59 | get_token $prefix |
| 60 | url=$INGRESS_HOST:$INGRESS_PORT"/"$prefix |
ktimoney | 90fcec9 | 2022-04-29 15:46:50 +0100 | [diff] [blame] | 61 | #echo $url |
| 62 | result=$(curl -s -X ${type} -H "Content-type: application/json" -H "Authorization: Bearer $ACCESS_TOKEN" $url) |
ktimoney | 6be0529 | 2022-03-02 12:53:14 +0000 | [diff] [blame] | 63 | echo $result |
| 64 | if [ "$result" != "$msg" ]; then |
| 65 | echo "FAIL" |
| 66 | FAILED=$((FAILED+1)) |
| 67 | else |
| 68 | echo "PASS" |
| 69 | PASSED=$((PASSED+1)) |
| 70 | fi |
| 71 | echo "" |
| 72 | } |
| 73 | |
| 74 | |
ktimoney | 90fcec9 | 2022-04-29 15:46:50 +0100 | [diff] [blame] | 75 | run_test "rapp-provider" "GET" "Hello World!" "" |
ktimoney | 6be0529 | 2022-03-02 12:53:14 +0000 | [diff] [blame] | 76 | |
| 77 | echo |
| 78 | echo "-----------------------------------------------------------------------" |
| 79 | echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED" |
| 80 | echo "Date: $TEST_TS" |
| 81 | echo "-----------------------------------------------------------------------" |