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