Skip to content
Permalink
Newer
Older
100644 558 lines (485 sloc) 21.3 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
422
function search_ldap_object_by_filter () {
423
local BASE_CONTEXT_FOR_SEARCH=$1
424
local FILTER="$2"
425
local LDAP_CONTAINER=$3
426
TMPFILE=$(mktemp /tmp/ldapsearch.XXXXXX)
427
428
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)
429
LDAPSEARCH_RESULT_FILE=$TMPFILE
430
return 0
433
function get_ldap_user () {
434
local USER_UID="$1"
435
local LDAP_CONTAINER=$2
436
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$USER_UID" $LDAP_CONTAINER || return 1
437
if ! grep -F "uid: $USER_UID" $LDAPSEARCH_RESULT_FILE; then
438
echo "Couldn't find user '$USER_UID'"
439
rm $LDAPSEARCH_RESULT_FILE
440
return 1
441
else
442
return 0
443
fi
444
}
445
446
function assert_ldap_user_has_value () {
447
local USER_UID="$1"
448
local TYPE=$2 # Entitlement or Affiliation
449
local VALUE="$3"
450
local LDAP_CONTAINER=$4
451
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
452
if ! grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
453
echo "'$USER_UID' has no $TYPE of '$VALUE'"
454
cat $LDAPSEARCH_RESULT_FILE
455
rm $LDAPSEARCH_RESULT_FILE
456
return 1
457
else
458
rm $LDAPSEARCH_RESULT_FILE
459
return 0
460
fi
461
}
462
463
function assert_ldap_user_has_no_value () {
464
local USER_UID="$1"
465
local TYPE=$2 # Entitlement or Affiliation
466
local VALUE="$3"
467
local LDAP_CONTAINER=$4
468
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
469
if grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
470
echo "'$USER_UID' has an $TYPE of '$VALUE' although it should not have one"
471
cat $LDAPSEARCH_RESULT_FILE
472
rm $LDAPSEARCH_RESULT_FILE
473
return 1
474
else
475
rm $LDAPSEARCH_RESULT_FILE
476
return 0
477
fi
478
}
479
480
function check_ldap_account_by_user_name () {
Oct 3, 2018
481
local NAME="$1"
482
local LDAP_CONTAINER=$2
483
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$NAME" $LDAP_CONTAINER
484
search_objects_by_name users $NAME
486
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)
487
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)
488
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)
489
490
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)
491
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)
492
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)
493
494
rm $SEARCH_RESULT_FILE
495
rm $LDAPSEARCH_RESULT_FILE
496
497
if [[ $MP_FULL_NAME = $LDAP_CN ]] && [[ $MP_GIVEN_NAME = $LDAP_GIVEN_NAME ]] && [[ $MP_FAMILY_NAME = $LDAP_SN ]]; then
498
return 0
499
fi
501
echo "User in Midpoint and LDAP Account with uid $NAME are not same"
502
return 1
503
}
504
505
function check_ldap_courses_by_name () {
506
local NAME="$1"
507
local LDAP_CONTAINER=$2
508
search_objects_by_name orgs $NAME
509
510
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)
511
512
search_ldap_object_by_filter "ou=courses,ou=groups,dc=internet2,dc=edu" "cn=$MP_ORG_IDENTIFIER" $LDAP_CONTAINER
513
514
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)
515
516
rm $SEARCH_RESULT_FILE
517
rm $LDAPSEARCH_RESULT_FILE
518
if [[ $MP_ORG_IDENTIFIER = $LDAP_CN ]]; then
519
return 0
520
fi
521
522
echo "Orgs $NAME in Midpoint and LDAP Group(Course) with cn $MP_ORG_IDENTIFIER are not same"
523
return 1
524
}
525
526
527
function check_of_ldap_membership () {
Oct 3, 2018
528
local NAME_OF_USER="$1"
529
local BASE_CONTEXT_FOR_GROUP="$2"
530
local NAME_OF_GROUP="$3"
531
local LDAP_CONTAINER=$4
532
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$NAME_OF_USER" $LDAP_CONTAINER
533
534
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)
536
search_ldap_object_by_filter "$BASE_CONTEXT_FOR_GROUP" "cn=$NAME_OF_GROUP" $LDAP_CONTAINER
537
538
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)
539
540
rm $LDAPSEARCH_RESULT_FILE
541
542
if [[ $LDAP_MEMBERS_DNS =~ $LDAP_ACCOUNT_DN ]]; then
543
return 0
544
fi
545
546
echo "LDAP Account with uid $NAME_OF_USER is not member of LDAP Group $NAME_OF_GROUP in base context $BASE_CONTEXT_FOR_GROUP"
547
return 1
548
}
549
550
function get_messages () {
551
local QUEUE="$1"
552
MESSAGES=$(curl -s -i -u guest:guest "http://localhost:15672/api/queues/%2f/$QUEUE" | sed 's/,/\n/g' | grep '"messages"' | sed 's/"messages"://g')
553
if [ -z "$MESSAGES" ]; then
554
echo "Unable to get number of messages in $QUEUE"
555
return 1
556
fi
557
return 0
558
}
You can’t perform that action at this time.