Skip to content
Permalink
Browse files

Add RabbitMQ-related tests in demo/complex

Plus a couple of other fixes in library.bash.
  • Loading branch information
mederly committed Oct 11, 2018
1 parent 5c4f48a commit 462ef741f228ff487714feffb9a4db1609fe806f
Showing with 106 additions and 25 deletions.
  1. +1 −1 Jenkinsfile
  2. +17 −6 demo/complex/tests/main.bats
  3. +1 −1 demo/complex/tests/resources/rabbitmq/check-samplequeue.sh
  4. +87 −17 library.bash
@@ -59,7 +59,7 @@ pipeline {
sh '(cd demo/simple ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
sh '(cd demo/shibboleth ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
sh '(cd demo/postgresql ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
//sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
sh '(cd demo/complex ; bats tests ) 2>&1 | tee -a debug ; test ${PIPESTATUS[0]} -eq 0'
} catch (error) {
def error_details = readFile('./debug')
def message = "BUILD ERROR: There was a problem testing ${imagename}:${tag}. \n\n ${error_details}"
@@ -125,7 +125,6 @@ load ../../../library
check_ldap_account_by_user_name amorrison complex_directory_1
check_ldap_account_by_user_name wprice complex_directory_1
check_ldap_account_by_user_name mroberts complex_directory_1
# TODO check assignments etc
}

@test "230 Import SIS_COURSES" {
@@ -215,12 +214,17 @@ load ../../../library
}

@test "320 Wait for the import to finish" {
if [ -e $BATS_TMPDIR/not-started ]; then skip 'not started'; fi

wait_for_task_completion 617fec0c-f7a6-4f91-89d0-395fb8878edd 8 10
assert_task_success 617fec0c-f7a6-4f91-89d0-395fb8878edd
}

@test "330 Assert wprice membership in LDAP" {
skip TODO
if [ -e $BATS_TMPDIR/not-started ]; then skip 'not started'; fi

assert_ldap_user_has_value wprice Entitlement "etc:testGroup" complex_directory_1
assert_ldap_user_has_value wprice Entitlement "ref:affiliation:alum" complex_directory_1
}

@test "400 Clean sampleQueue" {
@@ -246,27 +250,34 @@ load ../../../library
docker exec complex_grouper_daemon_1 bash -c "/opt/grouper/grouper.apiBinary/bin/gsh /tmp/t420.gsh"
}

