Skip to content
Permalink
Newer
Older
100644 588 lines (512 sloc) 22.4 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
docker ps
21
( docker logs $CONTAINER_NAME 2>&1 | grep -F "$MESSAGE" ) && return 0
22
echo "Waiting $DELAY seconds for $WAITING_FOR (attempt $ATTEMPT) ..."
23
sleep $DELAY
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
Oct 3, 2018
48
# Waits until Shibboleth IDP starts
49
function wait_for_shibboleth_idp_start_old () {
50
generic_wait_for_log $1 "INFO:oejs.Server:main: Started" "shibboleth idp to start" "shibboleth idp did not start" $2
53
# Waits until Shibboleth IDP starts
54
function wait_for_shibboleth_idp_start () {
55
generic_wait_for_log $1 "[main] INFO org.apache.catalina.startup.Catalina- Server startup in" "shibboleth idp to start" "shibboleth idp did not start" $2
56
}
57
Oct 3, 2018
58
# Waits until Grouper UI starts
59
function wait_for_grouper_ui_start () {
60
generic_wait_for_log $1 "INFO org.apache.catalina.startup.Catalina- Server startup in" "grouper ui to start" "grouper ui did not start" $2
61
}
62
Sep 28, 2018
63
# Checks the health of midPoint server
64
function check_health () {
65
echo Checking health...
66
(set -o pipefail ; curl -k -f https://localhost:8443/midpoint/actuator/health | tr -d '[:space:]' | grep -q "\"status\":\"UP\"")
67
status=$?
68
if [ $status -ne 0 ]; then
69
echo Error: $status
70
docker ps
71
return 1
72
else
73
echo OK
74
return 0
75
fi
76
}
77
78
# Checks the health of Shibboleth IDP server
79
function check_health_shibboleth_idp_old () {
80
echo Checking health of shibboleth idp...
81
status="$(curl -k --write-out %{http_code} --silent --output /dev/null https://localhost:4443/idp/)"
82
if [ $status -ne 200 ]; then
83
echo Error: Http code of response is $status
84
docker ps
85
return 1
86
else
87
echo OK
88
return 0
89
fi
90
}
91
92
function check_health_shibboleth_idp () {
93
echo Checking health of shibboleth idp...
94
status="$(curl -k --write-out %{http_code} --silent --output /dev/null https://localhost/idp/)"
95
if [ $status -ne 200 ]; then
96
echo Error: Http code of response is $status
97
docker ps
98
return 1
99
else
100
echo OK
101
return 0
102
fi
103
}
104
105
# Result is in OUTFILE
106
function get_object () {
107
local TYPE=$1
108
local OID=$2
109
OUTFILE=$(mktemp /tmp/get.XXXXXX)
110
echo out file is $OUTFILE
111
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X GET "https://localhost:8443/midpoint/ws/rest/$TYPE/$OID" >$OUTFILE || (rm $OUTFILE ; return 1)
112
return 0
113
}
114
Sep 28, 2018
115
# Retrieves XML object and checks if the name matches
116
# Object is deleted before return
Sep 28, 2018
117
function get_and_check_object () {
118
local TYPE=$1
119
local OID=$2
120
local NAME=$3
121
local TMPFILE=$(mktemp /tmp/get.XXXXXX)
Sep 28, 2018
122
echo tmp file is $TMPFILE
123
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)
124
if (grep -q "<name>$NAME</name>" <$TMPFILE); then
125
echo "Object $TYPE/$OID '$NAME' is OK"
126
rm $TMPFILE
127
return 0
128
else
129
echo "Object $TYPE/$OID '$NAME' was not found or not retrieved correctly:"
130
cat $TMPFILE
131
rm $TMPFILE
132
return 1
133
fi
134
}
135
136
# Adds object from a given file
137
function add_object () {
138
local TYPE=$1
139
local FILE=$2
140
TMPFILE=$(mktemp /tmp/addobject.XXXXXX)
Sep 28, 2018
141
echo "Adding to $TYPE from $FILE..."
143
curl -k -sD - --silent --write-out "%{http_code}" --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE" -d @$FILE >$TMPFILE
144
local HTTP_CODE=$(sed '$!d' $TMPFILE)
145
sed -i '$ d' $TMPFILE
147
if [ "$HTTP_CODE" -eq 201 ] || [ "$HTTP_CODE" -eq 202 ]; then
149
OID=$(grep -oP "Location: \K.*" $TMPFILE | awk -F "$TYPE/" '{print $2}') || (echo "Couldn't extract oid from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
151
echo "OID of created object: $OID"
152
rm $TMPFILE
153
return 0
154
else
155
echo "Error code: $HTTP_CODE"
156
if [ "$HTTP_CODE" -ge 500 ]; then
157
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
158
else
159
echo $(sed '1,/^\s*$/d' $TMPFILE) >$TMPFILE
160
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
161
echo "Error message: $ERROR_MESSAGE"
162
fi
163
rm $TMPFILE
164
return 1
165
fi
Sep 28, 2018
166
}
167
168
# parameter $2 (CONTAINER) is just for diagnostics: it is the container whose logs we want to dump on error (might be omitted)
169
function execute_bulk_action () {
170
local FILE=$1
171
local CONTAINER=$2
172
echo "Executing bulk action from $FILE..."
173
TMPFILE=$(mktemp /tmp/execbulkaction.XXXXXX)
175
(curl -k --silent --write-out "%{http_code}" --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/rpc/executeScript" -d @$FILE >$TMPFILE) || (echo "Midpoint logs: " ; ([[ -n "$CONTAINER" ]] && docker logs $CONTAINER ) ; return 1)
176
local HTTP_CODE=$(sed '$!d' $TMPFILE)
177
sed -i '$ d' $TMPFILE
178
179
if [ "$HTTP_CODE" -eq 200 ]; then
180
181
local STATUS=$(xmllint --xpath "/*/*/*[local-name()='status']/text()" $TMPFILE) || (echo "Couldn't extract status from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
182
if [ $STATUS = "success" ]; then
183
local CONSOLE_OUTPUT=$(xmllint --xpath "/*/*/*[local-name()='consoleOutput']/text()" $TMPFILE) || (echo "Couldn't extract console output from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
184
echo "Console output: $CONSOLE_OUTPUT"
185
rm $TMPFILE
186
return 0
187
else
188
echo "Bulk action status is not OK: $STATUS"
189
local CONSOLE_OUTPUT=$(xmllint --xpath "/*/*/*[local-name()='consoleOutput']/text()" $TMPFILE) || (echo "Couldn't extract console output from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
190
echo "Console output: $CONSOLE_OUTPUT"
191
rm $TMPFILE
192
return 1
193
fi
194
195
else
196
echo "Error code: $HTTP_CODE"
197
if [[ $HTTP_CODE -ge 500 ]]; then
198
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
200
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
201
echo "Error message: $ERROR_MESSAGE"
203
rm $TMPFILE
204
return 1
205
fi
206
}
207
208
# parameter $2 (CONTAINER) is just for diagnostics: it is the container whose logs we want to dump on error (might be omitted)
209
function run_task_now () {
210
local OID=$1
211
local CONTAINER=$2
212
echo "Running task $1 now..."
213
TMPFILE=$(mktemp /tmp/runtasknow.XXXXXX)
214
215
(curl -k --silent --write-out "%{http_code}" --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/tasks/$OID/run" >$TMPFILE) || (echo "Midpoint logs: " ; ([[ -n "$CONTAINER" ]] && docker logs $CONTAINER ) ; return 1)
216
local HTTP_CODE=$(sed '$!d' $TMPFILE)
217
sed -i '$ d' $TMPFILE
218
219
if [[ $HTTP_CODE -ge 200 && $HTTP_CODE -lt 300 ]]; then
220
rm $TMPFILE
221
return 0
222
else
223
echo "Error code: $HTTP_CODE"
224
cat $TMPFILE
225
rm $TMPFILE
226
return 1
227
fi
228
}
229
230
# parameter $2 (CONTAINER) is just for diagnostics: it is the container whose logs we want to dump on error (might be omitted)
231
function suspend_task () {
232
local OID=$1
233
local CONTAINER=$2
234
echo "Suspending task $OID..."
235
TMPFILE=$(mktemp /tmp/suspendtask.XXXXXX)
236
237
(curl -k --silent --write-out "%{http_code}" --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/tasks/$OID/suspend" >$TMPFILE) || (echo "Midpoint logs: " ; ([[ -n "$CONTAINER" ]] && docker logs $CONTAINER ) ; return 1)
238
local HTTP_CODE=$(sed '$!d' $TMPFILE)
239
sed -i '$ d' $TMPFILE
240
241
if [[ $HTTP_CODE -ge 200 && $HTTP_CODE -lt 300 ]]; then
242
rm $TMPFILE
243
return 0
244
else
245
echo "Error code: $HTTP_CODE"
246
cat $TMPFILE
247
rm $TMPFILE
248
return 1
249
fi
250
}
251
252
function delete_object_by_name () {
253
local TYPE=$1
254
local NAME=$2
255
search_objects_by_name users $NAME
256
local OID=$(xmllint --xpath "/*/*[local-name()='object']/@oid" $SEARCH_RESULT_FILE | awk -F"\"" '{print $2}' ) || (echo "Couldn't extract oid from file:" ; cat $SEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE; return 1)
257
delete_object $TYPE $OID
258
}
259
260
function delete_object () {
261
local TYPE=$1
262
local OID=$2
263
echo "Deleting object with type $TYPE and oid $OID..."
264
TMPFILE=$(mktemp /tmp/delete.XXXXXX)
265
266
curl -k --silent --write-out "%{http_code}" --user administrator:5ecr3t -H "Content-Type: application/xml" -X DELETE "https://localhost:8443/midpoint/ws/rest/$TYPE/$OID" >$TMPFILE
267
local HTTP_CODE=$(sed '$!d' $TMPFILE)
268
sed -i '$ d' $TMPFILE
269
270
if [ "$HTTP_CODE" -eq 204 ]; then
271
echo "Object with type $TYPE and oid $OID was deleted"
272
rm $TMPFILE
273
return 0
274
else
275
echo "Error code: $HTTP_CODE"
276
if [[ $HTTP_CODE -ge 500 ]]; then
277
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
278
else
279
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
280
echo "Error message: $ERROR_MESSAGE"
281
fi
282
#rm $TMPFILE
283
return 1
284
fi
285
}
286
Sep 28, 2018
287
# Tries to find an object with a given name
288
# Results of the search are in the $SEARCH_RESULT_FILE
289
# 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)
290
function search_objects_by_name () {
Oct 3, 2018
291
local TYPE=$1
292
local NAME="$2"
Sep 28, 2018
293
TMPFILE=$(mktemp /tmp/search.XXXXXX)
294
295
curl -k --write-out %{http_code} --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)
Sep 28, 2018
296
<q:query xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
297
<q:filter>
298
<q:equal>
299
<q:path>name</q:path>
300
<q:value>$NAME</q:value>
301
</q:equal>
302
</q:filter>
303
</q:query>
304
EOF
Oct 3, 2018
305
local HTTP_CODE=$(sed '$!d' <<<"$(cat $TMPFILE)")
306
sed -i '$ d' $TMPFILE
307
# cat $TMPFILE
Oct 3, 2018
309
if [ "$HTTP_CODE" -eq 200 ]; then
310
SEARCH_RESULT_FILE=$TMPFILE
311
return 0
312
else
Oct 3, 2018
313
echo "Error code: $HTTP_CODE"
314
if [[ $HTTP_CODE -ge 500 ]]; then
Oct 3, 2018
315
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
316
else
317
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
Oct 3, 2018
318
echo "Error message: $ERROR_MESSAGE"
319
fi
320
rm $SEARCH_RESULT_FILE
321
return 1
322
fi
Sep 28, 2018
323
}
324
325
# Searches for object with a given name and verifies it was found
326
function search_and_check_object () {
327
local TYPE=$1
328
local NAME="$2"
329
search_objects_by_name $TYPE "$NAME" || return 1
Sep 28, 2018
330
if (grep -q "<name>$NAME</name>" <$SEARCH_RESULT_FILE); then
331
echo "Object $TYPE/'$NAME' is OK"
332
rm $SEARCH_RESULT_FILE
333
return 0
334
else
335
echo "Object $TYPE/'$NAME' was not found or not retrieved correctly:"
336
cat $SEARCH_RESULT_FILE
337
rm $SEARCH_RESULT_FILE
338
return 1
339
fi
340
}
341
342
# Tests a resource
343
function test_resource () {
344
local OID=$1
345
local TMPFILE=$(mktemp /tmp/test.resource.XXXXXX)
346
347
curl -k --silent --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/resources/$OID/test" >$TMPFILE || (rm $TMPFILE ; return 1)
348
if [[ $(xmllint --xpath "/*/*[local-name()='status']/text()" $TMPFILE) == "success" ]]; then
349
echo "Resource $OID test succeeded"
350
rm $TMPFILE
351
return 0
352
else
353
echo "Resource $OID test failed"
354
cat $TMPFILE
355
rm $TMPFILE
356
return 1
357
fi
358
}
360
function recompute () {
361
local TYPE=$1
362
local OID=$2
363
local TMPFILE=$(mktemp /tmp/recompute.XXXXXX)
364
365
curl -k --silent --write-out "%{http_code}" --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/$TYPE/$OID" -d @- << EOF >$TMPFILE || (rm $TMPFILE ; return 1)
366
<objectModification xmlns='http://midpoint.evolveum.com/xml/ns/public/common/api-types-3'></objectModification>
367
EOF
368
local HTTP_CODE=$(sed '$!d' $TMPFILE)
369
sed -i '$ d' $TMPFILE
370
if [[ $HTTP_CODE -ge 200 && $HTTP_CODE -lt 300 ]]; then
371
echo "Object $TYPE/$OID recomputation succeeded"
372
rm $TMPFILE
373
return 0
374
else
375
echo "Object $TYPE/$OID recomputation failed: $HTTP_CODE"
376
cat $TMPFILE
377
rm $TMPFILE
378
return 1
379
fi
380
}
381
382
function assert_task_success () {
383
local OID=$1
384
get_object tasks $OID
385
TASK_STATUS=$(xmllint --xpath "/*/*[local-name()='resultStatus']/text()" $OUTFILE) || (echo "Couldn't extract task status from task $OID" ; cat $OUTFILE ; rm $OUTFILE ; return 1)
386
if [[ $TASK_STATUS = "success" ]]; then
387
echo "Task $OID status is OK"
388
rm $OUTFILE
389
return 0
390
else
391
echo "Task $OID status is not OK: $TASK_STATUS"
392
cat $OUTFILE
393
rm $OUTFILE
394
return 1
395
fi
396
}
397
398
function wait_for_task_completion () {
399
local OID=$1
400
local ATTEMPT=0
401
local MAX_ATTEMPTS=$2
402
local DELAY=$3
403
404
until [[ $ATTEMPT = $MAX_ATTEMPTS ]]; do
405
ATTEMPT=$((ATTEMPT+1))
406
echo "Waiting $DELAY seconds for task with oid $OID to finish (attempt $ATTEMPT) ..."
407
sleep $DELAY
408
get_object tasks $OID
409
TASK_EXECUTION_STATUS=$(xmllint --xpath "/*/*[local-name()='executionStatus']/text()" $OUTFILE) || (echo "Couldn't extract task status from task $OID" ; cat $OUTFILE ; rm $OUTFILE ; return 1)
410
if [[ $TASK_EXECUTION_STATUS = "suspended" ]] || [[ $TASK_EXECUTION_STATUS = "closed" ]]; then
411
echo "Task $OID is finished"
412
rm $OUTFILE
413
return 0
414
fi
415
done
416
rm $OUTFILE
417
echo Task with $OID did not finish in $(( $MAX_ATTEMPTS * $DELAY )) seconds
418
return 1
419
}
420
421
function get_task_execution_status () {
422
local NAME=$1
423
424
search_objects_by_name tasks "$NAME"
425
TASK_EXECUTION_STATUS=$(xmllint --xpath "/*/*/*[local-name()='executionStatus']/text()" $SEARCH_RESULT_FILE) || (echo "Couldn't extract task status from task $NAME" ; cat $SEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; return 1)
426
echo "Task execution status: $TASK_EXECUTION_STATUS"
427
return 0
428
}
429
430
function search_ldap_object_by_filter () {
431
local BASE_CONTEXT_FOR_SEARCH=$1
432
local FILTER="$2"
433
local LDAP_CONTAINER=$3
434
TMPFILE=$(mktemp /tmp/ldapsearch.XXXXXX)
435
436
docker exec $LDAP_CONTAINER ldapsearch -h localhost -p 389 -D "cn=Directory Manager" -w password -b "$BASE_CONTEXT_FOR_SEARCH" "($FILTER)" >$TMPFILE || (echo "Couldn't search $FILTER" ;rm $TMPFILE ; return 1)
437
LDAPSEARCH_RESULT_FILE=$TMPFILE
438
return 0
441
function get_ldap_user () {
442
local USER_UID="$1"
443
local LDAP_CONTAINER=$2
444
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$USER_UID" $LDAP_CONTAINER || return 1
445
if ! grep -F "uid: $USER_UID" $LDAPSEARCH_RESULT_FILE; then
446
echo "Couldn't find user '$USER_UID'"
447
rm $LDAPSEARCH_RESULT_FILE
448
return 1
449
else
450
return 0
451
fi
452
}
453
454
function assert_ldap_user_has_value () {
455
local USER_UID="$1"
456
local TYPE=$2 # Entitlement or Affiliation
457
local VALUE="$3"
458
local LDAP_CONTAINER=$4
459
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
460
if ! grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
461
echo "'$USER_UID' has no $TYPE of '$VALUE'"
462
cat $LDAPSEARCH_RESULT_FILE
463
rm $LDAPSEARCH_RESULT_FILE
464
return 1
465
else
466
rm $LDAPSEARCH_RESULT_FILE
467
return 0
468
fi
469
}
470
471
function assert_ldap_user_has_no_value () {
472
local USER_UID="$1"
473
local TYPE=$2 # Entitlement or Affiliation
474
local VALUE="$3"
475
local LDAP_CONTAINER=$4
476
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
477
if grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
478
echo "'$USER_UID' has an $TYPE of '$VALUE' although it should not have one"
479
cat $LDAPSEARCH_RESULT_FILE
480
rm $LDAPSEARCH_RESULT_FILE
481
return 1
482
else
483
rm $LDAPSEARCH_RESULT_FILE
484
return 0
485
fi
486
}
487
488
function check_ldap_account_by_user_name () {
Oct 3, 2018
489
local NAME="$1"
490
local LDAP_CONTAINER=$2
491
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$NAME" $LDAP_CONTAINER
492
search_objects_by_name users $NAME
494
local MP_FULL_NAME=$(xmllint --xpath "/*/*/*[local-name()='fullName']/text()" $SEARCH_RESULT_FILE) || (echo "Couldn't extract user fullName from file:" ; cat $SEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
495
local MP_GIVEN_NAME=$(xmllint --xpath "/*/*/*[local-name()='givenName']/text()" $SEARCH_RESULT_FILE) || (echo "Couldn't extract user givenName from file:" ; cat $SEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
496
local MP_FAMILY_NAME=$(xmllint --xpath "/*/*/*[local-name()='familyName']/text()" $SEARCH_RESULT_FILE) || (echo "Couldn't extract user familyName from file:" ; cat $SEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
497
498
local LDAP_CN=$(grep -oP "cn: \K.*" $LDAPSEARCH_RESULT_FILE) || (echo "Couldn't extract user cn from file:" ; cat $LDAPSEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
499
local LDAP_GIVEN_NAME=$(grep -oP "givenName: \K.*" $LDAPSEARCH_RESULT_FILE) || (echo "Couldn't extract user givenName from file:" ; cat $LDAPSEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
500
local LDAP_SN=$(grep -oP "sn: \K.*" $LDAPSEARCH_RESULT_FILE) || (echo "Couldn't extract user sn from file:" ; cat $LDAPSEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
501
502
rm $SEARCH_RESULT_FILE
503
rm $LDAPSEARCH_RESULT_FILE
504
505
if [[ $MP_FULL_NAME = $LDAP_CN ]] && [[ $MP_GIVEN_NAME = $LDAP_GIVEN_NAME ]] && [[ $MP_FAMILY_NAME = $LDAP_SN ]]; then
506
return 0
507
fi
509
echo "User in Midpoint and LDAP Account with uid $NAME are not same"
510
return 1
511
}
512
513
function check_ldap_courses_by_name () {
514
local NAME="$1"
515
local LDAP_CONTAINER=$2
516
search_objects_by_name orgs $NAME
517
518
local MP_ORG_IDENTIFIER=$(xmllint --xpath "/*/*/*[local-name()='identifier']/text()" $SEARCH_RESULT_FILE) || (echo "Couldn't extract user identifier from file:" ; cat $SEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; return 1)
519
520
search_ldap_object_by_filter "ou=courses,ou=groups,dc=internet2,dc=edu" "cn=$MP_ORG_IDENTIFIER" $LDAP_CONTAINER
521
522
local LDAP_CN=$(grep -oP "cn: \K.*" $LDAPSEARCH_RESULT_FILE) || (echo "Couldn't extract user cn from file:" ; cat $LDAPSEARCH_RESULT_FILE ; rm $SEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
523
524
rm $SEARCH_RESULT_FILE
525
rm $LDAPSEARCH_RESULT_FILE
526
if [[ $MP_ORG_IDENTIFIER = $LDAP_CN ]]; then
527
return 0
528
fi
529
530
echo "Orgs $NAME in Midpoint and LDAP Group(Course) with cn $MP_ORG_IDENTIFIER are not same"
531
return 1
532
}
533
534
535
function check_of_ldap_membership () {
Oct 3, 2018
536
local NAME_OF_USER="$1"
537
local BASE_CONTEXT_FOR_GROUP="$2"
538
local NAME_OF_GROUP="$3"
539
local LDAP_CONTAINER=$4
540
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$NAME_OF_USER" $LDAP_CONTAINER
541
542
local LDAP_ACCOUNT_DN=$(grep -oP "dn: \K.*" $LDAPSEARCH_RESULT_FILE) || (echo "Couldn't extract user dn from file:" ; cat $LDAPSEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
544
search_ldap_object_by_filter "$BASE_CONTEXT_FOR_GROUP" "cn=$NAME_OF_GROUP" $LDAP_CONTAINER
545
546
local LDAP_MEMBERS_DNS=$(grep -oP "uniqueMember: \K.*" $LDAPSEARCH_RESULT_FILE) || (echo "Couldn't extract user uniqueMember from file:" ; cat $LDAPSEARCH_RESULT_FILE ; rm $LDAPSEARCH_RESULT_FILE ; return 1)
547
548
rm $LDAPSEARCH_RESULT_FILE
549
550
if [[ $LDAP_MEMBERS_DNS =~ $LDAP_ACCOUNT_DN ]]; then
551
return 0
552
fi
553
554
echo "LDAP Account with uid $NAME_OF_USER is not member of LDAP Group $NAME_OF_GROUP in base context $BASE_CONTEXT_FOR_GROUP"
555
return 1
556
}
557
558
function get_messages () {
559
local QUEUE="$1"
560
MESSAGES=$(curl -s -i -u guest:guest "http://localhost:15672/api/queues/%2f/$QUEUE" | sed 's/,/\n/g' | grep '"messages"' | sed 's/"messages"://g')
561
if [ -z "$MESSAGES" ]; then
562
echo "Unable to get number of messages in $QUEUE"
563
return 1
564
fi
565
return 0
566
}
567
568
function upload_from_file () {
569
local FILENAME=$1
570
local OPTIONS_TO_ADD=$2
571
local REGEX="midpoint-objects.*/(.*)/(.*)"
572
if [[ $FILENAME =~ $REGEX ]]
573
then
574
TYPE="${BASH_REMATCH[1]}"
575
OID=`cat $FILENAME | sed -n 's:.*oid=\"\([A-Za-z0-9\-]*\)\".*:\1:p' | sed -n '1 p'`
576
echo "Uploading $FILENAME ($TYPE, $OID)"
577
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X PUT "https://localhost:8443/midpoint/ws/rest/$TYPE/$OID?options=overwrite$OPTIONS_TO_ADD" --data-binary @$FILENAME
578
else
579
echo "Skipping $FILENAME"
580
fi
581
}
582
583
function execute_gsh () {
584
local CONTAINER=$1
585
local FILE=$2
586
docker cp $FILE $CONTAINER:/tmp/
587
docker exec $CONTAINER bash -c "/opt/grouper/grouper.apiBinary/bin/gsh /tmp/$FILE"
588
}
You can’t perform that action at this time.