blob: b0aa133a73e9afebde99704306921fe45769572f [file] [log] [blame]
ktimoney6be05292022-03-02 12:53:14 +00001#!/bin/bash
ktimoney3570d5a2022-05-24 13:54:55 +01002#
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#
ktimoney6be05292022-03-02 12:53:14 +000021INGRESS_HOST=$(minikube ip)
22INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')
23TESTS=0
24PASSED=0
25FAILED=0
26TEST_TS=$(date +%F-%T)
27TOKEN=""
ktimoney90fcec92022-04-29 15:46:50 +010028ACCESS_TOKEN=""
29REFRESH_TOKEN=""
30CERT="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=="
ktimoney6be05292022-03-02 12:53:14 +000031
32function 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 \
ktimoney90fcec92022-04-29 15:46:50 +010038 "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
ktimoney6be05292022-03-02 12:53:14 +000052}
53
54function 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
ktimoney90fcec92022-04-29 15:46:50 +010061 #echo $url
62 result=$(curl -s -X ${type} -H "Content-type: application/json" -H "Authorization: Bearer $ACCESS_TOKEN" $url)
ktimoney6be05292022-03-02 12:53:14 +000063 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
ktimoney90fcec92022-04-29 15:46:50 +010075run_test "rapp-provider" "GET" "Hello World!" ""
ktimoney6be05292022-03-02 12:53:14 +000076
77echo
78echo "-----------------------------------------------------------------------"
79echo "Number of Tests: $TESTS, Tests Passed: $PASSED, Tests Failed: $FAILED"
80echo "Date: $TEST_TS"
81echo "-----------------------------------------------------------------------"