Skip to content
Permalink
Newer
Older
100644 137 lines (124 sloc) 4.38 KB
1
#!/bin/bash
2
Sep 28, 2018
3
#
4
# Contains common functions usable for midPoint system tests
5
#
6
7
# Waits until midPoint starts
8
function wait_for_midpoint_start () {
Sep 28, 2018
9
CONTAINER_NAME=$1
10
ATTEMPT=0
11
MAX_ATTEMPTS=20
12
DELAY=10
13
14
until [[ $ATTEMPT = $MAX_ATTEMPTS ]]; do
15
ATTEMPT=$((ATTEMPT+1))
16
echo "Waiting $DELAY seconds for midPoint to start (attempt $ATTEMPT) ..."
17
sleep $DELAY
18
docker ps
Sep 28, 2018
19
( docker logs $CONTAINER_NAME 2>&1 | grep "INFO (com.evolveum.midpoint.web.boot.MidPointSpringApplication): Started MidPointSpringApplication in" ) && return 0
20
done
21
Sep 28, 2018
22
echo midPoint did not start in $(( $MAX_ATTEMPTS * $DELAY )) seconds in $CONTAINER_NAME
23
echo "========== Container log =========="
24
docker logs $CONTAINER_NAME 2>&1
25
echo "========== End of the container log =========="
26
return 1
27
}
Sep 28, 2018
28
29
# Checks the health of midPoint server
30
function check_health () {
31
echo Checking health...
32
(set -o pipefail ; curl -k -f https://localhost:8443/midpoint/actuator/health | tr -d '[:space:]' | grep -q "\"status\":\"UP\"")
33
status=$?
34
if [ $status -ne 0 ]; then
35
echo Error: $status
36
docker ps
37
return 1
38
else
39
echo OK
40
return 0
41
fi
42
}
43
44
# Retrieves XML object and checks if the name matches
45
function get_and_check_object () {
46
TYPE=$1
47
OID=$2
48
NAME=$3
49
TMPFILE=$(mktemp /tmp/get.XXXXXX)
50
echo tmp file is $TMPFILE
51
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)
52
if (grep -q "<name>$NAME</name>" <$TMPFILE); then
53
echo "Object $TYPE/$OID '$NAME' is OK"
54
rm $TMPFILE
55
return 0
56
else
57
echo "Object $TYPE/$OID '$NAME' was not found or not retrieved correctly:"
58
cat $TMPFILE
59
rm $TMPFILE
60
return 1
61
fi
62
}
63
64
# Adds object from a given file
65
# TODO Returns the OID in OID variable
66
# it can be found in the following HTTP reader returned: Location: "https://localhost:8443/midpoint/ws/rest/users/85e62669-d36b-41ce-b4f1-1ffdd9f66262"
67
function add_object () {
68
local TYPE=$1
69
local FILE=$2
Sep 28, 2018
70
echo "Adding to $TYPE from $FILE..."
71
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE" -d @$FILE || return 1
72
#TODO check the returned XML
73
return 0
74
}
75
76
# Tries to find an object with a given name
77
# Results of the search are in the $SEARCH_RESULT_FILE
78
# 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)
79
function search_objects_by_name () {
80
TYPE=$1
81
NAME=$2
82
TMPFILE=$(mktemp /tmp/search.XXXXXX)
83
84
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)
85
<q:query xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
86
<q:filter>
87
<q:equal>
88
<q:path>name</q:path>
89
<q:value>$NAME</q:value>
90
</q:equal>
91
</q:filter>
92
</q:query>
93
EOF
94
SEARCH_RESULT_FILE=$TMPFILE
95
# TODO check validity of the file
96
return 0
97
}
98
99
# Searches for object with a given name and verifies it was found
100
function search_and_check_object () {
101
local TYPE=$1
102
local NAME=$2
Sep 28, 2018
103
search_objects_by_name $TYPE $NAME || return 1
104
if (grep -q "<name>$NAME</name>" <$SEARCH_RESULT_FILE); then
105
echo "Object $TYPE/'$NAME' is OK"
106
rm $SEARCH_RESULT_FILE
107
return 0
108
else
109
echo "Object $TYPE/'$NAME' was not found or not retrieved correctly:"
110
cat $SEARCH_RESULT_FILE
111
rm $SEARCH_RESULT_FILE
112
return 1
113
fi
114
}
115
116
# Tests a resource
117
function test_resource () {
118
local OID=$1
119
local TMPFILE=$(mktemp /tmp/test.resource.XXXXXX)
120
local TMPFILE_ERR=$(mktemp /tmp/test.resource.err.XXXXXX)
121
122
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/resources/$OID/test" >$TMPFILE || (rm $TMPFILE $TMPFILE_ERR ; return 1)
123
if [[ $(xmllint --xpath "/*/*[local-name()='status']/text()" $TMPFILE) == "success" ]]; then
124
echo "Resource $OID test succeeded"
125
rm $TMPFILE
126
return 0
127
else
128
echo "Resource $OID test failed"
129
cat $TMPFILE
130
rm $TMPFILE
131
return 1
132
fi
133
}
134
135
function get_xpath () {
136
echo ok
137
}
You can’t perform that action at this time.