Skip to content
Permalink
Newer
Older
100644 505 lines (437 sloc) 19.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
function delete_object_by_name () {
231
local TYPE=$1
232
local NAME=$2
233
search_objects_by_name users $NAME
234
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)
235
delete_object $TYPE $OID
236
}
237
238
function delete_object () {
239
local TYPE=$1
240
local OID=$2
241
echo "Deleting object with type $TYPE and oid $OID..."
242
TMPFILE=$(mktemp /tmp/delete.XXXXXX)
243
244
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
245
local HTTP_CODE=$(sed '$!d' $TMPFILE)
246
sed -i '$ d' $TMPFILE
247
248
if [ "$HTTP_CODE" -eq 204 ]; then
249
echo "Object with type $TYPE and oid $OID was deleted"
250
rm $TMPFILE
251
return 0
252
else
253
echo "Error code: $HTTP_CODE"
254
if [[ $HTTP_CODE -ge 500 ]]; then
255
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
256
else
257
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
258
echo "Error message: $ERROR_MESSAGE"
259
fi
260
#rm $TMPFILE
261
return 1
262
fi
263
}
264
Sep 28, 2018
265
# Tries to find an object with a given name
266
# Results of the search are in the $SEARCH_RESULT_FILE
267
# 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)
268
function search_objects_by_name () {
Oct 3, 2018
269
local TYPE=$1
270
local NAME="$2"
Sep 28, 2018
271
TMPFILE=$(mktemp /tmp/search.XXXXXX)
272
273
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
274
<q:query xmlns:q="http://prism.evolveum.com/xml/ns/public/query-3">
275
<q:filter>
276
<q:equal>
277
<q:path>name</q:path>
278
<q:value>$NAME</q:value>
279
</q:equal>
280
</q:filter>
281
</q:query>
282
EOF
Oct 3, 2018
283
local HTTP_CODE=$(sed '$!d' <<<"$(cat $TMPFILE)")
284
sed -i '$ d' $TMPFILE
285
cat $TMPFILE
Oct 3, 2018
287
if [ "$HTTP_CODE" -eq 200 ]; then
288
SEARCH_RESULT_FILE=$TMPFILE
289
return 0
290
else
Oct 3, 2018
291
echo "Error code: $HTTP_CODE"
292
if [[ $HTTP_CODE -ge 500 ]]; then
Oct 3, 2018
293
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
294
else
295
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
296
echo "Error message: $ERROR_MESSAGE"
297
fi
298
rm $SEARCH_RESULT_FILE
299
return 1
300
fi
Sep 28, 2018
301
}
302
303
# Searches for object with a given name and verifies it was found
304
function search_and_check_object () {
305
local TYPE=$1
306
local NAME="$2"
307
search_objects_by_name $TYPE "$NAME" || return 1
Sep 28, 2018
308
if (grep -q "<name>$NAME</name>" <$SEARCH_RESULT_FILE); then
309
echo "Object $TYPE/'$NAME' is OK"
310
rm $SEARCH_RESULT_FILE
311
return 0
312
else
313
echo "Object $TYPE/'$NAME' was not found or not retrieved correctly:"
314
cat $SEARCH_RESULT_FILE
315
rm $SEARCH_RESULT_FILE
316
return 1
317
fi
318
}
319
320
# Tests a resource
321
function test_resource () {
322
local OID=$1
323
local TMPFILE=$(mktemp /tmp/test.resource.XXXXXX)
324
325
curl -k --user administrator:5ecr3t -H "Content-Type: application/xml" -X POST "https://localhost:8443/midpoint/ws/rest/resources/$OID/test" >$TMPFILE || (rm $TMPFILE ; return 1)
326
if [[ $(xmllint --xpath "/*/*[local-name()='status']/text()" $TMPFILE) == "success" ]]; then
327
echo "Resource $OID test succeeded"
328
rm $TMPFILE
329
return 0
330
else
331
echo "Resource $OID test failed"
332
cat $TMPFILE
333
rm $TMPFILE
334
return 1
335
fi
336
}
338
function assert_task_success () {
339
local OID=$1
340
get_object tasks $OID
341
TASK_STATUS=$(xmllint --xpath "/*/*[local-name()='resultStatus']/text()" $OUTFILE) || (echo "Couldn't extract task status from task $OID" ; cat $OUTFILE ; rm $OUTFILE ; return 1)
342
if [[ $TASK_STATUS = "success" ]]; then
343
echo "Task $OID status is OK"
344
rm $OUTFILE
345
return 0
346
else
347
echo "Task $OID status is not OK: $TASK_STATUS"
348
cat $OUTFILE
349
rm $OUTFILE
350
return 1
351
fi
352
}
353
354
function wait_for_task_completion () {
355
local OID=$1
356
local ATTEMPT=0
357
local MAX_ATTEMPTS=$2
358
local DELAY=$3
359
360
until [[ $ATTEMPT = $MAX_ATTEMPTS ]]; do
361
ATTEMPT=$((ATTEMPT+1))
362
echo "Waiting $DELAY seconds for task with oid $OID to finish (attempt $ATTEMPT) ..."
363
sleep $DELAY
364
get_object tasks $OID
365
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)
366
if [[ $TASK_EXECUTION_STATUS = "suspended" ]] || [[ $TASK_EXECUTION_STATUS = "closed" ]]; then
367
echo "Task $OID is finished"
368
rm $OUTFILE
369
return 0
370
fi
371
done
372
rm $OUTFILE
373
echo Task with $OID did not finish in $(( $MAX_ATTEMPTS * $DELAY )) seconds
374
return 1
375
}
376
377
378
function search_ldap_object_by_filter () {
379
local BASE_CONTEXT_FOR_SEARCH=$1
380
local FILTER="$2"
381
local LDAP_CONTAINER=$3
382
TMPFILE=$(mktemp /tmp/ldapsearch.XXXXXX)
383
384
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)
385
LDAPSEARCH_RESULT_FILE=$TMPFILE
386
return 0
389
function get_ldap_user () {
390
local USER_UID="$1"
391
local LDAP_CONTAINER=$2
392
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$USER_UID" $LDAP_CONTAINER || return 1
393
if ! grep -F "uid: $USER_UID" $LDAPSEARCH_RESULT_FILE; then
394
echo "Couldn't find user '$USER_UID'"
395
rm $LDAPSEARCH_RESULT_FILE
396
return 1
397
else
398
return 0
399
fi
400
}
401
402
function assert_ldap_user_has_value () {
403
local USER_UID="$1"
404
local TYPE=$2 # Entitlement or Affiliation
405
local VALUE="$3"
406
local LDAP_CONTAINER=$4
407
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
408
if ! grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
409
echo "'$USER_UID' has no $TYPE of '$VALUE'"
410
cat $LDAPSEARCH_RESULT_FILE
411
rm $LDAPSEARCH_RESULT_FILE
412
return 1
413
else
414
rm $LDAPSEARCH_RESULT_FILE
415
return 0
416
fi
417
}
418
419
function assert_ldap_user_has_no_value () {
420
local USER_UID="$1"
421
local TYPE=$2 # Entitlement or Affiliation
422
local VALUE="$3"
423
local LDAP_CONTAINER=$4
424
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
425
if grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
426
echo "'$USER_UID' has an $TYPE of '$VALUE' although it should not have one"
427
cat $LDAPSEARCH_RESULT_FILE
428
rm $LDAPSEARCH_RESULT_FILE
429
return 1
430
else
431
rm $LDAPSEARCH_RESULT_FILE
432
return 0
433
fi
434
}
435
436
function check_ldap_account_by_user_name () {
Oct 3, 2018
437
local NAME="$1"
438
local LDAP_CONTAINER=$2
439
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$NAME" $LDAP_CONTAINER
440
search_objects_by_name users $NAME
442
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)
443
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)
444
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)
445
446
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)
447
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)
448
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)
449
450
rm $SEARCH_RESULT_FILE
451
rm $LDAPSEARCH_RESULT_FILE
452
453
if [[ $MP_FULL_NAME = $LDAP_CN ]] && [[ $MP_GIVEN_NAME = $LDAP_GIVEN_NAME ]] && [[ $MP_FAMILY_NAME = $LDAP_SN ]]; then
454
return 0
455
fi
457
echo "User in Midpoint and LDAP Account with uid $NAME are not same"
458
return 1
459
}
460
461
function check_ldap_courses_by_name () {
462
local NAME="$1"
463
local LDAP_CONTAINER=$2
464
search_objects_by_name orgs $NAME
465
466
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)
467
468
search_ldap_object_by_filter "ou=courses,ou=groups,dc=internet2,dc=edu" "cn=$MP_ORG_IDENTIFIER" $LDAP_CONTAINER
469
470
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)
471
472
rm $SEARCH_RESULT_FILE
473
rm $LDAPSEARCH_RESULT_FILE
474
475
if [[ $MP_ORG_IDENTIFIER = $LDAP_CN ]]; then
476
return 0
477
fi
478
479
echo "Orgs $NAME in Midpoint and LDAP Group(Course) with cn $MP_ORG_IDENTIFIER are not same"
480
return 1
481
}
482
483
484
function check_of_ldap_membership () {
Oct 3, 2018
485
local NAME_OF_USER="$1"
486
local BASE_CONTEXT_FOR_GROUP="$2"
487
local NAME_OF_GROUP="$3"
488
local LDAP_CONTAINER=$4
489
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$NAME_OF_USER" $LDAP_CONTAINER
490
491
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)
493
search_ldap_object_by_filter "$BASE_CONTEXT_FOR_GROUP" "cn=$NAME_OF_GROUP" $LDAP_CONTAINER
494
495
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)
496
497
rm $LDAPSEARCH_RESULT_FILE
498
499
if [[ $LDAP_MEMBERS_DNS =~ $LDAP_ACCOUNT_DN ]]; then
500
return 0
501
fi
502
503
echo "LDAP Account with uid $NAME_OF_USER is not member of LDAP Group $NAME_OF_GROUP in base context $BASE_CONTEXT_FOR_GROUP"
504
return 1
505
}
You can’t perform that action at this time.