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