From: <svn...@op...> - 2010-01-14 20:57:13
|
Author: scriptor Date: Thu Jan 14 21:57:04 2010 New Revision: 6009 URL: http://www.opensync.org/changeset/6009 Log: 1. I have eliminated the different ldap-sync.conf* files in tests/. Instead, the ldap-sync.conf is now generated from tests/ldap-sync.conf.templ each time, with the variables being set in test.conf. Thus the configuration becomes easier, as it is now concentrated in tests/test.conf and tests/CMakeLists.txt. Different ldap-sync.conf files are right now necessary only in the check_plugin_auth script. So this file might be worth being checked in case of any problems. Besides, for debugging purposes the "debug" variable in tests/test.conf can be set to "yes". This saves an ldap-sync.conf_${test_name} in the build subdirectory, when the tests are run, so these files can be checked whether something is wrong, there. 2. I have added further tests regarding the files in tests/vcards, tests/vevents, tests/vtodos and tests/vnotes. Trying to write them into the LDAP tree reveals quite some issues, most of them located outside of the LDAP plugin. Among these problems is a) http://www.opensync.org/ticket/1176 element AlarmRepeat: Schemas validity error : Element 'AlarmRepeat': '' is not a valid value of the atomic type 'xs:integer'. ERROR: XMLFormat validation failed. EXIT_ERROR: osync_converter_invoke: XMLFormat validation failed. b) "company phoneöä" is invalid for the LDAP attribute "homePhone" ERROR: /home/a0037/dev/plugins/ldap-sync-jl/src/ldap_plugin.c:3143: LDAP ERROR: "Invalid syntax". homePhone: value #0 invalid per syntax /home/a0037/dev/plugins/ldap-sync-jl/src/ldap_plugin.c:3143: LDAP ERROR: "Invalid syntax". homePhone: value #0 invalid per syntax /home/a0037/dev/plugins/ldap-sync-jl/src/ldap_plugin.c:3143: This error occurred with id = evo2-umlaute.vcf, chtype = 1 dn: uid=evo2-umlaute.vcf,ou=addressbook,dc=example,dc=com cn: Titleö Firstä Middleü Lastß Suffixö givenName: Firstä homePhone: company phoneöä homePostalAddress: Multiline street multiline cityäüööüä mail: workemailö o: organization objectClass: inetOrgPerson sn: Titleö Firstä Middleü Lastß Suffixö uid: evo2-umlaute.vcf c) Several validation errors regarding object type "event": element event: Schemas validity error : Element 'event': Missing child element(s ). Expected is one of ( AlarmAudio, AlarmDisplay, AlarmEmail, AlarmProcedure, Attach, Attendee, CalendarScale, Categories, Class, Comment ). ERROR: XMLFormat validation failed. EXIT_ERROR: osync_converter_invoke: XMLFormat validation failed. (occurred, for example, with evolution2-1-hour-alarm2.vcf) element Timezone: Schemas validity error : Element 'Timezone': This element is not expected. Expected is one of ( Uid, Url, Version ). ERROR: XMLFormat validation failed. EXIT_ERROR: osync_converter_invoke: XMLFormat validation failed. (occurred, for example, with evolution2-todo-full1.vcf) element Attendee: Schemas validity error : Element 'Attendee', attribute 'Status': The attribute 'Status' is not allowed. element Content: Schemas validity error : Element 'Content': [facet 'enumeration'] The value 'NEEDS_ACTION' is not an element of the set {'NEEDS-ACTION', 'COMPLETED', 'IN-PROCESS', 'CANCELLED'}. element Content: Schemas validity error : Element 'Content': 'NEEDS_ACTION' is not a valid value of the atomic type 'TodoStatusValue'. ERROR: XMLFormat validation failed. EXIT_ERROR: osync_converter_invoke: XMLFormat validation failed. (occurred with kdepim-todoful1.vcs) d) Possible detector problem: Entity: line 1: parser error : Start tag expected, '<' not found BEGIN:VCALENDAR ^ ERROR: Could not parse XML. Well, a vevent is not an XML file. (occurred, for example, with evolution2-1-hour-alarm.vcf) e) ERROR: /home/a0037/dev/plugins/ldap-sync-jl/src/ldap_connect.c:4622: WARNING: Value of keyattribute ("documentIdentifier"): "20050306T005538Z-4378-1000-1-28@azrael" conflicts with identifier: "evolution2-todo-full2.vcf". 3. New display utility tests/show_ldap_tree to make the debugging easier. 4. I have fixed several smaller bugs in the test scripts. And cleaned them up a bit. Added: plugins/ldap-sync/tests/check_common.inc - copied, changed from r6005, plugins/ldap-sync/tests/check_osynctool_common.inc Copied and modified: plugins/ldap-sync/tests/check_common.inc (from r6005, plugins/ldap-sync/tests/check_osynctool_common.inc) ============================================================================== --- plugins/ldap-sync/tests/check_osynctool_common.inc Wed Jan 13 13:08:22 2010 (r6005, copy source) +++ plugins/ldap-sync/tests/check_common.inc Thu Jan 14 21:57:04 2010 (r6009) @@ -3,6 +3,9 @@ enable_tracing() { + local rv=0 + + test_name="$1" if test -z "$test_name"; then echo "${FUNCNAME}(): ERROR: \$test_name is empty. Exiting." @@ -69,6 +72,9 @@ enable_trace_subdir() { + local rv=0 + + test_name="$1" if test -z "$test_name"; then echo "${FUNCNAME}(): ERROR: \$test_name is empty. Exiting." @@ -307,7 +313,54 @@ +build_dn() +{ + short_name="$1" + + if test -z "$short_name"; then + echo -e "${FUNCNAME}(): ERROR: \$short_name is empty. Exiting." + exit 1 + fi + + dn_to_be_found="" + dn_to_be_found2="" + dn_to_be_found3="" + + if test "$short_name" == "contact1.xml"; then + dn_to_be_found="$CONTACT1_DN" + dn_to_be_found3="uid=${short_name},${SEARCHBASE_CONTACT}" + elif test "$short_name" == "contact2.xml"; then + dn_to_be_found="$CONTACT2_DN" + dn_to_be_found3="uid=${short_name},${SEARCHBASE_CONTACT}" + elif test "$short_name" == "event1.xml"; then + dn_to_be_found="$EVENT1_DN" + dn_to_be_found3="documentIdentifier=${short_name},${SEARCHBASE_EVENT}" + elif test "$short_name" == "todo1.xml"; then + dn_to_be_found="$TODO1_DN" + dn_to_be_found3="documentIdentifier=${short_name},${SEARCHBASE_TODO}" + elif test "$short_name" == "note1.xml"; then + dn_to_be_found="$NOTE1_DN" + dn_to_be_found3="documentIdentifier=${short_name},${SEARCHBASE_NOTE}" + elif test "$short_name" == "note2.xml"; then + dn_to_be_found="$NOTE2_DN" + dn_to_be_found3="documentIdentifier=${short_name},${SEARCHBASE_NOTE}" + elif test "$objecttype" == "contact"; then + dn_to_be_found="uid=${short_name},${SEARCHBASE_CONTACT}" + dn_to_be_found3="$dn_to_be_found" + elif test "$objecttype" == "event"; then + dn_to_be_found="documentIdentifier=${short_name},${SEARCHBASE_EVENT}" + dn_to_be_found3="$dn_to_be_found" + elif test "$objecttype" == "todo"; then + dn_to_be_found="documentIdentifier=${short_name},${SEARCHBASE_TODO}" + dn_to_be_found3="$dn_to_be_found" + elif test "$objecttype" == "note"; then + dn_to_be_found="documentIdentifier=${short_name},${SEARCHBASE_NOTE}" + dn_to_be_found3="$dn_to_be_found" + fi + + +} @@ -317,6 +370,10 @@ verify_file_add() { xmlfile="$1" + objecttype="$2" + local rv=0 + + if test -z "$xmlfile"; then echo -e "${FUNCNAME}(): ERROR: \$xmlfile is empty. Exiting." exit 1 @@ -330,6 +387,16 @@ echo -e "${FUNCNAME}(): ERROR: $xmlfile could be found, but was not readable. Exiting." fi + if test -z "$objecttype"; then + echo -e "${FUNCNAME}(): ERROR: \$objecttype is empty. Exiting." + exit 1 + fi + + if test "$objecttype" != "contact" -a "$objecttype" != "event" -a "$objecttype" != "todo" -a "$objecttype" != "note"; then + echo -e "${FUNCNAME}(): ERROR: Unknown \$objecttype: \"$objecttype\" . Exiting." + exit 1 + fi + short_name=$(basename $xmlfile) if test -z "$short_name"; then @@ -337,21 +404,7 @@ exit 1 fi - dn_to_be_found="" - dn_to_be_found2="" - if test "$short_name" == "contact1.xml"; then - dn_to_be_found="$CONTACT1_DN" - elif test "$short_name" == "contact2.xml"; then - dn_to_be_found="$CONTACT2_DN" - elif test "$short_name" == "event1.xml"; then - dn_to_be_found="$EVENT1_DN" - elif test "$short_name" == "todo1.xml"; then - dn_to_be_found="$TODO1_DN" - elif test "$short_name" == "note1.xml"; then - dn_to_be_found="$NOTE1_DN" - elif test "$short_name" == "note2.xml"; then - dn_to_be_found="$NOTE2_DN" - fi + eval build_dn "$short_name" if test -z "$dn_to_be_found"; then echo -e "${FUNCNAME}(): ERROR: \$dn_to_be_found could not be set. Exiting." @@ -377,14 +430,23 @@ cmd="$LDAPSEARCH $AUTH -LLL -s base -b $dn_to_be_found" output=`$cmd` - local rv=$? + rv=$? if test $rv -ne 0; then cmd="$LDAPSEARCH $AUTH -LLL -s base -b $dn_to_be_found2" output=`$cmd` rv=$? if test $rv -ne 0; then - echo -e "${FUNCNAME}(): ERROR: ldapsearch could not find \"$dn_to_be_found\" nor \"$dn_to_be_found2\". Synchronizing after the addition must have failed. Exiting." - exit 1 + cmd="$LDAPSEARCH $AUTH -LLL -s base -b $dn_to_be_found3" + output=`$cmd` + rv=$? + if test $rv -ne 0; then + echo -e "${FUNCNAME}(): ERROR: ldapsearch could not find \"$dn_to_be_found\" nor \"$dn_to_be_found2\". Synchronizing after the addition must have failed. Exiting." + exit 1 + else + echo -e "\n\n\nOK. Synchronizing after the addition was successful.\n\n\n" + fi + else + echo -e "\n\n\nOK. Synchronizing after the addition was successful.\n\n\n" fi else echo -e "\n\n\nOK. Synchronizing after the addition was successful.\n\n\n" @@ -397,6 +459,9 @@ verify_file_delete() { + local rv=0 + + xmlfile="$1" if test -z "$xmlfile"; then echo -e "${FUNCNAME}(): ERROR: \$xmlfile is empty. Exiting." @@ -418,21 +483,7 @@ exit 1 fi - dn_to_be_found="" - dn_to_be_found2="" - if test "$short_name" == "contact1.xml"; then - dn_to_be_found="$CONTACT1_DN" - elif test "$short_name" == "contact2.xml"; then - dn_to_be_found="CONTACT2_DN" - elif test "$short_name" == "event1.xml"; then - dn_to_be_found="$EVENT1_DN" - elif test "$short_name" == "todo1.xml"; then - dn_to_be_found="$TODO1_DN" - elif test "$short_name" == "note1.xml"; then - dn_to_be_found="NOTE1_DN" - elif test "$short_name" == "note2.xml"; then - dn_to_be_found="NOTE2_DN" - fi + eval build_dn "$short_name" if test -z "$dn_to_be_found"; then echo -e "${FUNCNAME}(): ERROR: \$dn_to_be_found could not be set. Exiting." @@ -458,7 +509,7 @@ cmd="$LDAPSEARCH $AUTH -LLL -s base -b $dn_to_be_found2" output=`$cmd` - local rv=$? + rv=$? if test $rv -eq 0; then echo -e "${FUNCNAME}(): ERROR: ldapsearch found \"$dn_to_be_found2\". Synchronizing after the deletion must have failed. Exiting." exit 1 @@ -477,6 +528,7 @@ check_plugin_available() { + local rv=0 plugin="$1" if test -z "$plugin"; then @@ -501,18 +553,22 @@ $OSYNCTOOL --listplugins | grep -q "$plugin" - local rv=$? + rv=$? if test $rv -ne 0; then echo "${FUNCNAME}(): ERROR: ldap-sync was not included in pluginlist. Exiting." exit 1 fi + return $rv } check_ldap_formats() { + local rv=0 + + if test -z "$OSYNCTOOL"; then echo "${FUNCNAME}(): ERROR: \$OSYNCTOOL is empty. Exiting." exit 1; @@ -530,7 +586,7 @@ $OSYNCTOOL --listformats | grep -q "ldap-evolutionperson" - local rv=$? + rv=$? if test $rv -ne 0; then echo "${FUNCNAME}(): ERROR: ldap-evolutionperson was not included in formatlist. Exiting." exit 1 @@ -571,6 +627,9 @@ check_xmlformats() { + local rv=0 + + if test -z "$OSYNCTOOL"; then echo "${FUNCNAME}(): ERROR: \$OSYNCTOOL is empty. Exiting." exit 1; @@ -588,7 +647,7 @@ $OSYNCTOOL --listformats | grep -q "xmlformat-contact$" - local rv=$? + rv=$? if test $rv -ne 0; then echo "${FUNCNAME}(): ERROR: xmlformat-contact was not included in formatlist. Exiting." exit 1 @@ -641,6 +700,9 @@ check_file_directories() { + local rv=0 + + for f in "$CONTACT1_FILE" "$CONTACT2_FILE" "$EVENT1_FILE" "$TODO1_FILE" "$NOTE1_FILE" "$NOTE2_FILE"; do do_check_file_directories $f; rv=$?; @@ -657,6 +719,9 @@ configure_plugin() { + local rv=0 + + group="$1" if test -z "$group"; then echo "${FUNCNAME}(): ERROR: \$group is empty. Exiting."; @@ -669,19 +734,52 @@ exit 1; fi - member_config_file="$3" + BUILD_DIR="$3" + if test -z "$BUILD_DIR"; then + echo "$FILE:$LINENO: ERROR: \$BUILD_DIR is empty. Exiting."; + exit 1; + fi + + if test ! -d "$BUILD_DIR"; then + echo "$FILE:$LINENO: ERROR: \$BUILD_DIR = \"${BUILD_DIR}\" does not exist or is not a directory. Exiting."; + exit 1; + fi + + member_config_file="$4" if test -z "$member_config_file"; then echo "${FUNCNAME}(): ERROR: \$member_config_file is empty. Exiting."; exit 1; fi - if test ! -f "$SOURCE_DIR/$member_config_file"; then - echo "${FUNCNAME}(): ERROR: $SOURCE_DIR/$member_config_file does not exist. Exiting."; + if test -e "$SOURCE_DIR/$member_config_file"; then + config_file="$SOURCE_DIR/$member_config_file" + else + if test -e "$SOURCE_DIR/${member_config_file}.templ"; then + echo "${FUNCNAME}(): INFO: $SOURCE_DIR/${member_config_file}.templ could be found. Generating $BUILD_DIR/$member_config_file" + templ=$(eval "$SOURCE_DIR/${member_config_file}.templ") + echo "${templ}" > "$BUILD_DIR/$member_config_file" + else + echo "${FUNCNAME}(): INFO: $SOURCE_DIR/${member_config_file}.templ could NOT be found." + fi + + + if test -e "$BUILD_DIR/$member_config_file"; then + config_file="$BUILD_DIR/$member_config_file" + else + if test -e "$member_config_file"; then + config_file="$member_config_file" + fi + fi + fi + + + if test ! -e "$config_file"; then + echo "${FUNCNAME}(): ERROR: $config_file does not exist. Exiting."; exit 1; fi - if test ! -r "$SOURCE_DIR/$member_config_file"; then - echo "${FUNCNAME}(): ERROR: $SOURCE_DIR/$member_config_file does exist, but it is not readable. Exiting."; + if test ! -r "$config_file"; then + echo "${FUNCNAME}(): ERROR: $config_file does exist, but it is not readable. Exiting."; exit 1; fi @@ -720,7 +818,7 @@ export EDITOR="cat >" - $OSYNCTOOL --configdir "$TMPDIR" --configure "$group" "$memberid" < "$SOURCE_DIR/$member_config_file" + $OSYNCTOOL --configdir "$TMPDIR" --configure "$group" "$memberid" < "$config_file" local rv=$? @@ -734,6 +832,9 @@ setup_group() { + local rv=0 + + group="$1" if test -z "$group"; then echo "${FUNCNAME}(): ERROR: \$group is empty. Exiting."; @@ -741,6 +842,17 @@ fi + BUILD_DIR="$2" + if test -z "$BUILD_DIR"; then + echo "${FUNCNAME}(): ERROR: \$BUILD_DIR is empty. Exiting."; + exit 1; + fi + + if test ! -d "$BUILD_DIR"; then + echo "${FUNCNAME}(): ERROR: \$BUILD_DIR = \"${BUILD_DIR}\" does not exist or is not a directory. Exiting."; + exit 1; + fi + if test -z "$OSYNCTOOL"; then echo "${FUNCNAME}(): ERROR: \$OSYNCTOOL is empty. Exiting." exit 1; @@ -775,8 +887,8 @@ - configure_plugin "$group" "1" "file-sync.conf" - local rv=$? + configure_plugin "$group" "1" "${BUILD_DIR}" "file-sync.conf" + rv=$? if test $rv -ne 0; then echo "${FUNCNAME}(): ERROR: configure plugin \"$group\" \"1\" has failed. Exiting." @@ -788,7 +900,7 @@ - configure_plugin "$group" "2" "ldap-sync.conf" + configure_plugin "$group" "2" "${BUILD_DIR}" "ldap-sync.conf" rv=$? if test $rv -ne 0; then echo "${FUNCNAME}(): ERROR: configure plugin \"$group\" \"1\" has failed. Exiting." @@ -849,6 +961,17 @@ prologue() { + BUILD_DIR="$1" + if test -z "$BUILD_DIR"; then + echo "${FUNCNAME}(): ERROR: \$BUILD_DIR is empty. Exiting."; + exit 1; + fi + + if test ! -d "$BUILD_DIR"; then + echo "${FUNCNAME}(): ERROR: \$BUILD_DIR = \"${BUILD_DIR}\" does not exist or is not a directory. Exiting."; + exit 1; + fi + if test -n "$OSYNC_TRACE"; then remember="$OSYNC_TRACE" unset OSYNC_TRACE @@ -863,7 +986,7 @@ check_ldap_formats; check_xmlformats; - setup_group "$GROUPNAME" + setup_group "$GROUPNAME" "$BUILD_DIR" if test -n "$remember"; then @@ -900,6 +1023,9 @@ run_ldapadd() { ldif="$1" + local rv=0 + + if test -z "$ldif"; then echo "${FUNCNAME}(): ERROR: \$ldif is empty. Exiting." exit 1; @@ -920,12 +1046,12 @@ LDAPADD=$(which ldapadd 2>/dev/null) if test ! -f "$LDAPADD"; then - echo "$FILE:$LINENO: ERROR: ldapadd could not be found. Exiting." + echo "${FUNCNAME}(): ERROR: ldapadd could not be found. Exiting." exit 1 fi if test ! -x "$LDAPADD"; then - echo "$FILE:$LINENO: ERROR: ldapadd could be found, but is not executable. Exiting." + echo "${FUNCNAME}(): ERROR: ldapadd could be found, but is not executable. Exiting." exit 1 fi @@ -958,7 +1084,7 @@ echo "Command: $LDAPADD $AUTH -a -f $ldif" $LDAPADD $AUTH -a -f $ldif - local rv=$? + rv=$? if test $rv -ne 0; then echo "${FUNCNAME}(): ERROR: ldapadd has failed. Exiting." exit $rv; @@ -971,6 +1097,7 @@ run_ldapmodify() { + local rv=0 entrymods="$1" if test -z "$entrymods"; then echo "${FUNCNAME}(): ERROR: \$entrymods is empty. Exiting." @@ -1017,7 +1144,7 @@ echo "Command: $LDAPMODIFY $AUTH -f $entrymods" $LDAPMODIFY $AUTH -f $entrymods - local rv=$? + rv=$? if test $rv -ne 0; then echo "${FUNCNAME}(): ERROR: ldapmodify has failed. Exiting." exit $rv; @@ -1030,6 +1157,7 @@ run_ldapdelete() { + local rv=0 ldif="$1" if test -z "$ldif"; then echo "${FUNCNAME}(): ERROR: \$ldif is empty. Exiting." @@ -1090,7 +1218,7 @@ echo "Command: $LDAPDELETE $AUTH -r $DN" $LDAPDELETE $AUTH -r $DN - local rv=$? + rv=$? if test $rv -ne 0; then $LDAPDELETE $AUTH -r ${DN/@/_} rv=$? @@ -1109,6 +1237,8 @@ { check_file_directories; + CONTACT_FILE="$1" + if test -z "$CONTACT1_FILE"; then echo "${FUNCNAME}(): ERROR: \$CONTACT1_FILE is empty. Ignoring." elif test -f "$CONTACT1_FILE"; then @@ -1121,39 +1251,81 @@ rm -f ${CONTACT2_FILE}* fi - # output=$(ls -al /tmp/file_contact) - # echo -e "$output\n" + if test -n "$CONTACT_FILE"; then + rm -f "${CONTACT_DIR}/$CONTACT_FILE" + fi + + for f in ${CONTACT_FILES}; do + rm -f "${CONTACT_DIR}/${f}" + done + + if test $debug = "yes" -o "$debug" = "on" -o "$debug" = "true"; then + output=$(ls -al "${CONTACT_DIR}") + echo -e "$output\n" + fi } remove_event1_file() { + EVENT_FILE="$1" + if test -z "$EVENT1_FILE"; then echo "${FUNCNAME}(): ERROR: \$EVENT1_FILE is empty. Ignoring." elif test -f "$EVENT1_FILE"; then rm -f ${EVENT1_FILE}* fi - # output=$(ls -al /tmp/file_event) - # echo -e "$output\n" + + if test -n "$EVENT_FILE"; then + rm -f "${EVENT_DIR}/$EVENT_FILE" + fi + + + for f in ${EVENT_FILES}; do + rm -f "${EVENT_DIR}/${f}" + done + + + if test $debug = "yes" -o "$debug" = "on" -o "$debug" = "true"; then + output=$(ls -al "${EVENT_DIR}") + echo -e "$output\n" + fi } remove_todo1_file() { + TODO_FILE="$1" + + if test -z "$TODO1_FILE"; then echo "${FUNCNAME}(): ERROR: \$TODO1_FILE is empty. Ignoring." elif test -f "$TODO1_FILE"; then rm -f ${TODO1_FILE}* fi - # output=$(ls -al /tmp/file_todo) - # echo -e "$output\n" + + if test -n "$TODO_FILE"; then + rm -f "${TODO_DIR}/$TODO_FILE" + fi + + for f in ${TODO_FILES}; do + rm -f "${TODO_DIR}/${f}" + done + + if test $debug = "yes" -o "$debug" = "on" -o "$debug" = "true"; then + output=$(ls -al "${TODO_DIR}") + echo -e "$output\n" + fi } remove_note_files() { + NOTE_FILE="$1" + + if test -z "$NOTE1_FILE"; then echo "${FUNCNAME}(): ERROR: \$NOTE1_FILE is empty. Ignoring." elif test -f "$NOTE1_FILE"; then @@ -1166,14 +1338,30 @@ rm -f ${NOTE2_FILE}* fi - # output=$(ls -al /tmp/file_note) - # echo -e "$output\n" + + if test -n "$NOTE_FILE"; then + rm -f "${NOTE_DIR}/$NOTE_FILE" + fi + + + for f in ${NOTE_FILES}; do + p="${NOTE_DIR}/${f}" + rm -f + done + + + if test $debug = "yes" -o "$debug" = "on" -o "$debug" = "true"; then + output=$(ls -al "${NOTE_DIR}") + echo -e "$output\n" + fi } remove_file_by_objtype() { objtype="$1" + xmlfile="$2" + if test -z "$objtype"; then echo "${FUNCNAME}(): ERROR: \$objtype is empty. Exiting."; @@ -1187,13 +1375,13 @@ if test "$objtype" == "contact"; then - remove_contact_files + remove_contact_files "$xmlfile" elif test "$objtype" == "event"; then - remove_event1_file + remove_event1_file "$xmlfile" elif test "$objtype" == "todo"; then - remove_todo1_file + remove_todo1_file "$xmlfile" elif test "$objtype" == "note"; then - remove_note_files + remove_note_files "$xmlfile" fi } @@ -1207,10 +1395,269 @@ remove_event1_file remove_todo1_file remove_note_files + + # Workaround for failing tests: + remove_event1_file "event1.xml" + remove_todo1_file "todo1.xml" } +do_clear_dn() +{ + local rv=0 + dn="$1" + if test -z "$dn"; then + echo "$FILE:$LINENO: ERROR: \$dn is empty. Exiting." + exit 1 + fi + + + LDAPSEARCH=$(which ldapsearch 2>/dev/null) + if test -z "$LDAPSEARCH"; then + echo -e "${FUNCNAME}(): ERROR: \$LDAPSEARCH could not be found. Exiting." + exit 1 + fi + + if test ! -f "$LDAPSEARCH"; then + echo -e "${FUNCNAME}(): ERROR: ldapsearch could not be found. Exiting." + exit 1 + fi + + if test ! -x "$LDAPSEARCH"; then + echo -e "${FUNCNAME}(): ERROR: ldapsearch could be found, but is not executable. Exiting." + exit 1 + fi + + + LDAPDELETE=$(which ldapdelete 2>/dev/null) + + if test ! -f "$LDAPDELETE"; then + echo "$FILE:$LINENO: ERROR: ldapdelete could not be found. Exiting." + exit 1 + fi + + if test ! -x "$LDAPDELETE"; then + echo "$FILE:$LINENO: ERROR: ldapdelete could be found, but is not executable. Exiting." + exit 1 + fi + + echo "${FUNCNAME}(): AUTH = \"$AUTH\"" + + $LDAPSEARCH $AUTH -LLL -s base -b "$dn" 2> /dev/null + rv=$? + if test $rv -eq 0; then + echo "$FILE:$LINENO: Found ${dn}. Trying to delete it." + $LDAPDELETE $AUTH -r "$dn" + rv2=$? + if test $rv2 -ne 0; then + echo "$FILE:$LINENO: ERROR: ldapdelete has failed with \$dn = \"$dn\". Exiting." + exit $rv2; + fi + else + if test $rv -ne 32; then + echo -e "\n\n$FILE:$LINENO: ERROR: ldapsearch has failed with \$dn = \"$dn\"\n\n" + fi + fi + +} + + + + +clear_dn() +{ + dn="$1" + if test -z "$dn"; then + echo "$FILE:$LINENO: ERROR: \$dn is empty. Exiting." + exit 1 + fi + + dn2="${dn/@/_}" + if test -z "$dn2"; then + echo "$FILE:$LINENO: ERROR: \$dn2 is empty. Exiting." + exit 1 + fi + + do_clear_dn "$dn" + + do_clear_dn "$dn2" +} + + + + +remove_ldif_by_objtype() +{ + objtype="$1" + short_name="$2" + local rv=0 + + + eval build_dn "$short_name" + if test -z "$dn_to_be_found"; then + echo -e "${FUNCNAME}(): ERROR: \$dn_to_be_found could not be set. Exiting." + exit 1 + fi + + dn_to_be_found2="${dn_to_be_found/@/_}" + + LDAPSEARCH=$(which ldapsearch 2>/dev/null) + if test -z "$LDAPSEARCH"; then + echo -e "${FUNCNAME}(): ERROR: \$LDAPSEARCH could not be found. Exiting." + exit 1 + fi + + if test ! -f "$LDAPSEARCH"; then + echo -e "${FUNCNAME}(): ERROR: ldapsearch could not be found. Exiting." + exit 1 + fi + + if test ! -x "$LDAPSEARCH"; then + echo -e "${FUNCNAME}(): ERROR: ldapsearch could be found, but is not executable. Exiting." + exit 1 + fi + + + echo "AUTH = \"$AUTH\"" + + cmd="$LDAPSEARCH $AUTH -LLL -s base -b $dn_to_be_found" + output=`$cmd` + rv=$? + if test $rv -ne 0; then + cmd="$LDAPSEARCH $AUTH -LLL -s base -b $dn_to_be_found2" + output=`$cmd` + rv=$? + if test $rv -eq 0; then + clear_dn "$dn_to_be_found2" + else + cmd="$LDAPSEARCH $AUTH -LLL -s base -b $dn_to_be_found3" + output=`$cmd` + rv=$? + if test $rv -eq 0; then + clear_dn "$dn_to_be_found3" + fi + fi + else + clear_dn "$dn_to_be_found" + fi + +} + + + + +remove_ldifs() +{ + + if test -z "$AUTH"; then + echo "$FILE:$LINENO: ERROR: \$AUTH is empty. Exiting."; + exit 1 + fi + + + if test -z "$CONTACT1_DN"; then + echo "$FILE:$LINENO: ERROR: \$CONTACT1 is empty. Exiting."; + exit 1 + fi + + + if test -z "$CONTACT2_DN"; then + echo "$FILE:$LINENO: ERROR: \$CONTACT2 is empty. Exiting."; + exit 1 + fi + + + if test -z "$EVENT1_DN"; then + echo "$FILE:$LINENO: ERROR: \$EVENT1 is empty. Exiting."; + exit 1 + fi + + + if test -z "$TODO1_DN"; then + echo "$FILE:$LINENO: ERROR: \$TODO1 is empty. Exiting."; + exit 1 + fi + + + if test -z "$NOTE1_DN"; then + echo "$FILE:$LINENO: ERROR: \$NOTE1 is empty. Exiting."; + exit 1 + fi + + if test -z "$NOTE2_DN"; then + echo "$FILE:$LINENO: ERROR: \$NOTE1 is empty. Exiting."; + exit 1 + fi + + + LDAPSEARCH=$(which ldapsearch 2>/dev/null) + + if test ! -f "$LDAPSEARCH"; then + echo "$FILE:$LINENO: ERROR: ldapsearch could not be found. Exiting." + exit 1 + fi + + if test ! -x "$LDAPSEARCH"; then + echo "$FILE:$LINENO: ERROR: ldapsearch could be found, but is not executable. Exiting." + exit 1 + fi + + + LDAPDELETE=$(which ldapdelete 2>/dev/null) + + if test ! -f "$LDAPDELETE"; then + echo "$FILE:$LINENO: ERROR: ldapdelete could not be found. Exiting." + exit 1 + fi + + if test ! -x "$LDAPDELETE"; then + echo "$FILE:$LINENO: ERROR: ldapdelete could be found, but is not executable. Exiting." + exit 1 + fi + + + clear_dn "$CONTACT1_DN" + + clear_dn "$CONTACT2_DN" + + clear_dn "$EVENT1_DN" + + clear_dn "$TODO1_DN" + + clear_dn "$NOTE1_DN" + + clear_dn "$NOTE2_DN" + + + for f in ${CONTACT_FILES}; do + dn="uid=${f},${SEARCHBASE_CONTACT}" + clear_dn "$dn" + done + + for f in ${EVENT_FILES}; do + dn="documentIdentifier=${f},${SEARCHBASE_EVENT}" + clear_dn "$dn" + done + + for f in ${TODO_FILES}; do + dn="documentIdentifier=${f},${SEARCHBASE_TODO}" + clear_dn "$dn" + done + + for f in ${NOTE_FILES}; do + dn="documentIdentifier=${f},${SEARCHBASE_NOTE}" + clear_dn "$dn" + done + + + # Workaround for failing tests: + clear_dn "documentIdentifier=todo1.xml,ou=todo,dc=example,dc=com" +} + + + + add_file() { objtype="$1" @@ -1254,15 +1701,24 @@ elif test "$tmp" == "contact2.xml"; then cp -f "$xmlfile" $CONTACT2_FILE else - echo "$FUNCNAME(): ERROR: Cannot find out whether to take CONTACT1_FILE or CONTACT2_FILE. Exiting." - exit 1; + cp -f "$xmlfile" $CONTACT_DIR + fi + + if test $debug = "yes" -o "$debug" = "on" -o "$debug" = "true"; then + echo + echo + echo + ls -al $CONTACT_DIR + echo + echo + echo fi elif test "$objtype" == "event"; then - cp -f "$xmlfile" $EVENT1_FILE + cp -f "$xmlfile" $EVENT_DIR elif test "$objtype" == "todo"; then - cp -f "$xmlfile" $TODO1_FILE + cp -f "$xmlfile" $TODO_DIR elif test "$objtype" == "note"; then tmp=$(basename "$xmlfile") @@ -1272,8 +1728,7 @@ elif test "$tmp" == "note2.xml"; then cp -f "$xmlfile" $NOTE2_FILE else - echo "$FUNCNAME(): ERROR: Cannot find out whether to take NOTE1_FILE or NOTE2_FILE. Exiting." - exit 1; + cp -f "$xmlfile" $NOTE_DIR fi fi @@ -1702,6 +2157,7 @@ { group="$GROUPNAME" objtype="$1" + local rv=0 if test -z "$group"; then @@ -1754,8 +2210,9 @@ $VALGRIND $OSYNCTOOL --configdir "$TMPDIR" --sync "$group" --slow-sync "$objtype" --always-accept-forecast --conflict 2 + rv=$? - + return $rv } @@ -1810,3 +2267,60 @@ $VALGRIND $OSYNCTOOL --configdir "$TMPDIR" --sync "$group" --always-accept-forecast --conflict 2 } + + + +generate_conf() +{ + SOURCE_DIR="$1" + BUILD_DIR="$2" + PLUGINNAME="$3" + + if test -z "$SOURCE_DIR"; then + echo "${FUNCNAME}(): ERROR: \$SOURCE_DIR is empty. Exiting."; + exit 1; + fi + + if test -z "$BUILD_DIR"; then + echo "${FUNCNAME}(): ERROR: \$BUILD_DIR is empty. Exiting."; + exit 1; + fi + + if test -z "$PLUGINNAME"; then + echo "${FUNCNAME}(): ERROR: \$PLUGINNAME is empty. Exiting."; + exit 1; + fi + + + if test -e "$SOURCE_DIR/${PLUGINNAME}.conf"; then + CFG="$SOURCE_DIR/${PLUGINNAME}.conf" + else + if test -e "$3/${PLUGINNAME}.conf"; then + CFG="$3/${PLUGINNAME}.conf" + else + if test -e "$SOURCE_DIR/${PLUGINNAME}.conf.templ"; then + echo "${FUNCNAME}(): INFO: $SOURCE_DIR/${PLUGINNAME}.conf.templ could be found. Generating $BUILD_DIR/${PLUGINNAME}.conf" + templ=$(eval "$SOURCE_DIR/${PLUGINNAME}.conf.templ") + echo "${templ}" > "$BUILD_DIR/${PLUGINNAME}.conf" + CFG="$BUILD_DIR/${PLUGINNAME}.conf" + else + echo "${FUNCNAME}(): ERROR: $SOURCE_DIR/${PLUGINNAME}.conf.templ could NOT be found. Exiting." + exit 1 + fi + fi + fi + + + if test -z "$CFG"; then + echo "${FUNCNAME}(): ERROR: \$CFG is empty. Exiting."; + exit 1; + fi + + + if test ! -e "$CFG"; then + echo "${FUNCNAME}(): ERROR: \$CFG = \"$CFG\" does not exist. Exiting."; + exit 1; + fi + + +} |