Skip to content
Permalink
Newer
Older
100644 201 lines (178 sloc) 6.21 KB
1
#!/bin/bash
2
Sep 28, 2018
3
#
4
# Contains common functions usable for midPoint system tests
5
#
6
7
# do not use from outside (ugly signature)
8
function generic_wait_for_log () {
Sep 28, 2018
9
CONTAINER_NAME=$1
10
MESSAGE="$2"
11
WAITING_FOR="$3"
12
FAILURE="$4"
13
ADDITIONAL_CONTAINER_NAME=$5
14
ATTEMPT=0
15
MAX_ATTEMPTS=20
16
DELAY=10
17
18
until [[ $ATTEMPT = $MAX_ATTEMPTS ]]; do
19
ATTEMPT=$((ATTEMPT+1))
20
echo "Waiting $DELAY seconds for $WAITING_FOR (attempt $ATTEMPT) ..."
21
sleep $DELAY
22
docker ps
23
( docker logs $CONTAINER_NAME 2>&1 | grep "$MESSAGE" ) && return 0
24
done
25
26
echo "$FAILURE" in $(( $MAX_ATTEMPTS * $DELAY )) seconds in $CONTAINER_NAME
27
echo "========== Container log =========="
28
docker logs $CONTAINER_NAME 2>&1
29
echo "========== End of the container log =========="
30
if [ -n "ADDITIONAL_CONTAINER_NAME" ]; then
31
echo "========== Container log ($ADDITIONAL_CONTAINER_NAME) =========="
32
docker logs $ADDITIONAL_CONTAINER_NAME 2>&1
33
echo "========== End of the container log ($DATABASE_CONTAINER_NAME) =========="
34
fi
35
return 1
36
}
Sep 28, 2018
37
39
function wait_for_log_message () {
40
generic_wait_for_log $1 "$2" "log message" "log message has not appeared"
41
}
42
43
# Waits until midPoint starts
44
function wait_for_midpoint_start () {
45
generic_wait_for_log $1 "INFO (com.evolveum.midpoint.web.boot.MidPointSpringApplication): Started MidPointSpringApplication in" "midPoint to start" "midPoint did not start" $2
46
}
47
48
# Waits until Shibboleth IDP starts ... TODO refactor using generic waiting function
49
function wait_for_shibboleth_idp_start () {
50
CONTAINER_NAME=$1
51
ATTEMPT=0
52
MAX_ATTEMPTS=20
53
DELAY=10
54
55
until [[ $ATTEMPT = $MAX_ATTEMPTS ]]; do
56
ATTEMPT=$((ATTEMPT+1))
57
echo "Waiting $DELAY seconds for Shibboleth IDP to start (attempt $ATTEMPT) ..."
58
sleep $DELAY
59
docker ps
60
( docker logs $CONTAINER_NAME 2>&1 | grep "INFO:oejs.Server:main: Started" ) && return 0
61
done
62
63
echo Shibboleth IDP did not start in $(( $MAX_ATTEMPTS * $DELAY )) seconds in $CONTAINER_NAME
64
echo "========== Container log =========="
65
docker logs $CONTAINER_NAME 2>&1
66
echo "========== End of the container log =========="
67
return 1
68
}
69
70
Sep 28, 2018
71
# Checks the health of midPoint server
72
function check_health () {
73
echo Checking health...
74
(set -o pipefail ; curl -k -f https://localhost:8443/midpoint/actuator/health | tr -d '[:space:]' | grep -q "\"status\":\"UP\"")
75
status=$?
76
if [ $status -ne 0 ]; then
77
echo Error: $status
78
docker ps
79
return 1
80
else
81
echo OK
82
return 0
83
fi
84
}
85
86
# Checks the health of Shibboleth IDP server
87
function check_health_shibboleth_idp () {
88
echo Checking health of shibboleth idp...
89
status="$(curl -k --write-out %{http_code} --silent --output /dev/null https://localhost:4443/idp/)"
90
if [ $status -ne 200 ]; then
91
echo Error: Http code of response is $status
92
docker ps
93
return 1
94
else
95
echo OK
96
return 0
97
fi
98
}
99
100
Sep 28, 2018
101
# Retrieves XML object and checks if the name matches
102
function get_and_check_object () {
103
TYPE=$1
104
OID=$2
105
NAME=$3
106
TMPFILE=$(mktemp /tmp/get.XXXXXX)
107
echo tmp file is $TMPFILE
108
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X GET "https://localhost:8443/midpoint/ws/rest/$TYPE/$OID" >$TMPFILE || (rm $TMPFILE ; return 1)
109
if (grep -q "<name>$NAME</name>" <$TMPFILE); then
110
echo "Object $TYPE/$OID '$NAME' is OK"
111
rm $TMPFILE
112
return 0
113
else
114
echo "Object $TYPE/$OID '$NAME' was not found or not retrieved correctly:"
115
cat $TMPFILE
116
rm $TMPFILE
117
return 1
118
fi
119
}
120
121
# Adds object from a given file
122
# TODO Returns the OID in OID variable
123
# it can be found in the following HTTP reader returned: Location: "https://localhost:8443/midpoint/ws/rest/users/85e62669-d36b-41ce-b4f1-1ffdd9f66262"
124
function add_object () {
125
local TYPE=$1
126
local FILE=$2
Sep 28, 2018
127
echo "Adding to $TYPE from $FILE..."
128
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE" -d @$FILE || return 1
129
#TODO check the returned XML
130
return 0
131
}
132
133
# Tries to find an object with a given name
134
# Results of the search are in the $SEARCH_RESULT_FILE
135
# TODO check if the result is valid (i.e. not an error) - return 1 if invalid, otherwise return 0 ("no objects" is considered OK here)
136
function search_objects_by_name () {
137
TYPE=$1
138
NAME="$2"
Sep 28, 2018
139
TMPFILE=$(mktemp /tmp/search.XXXXXX)
140
141
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE/search" -d @- << EOF >$TMPFILE || (rm $TMPFILE ; return 1)
142
<q:query xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
143
<q:filter>
144
<q:equal>
145
<q:path>name</q:path>
146
<q:value>$NAME</q:value>
147
</q:equal>
148
</q:filter>
149
</q:query>
150
EOF
151
SEARCH_RESULT_FILE=$TMPFILE
152
# TODO check validity of the file
153
return 0
154
}
155
156
# Searches for object with a given name and verifies it was found
157
function search_and_check_object () {
158
local TYPE=$1
159
local NAME="$2"
160
search_objects_by_name $TYPE "$NAME" || return 1
Sep 28, 2018
161
if (grep -q "<name>$NAME</name>" <$SEARCH_RESULT_FILE); then
162
echo "Object $TYPE/'$NAME' is OK"
163
rm $SEARCH_RESULT_FILE
164
return 0
165
else
166
echo "Object $TYPE/'$NAME' was not found or not retrieved correctly:"
167
cat $SEARCH_RESULT_FILE
168
rm $SEARCH_RESULT_FILE
169
return 1
170
fi
171
}
172
173
# Tests a resource
174
function test_resource () {
175
local OID=$1
176
local TMPFILE=$(mktemp /tmp/test.resource.XXXXXX)
177
178
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/resources/$OID/test" >$TMPFILE || (rm $TMPFILE ; return 1)
179
if [[ $(xmllint --xpath "/*/*[local-name()='status']/text()" $TMPFILE) == "success" ]]; then
180
echo "Resource $OID test succeeded"
181
rm $TMPFILE
182
return 0
183
else
184
echo "Resource $OID test failed"
185
cat $TMPFILE
186
rm $TMPFILE
187
return 1
188
fi
189
}
191
function assert_task_success () {
192
local OID=$1
193
# TODO
194
return 0
195
}
196
197
function wait_for_task_completion () {
198
local OID=$1
199
sleep 60 # TODO
200
return 0
You can’t perform that action at this time.