@test "430 Assert existence of change messages in sampleQueue" {
@test "425 Wait 80 seconds for changes to be propagated to MQ" {
if [ -e $BATS_TMPDIR/not-started ]; then skip 'not started'; fi

sleep 80
}

@test "430 Assert existence of change messages in sampleQueue" {
if [ -e $BATS_TMPDIR/not-started ]; then skip 'not started'; fi

docker cp tests/resources/rabbitmq/check-samplequeue.sh complex_mq_1:/tmp/
docker exec complex_mq_1 bash /tmp/check-samplequeue.sh
}

@test "440 Execute Grouper-to-midPoint live sync task (again)" {
if [ -e $BATS_TMPDIR/not-started ]; then skip 'not started'; fi

skip TODO

check_health
run_task_now 87ffce52-717a-4205-ba01-0a698f0deaee
wait_for_task_completion 87ffce52-717a-4205-ba01-0a698f0deaee 8 10
assert_task_success 87ffce52-717a-4205-ba01-0a698f0deaee
}

@test "450 Assert wprice and kwhite membership in LDAP" {
skip TODO
if [ -e $BATS_TMPDIR/not-started ]; then skip 'not started'; fi

assert_ldap_user_has_value kwhite Entitlement "etc:testGroup" complex_directory_1
assert_ldap_user_has_value wprice Entitlement "etc:testGroup" complex_directory_1
assert_ldap_user_has_no_value wprice Entitlement "ref:affiliation:alum" complex_directory_1
}

@test "999 Clean up" {
@@ -1,4 +1,4 @@
count=$(rabbitmqctl list_queues | grep s1ampleQueue | awk '{print $2}')
count=$(rabbitmqctl list_queues | grep sampleQueue | awk '{print $2}')
if [[ -z $count || $count -eq 0 ]]; then
echo "ERROR: sampleQueue does not exist or is empty"
exit 1
@@ -142,23 +142,25 @@ function add_object () {

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
local HTTP_CODE=$(sed '$!d' $TMPFILE)
sed -i '$ d' $TMPFILE

if [ "$HTTP_CODE" -eq 201 ] || [ "$HTTP_CODE" -eq 202 ]; then

OID=$(grep -oP "Location: \K.*" $TMPFILE | awk -F "$TYPE/" '{print $2}') || (echo "Couldn't extract oid from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
OID=$(grep -oP "Location: \K.*" $TMPFILE | awk -F "$TYPE/" '{print $2}') || (echo "Couldn't extract oid from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)

echo "OID of created object: $OID"
rm $TMPFILE
rm $TMPFILE
return 0
else
echo "Error code: $HTTP_CODE"
if [ "$HTTP_CODE" -ge 500 ]; then
echo "Error code: $HTTP_CODE"
if [ "$HTTP_CODE" -ge 500 ]; then
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
else
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='error']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
else
echo $(sed '1,/^\s*$/d' $TMPFILE) >$TMPFILE
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
echo "Error message: $ERROR_MESSAGE"
fi
rm $TMPFILE
fi
rm $TMPFILE
return 1
fi
}
@@ -192,17 +194,39 @@ function execute_bulk_action () {

else
echo "Error code: $HTTP_CODE"
if [ "$HTTP_CODE" -ge 500 ]; then
if [[ $HTTP_CODE -ge 500 ]]; then
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
else
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='error']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
echo "Error message: $ERROR_MESSAGE"
fi
rm $TMPFILE
return 1
fi
}

# parameter $2 (CONTAINER) is just for diagnostics: it is the container whose logs we want to dump on error (might be omitted)
function run_task_now () {
local OID=$1
local CONTAINER=$2
echo "Running task $1 now..."
TMPFILE=$(mktemp /tmp/runtasknow.XXXXXX)

(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)
local HTTP_CODE=$(sed '$!d' $TMPFILE)
sed -i '$ d' $TMPFILE

if [[ $HTTP_CODE -ge 200 && $HTTP_CODE -lt 300 ]]; then
rm $TMPFILE
return 0
else
echo "Error code: $HTTP_CODE"
cat $TMPFILE
rm $TMPFILE
return 1
fi
}

function delete_object_by_name () {
local TYPE=$1
local NAME=$2
@@ -227,13 +251,13 @@ function delete_object () {
return 0
else
echo "Error code: $HTTP_CODE"
if [ "$HTTP_CODE" -ge 500 ]; then
if [[ $HTTP_CODE -ge 500 ]]; then
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
else
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='error']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
echo "Error message: $ERROR_MESSAGE"
fi
rm $TMPFILE
#rm $TMPFILE
return 1
fi
}
@@ -265,10 +289,10 @@ EOF
return 0
else
echo "Error code: $HTTP_CODE"
if [ "$HTTP_CODE" -ge 500 ]; then
if [[ $HTTP_CODE -ge 500 ]]; then
echo "Error message: Internal server error. Unexpected error occurred, if necessary please contact system administrator."
else
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='error']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
local ERROR_MESSAGE=$(xmllint --xpath "/*/*[local-name()='message']/text()" $TMPFILE) || (echo "Couldn't extract error message from file:" ; cat $TMPFILE ; rm $TMPFILE; return 1)
echo "Error message: $ERROR_MESSAGE"
fi
rm $SEARCH_RESULT_FILE
@@ -351,18 +375,64 @@ function wait_for_task_completion () {
}


#search LDAP accout by uid
function search_ldap_object_by_filter () {
local BASE_CONTEXT_FOR_SEARCH=$1
local FILTER="$2"
local LDAP_CONTAINER=$3
TMPFILE=$(mktemp /tmp/ldapsearch.XXXXXX)

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)
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)
LDAPSEARCH_RESULT_FILE=$TMPFILE
return 0
}

function get_ldap_user () {
local USER_UID="$1"
local LDAP_CONTAINER=$2
search_ldap_object_by_filter "ou=people,dc=internet2,dc=edu" "uid=$USER_UID" $LDAP_CONTAINER || return 1
if ! grep -F "uid: $USER_UID" $LDAPSEARCH_RESULT_FILE; then
echo "Couldn't find user '$USER_UID'"
rm $LDAPSEARCH_RESULT_FILE
return 1
else
return 0
fi
}

function assert_ldap_user_has_value () {
local USER_UID="$1"
local TYPE=$2 # Entitlement or Affiliation
local VALUE="$3"
local LDAP_CONTAINER=$4
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
if ! grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
echo "'$USER_UID' has no $TYPE of '$VALUE'"
cat $LDAPSEARCH_RESULT_FILE
rm $LDAPSEARCH_RESULT_FILE
return 1
else
rm $LDAPSEARCH_RESULT_FILE
return 0
fi
}

function assert_ldap_user_has_no_value () {
local USER_UID="$1"
local TYPE=$2 # Entitlement or Affiliation
local VALUE="$3"
local LDAP_CONTAINER=$4
get_ldap_user "$USER_UID" $LDAP_CONTAINER || return 1
if grep -F "eduPerson$TYPE: $VALUE" $LDAPSEARCH_RESULT_FILE; then
echo "'$USER_UID' has an $TYPE of '$VALUE' although it should not have one"
cat $LDAPSEARCH_RESULT_FILE
rm $LDAPSEARCH_RESULT_FILE
return 1
else
rm $LDAPSEARCH_RESULT_FILE
return 0
fi
}

function check_ldap_account_by_user_name () {
local NAME="$1"
local LDAP_CONTAINER=$2

0 comments on commit 462ef74

Please sign in to comment.
You can’t perform that action at this time.