Skip to content

Commit

Permalink
Fix lsc-project#12 Do not delete entry if get script returns an error
Browse files Browse the repository at this point in the history
  • Loading branch information
soisik committed Jan 4, 2022
1 parent b271f26 commit 9462769
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ public int execute(String[] runtime, String[] env, String input) {
return execute(runtime, env, input, datas);
}

public String executeWithReturn(String[] runtime, String[] env, String input) {
public String executeWithReturn(String[] runtime, String[] env, String input) throws LscServiceException {
StringBuffer datas = new StringBuffer();
execute(runtime, env, input, datas);
int exitValue = execute(runtime, env, input, datas);
if (exitValue != 0) {
String message = "Process returned a non zero exit code, exit code=" + exitValue;
throw new LscServiceException(message, new RuntimeException(message));
}
return datas.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ public final void testCleanLdap2Ldap() throws Exception {
assertFalse(dstJndiServices.exists(DN_DELETE_DST));
}

public final void testFailOnBadExitCode() throws Exception {
// Clean should fail
SimpleSynchronize sync = new SimpleSynchronize();
List<String> cleanType = new ArrayList<String>();
cleanType.add("failOnErrorTestTask");
sync.setThreads(1);
boolean ret = sync.launch(new ArrayList<String>(), new ArrayList<String>(), cleanType);
assertFalse(ret);

}
private void launchSyncCleanTask(String taskName, boolean doSync,
boolean doClean) throws Exception {
// initialize required stuff
Expand Down
131 changes: 131 additions & 0 deletions src/test/resources/etc/lsc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<factory>com.sun.jndi.ldap.LdapCtxFactory</factory>
<tlsActivated>false</tlsActivated>
</ldapConnection>
<pluginConnection>
<name>executable</name>
<url>fake</url>
<username>fake</username>
<password>fake</password>
</pluginConnection>
</connections>
<tasks>
<task>
Expand Down Expand Up @@ -159,5 +165,130 @@
</dataset>
</propertiesBasedSyncOptions>
</task>
<task>
<name>failOnErrorTestTask</name>
<bean>org.lsc.beans.SimpleBean</bean>
<pluginSourceService implementationClass="org.lsc.plugins.connectors.executable.ExecutableLdifSourceService">
<name>failOnErrorTestTask-src-service</name>
<connection reference="executable" />
<exec:executableLdifSourceServiceSettings>
<name>failOnErrorTestTask-src-service-exec</name>
<connection reference="executable" />
<exec:listScript>src/test/resources/org/lsc/plugins/connectors/executable/list.sh</exec:listScript>
<exec:getScript>src/test/resources/org/lsc/plugins/connectors/executable/get-bad-return-code.sh</exec:getScript>
<exec:variables>
<entry><key>LDAP_BIND_DN</key><value>cn=Directory Manager</value></entry>
<entry><key>LDAP_BIND_PW</key><value>secret</value></entry>
<entry><key>LDAP_URL</key><value>ldap://localhost:33389</value></entry>
<entry><key>LDAP_BASE</key><value>ou=ldap2ldap2TestTaskSrc,ou=Test Data,dc=lsc-project,dc=org</value></entry>
<entry><key>LDAP_SCOPE</key><value>sub</value></entry>
</exec:variables>
</exec:executableLdifSourceServiceSettings>
</pluginSourceService>
<pluginDestinationService
implementationClass="org.lsc.plugins.connectors.executable.ExecutableLdapDestinationService">
<name>failOnErrorTestTask-dst-service</name>
<connection reference="ldap-dst-conn" />
<exec:executableLdapDestinationServiceSettings>
<name>failOnErrorTestTask-dst-service-exec</name>
<connection reference="ldap-dst-conn" />
<baseDn>ou=ldap2ldap2TestTaskDst,ou=Test Data,dc=lsc-project,dc=org</baseDn>
<pivotAttributes>
<string>sn</string>
</pivotAttributes>
<fetchedAttributes>
<string>description</string>
<string>cn</string>
<string>sn</string>
<string>userPassword</string>
<string>objectClass</string>
<string>uid</string>
<string>mail</string>
<string>telephoneNumber</string>
<string>seeAlso</string>
</fetchedAttributes>
<getAllFilter>(objectClass=person)</getAllFilter>
<getOneFilter>(&amp;(objectClass=person)(sn={sn}))</getOneFilter>
<!-- <exec:interpretor>CYGWIN</exec:interpretor>
<exec:interpretorBinary>c:/cygwin/bin/bash.exe</exec:interpretorBinary>
--> <exec:addScript>src/test/resources/org/lsc/plugins/connectors/executable/add.sh</exec:addScript>
<exec:updateScript>src/test/resources/org/lsc/plugins/connectors/executable/update.sh</exec:updateScript>
<exec:removeScript>src/test/resources/org/lsc/plugins/connectors/executable/delete.sh</exec:removeScript>
<exec:renameScript>src/test/resources/org/lsc/plugins/connectors/executable/rename.sh</exec:renameScript>
<exec:variables>
<entry><key>LDAP_BIND_DN</key><value>cn=Directory Manager</value></entry>
<entry><key>LDAP_BIND_PW</key><value>secret</value></entry>
<entry><key>LDAP_URL</key><value>ldap://localhost:33389</value></entry>
</exec:variables>
</exec:executableLdapDestinationServiceSettings>
</pluginDestinationService>
<propertiesBasedSyncOptions>
<mainIdentifier>js:"cn=" + srcBean.getDatasetFirstValueById("cn") + ",ou=ldap2ldap2TestTaskDst,ou=Test Data,dc=lsc-project,dc=org"</mainIdentifier>
<defaultDelimiter>,</defaultDelimiter>
<defaultPolicy>KEEP</defaultPolicy>
<dataset>
<name>telephoneNumber</name>
<policy>MERGE</policy>
<defaultValues>
<string>"123456"</string>
<string>"789987"</string>
</defaultValues>
<createValues>
<string>"000000"</string>
<string>"11111"</string>
</createValues>
</dataset>
<dataset>
<name>objectClass</name>
<policy>KEEP</policy>
<createValues>
<string>"inetOrgPerson"</string>
<string>"organizationalPerson"</string>
<string>"person"</string>
<string>"top"</string>
</createValues>
</dataset>
<dataset>
<name>initials</name>
<policy>FORCE</policy>
<createValues>
<string>"cn=oops"</string>
</createValues>
</dataset>
<dataset>
<name>default</name>
<policy>FORCE</policy>
</dataset>
<dataset>
<name>description</name>
<policy>MERGE</policy>
<defaultValues>
<string>srcBean.getDatasetFirstValueById("userPassword")</string>
</defaultValues>
</dataset>
<dataset>
<name>seeAlso</name>
<policy>FORCE</policy>
</dataset>
<dataset>
<name>userPassword</name>
<policy>FORCE</policy>
<defaultValues></defaultValues>
<forceValues>
<string>"secret" + srcBean.getDatasetFirstValueById("cn")</string>
</forceValues>
<createValues></createValues>
</dataset>
<dataset>
<name>mail</name>
<policy>FORCE</policy>
<defaultValues></defaultValues>
<forceValues></forceValues>
<createValues>
<string>"[email protected]"</string>
</createValues>
</dataset>
</propertiesBasedSyncOptions>
</task>
</tasks>
</lsc>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

line=""
read line
text="$line"
filter="(&(`echo "$line" | sed -e "s/^\([a-zA-Z0-9]\+\): \(.*\)$/\1=\2/g"`)"

while test "$line" != ""
do
read line
text="$text
$line"
if test "$line" != ""; then
filter="$filter(`echo "$line" | sed -e "s/^\([a-zA-Z0-9]\+\): \(.*\)$/\1=\2/g"`)"
fi
done

filter="$filter)"

echo "Getting user information for id=$1" 1>&2
ldapsearch -x -LLL -H "$LDAP_URL" -D "$LDAP_BIND_DN" -w "$LDAP_BIND_PW" -b "$LDAP_BASE" -s "$LDAP_SCOPE" "$filter" \
| sed -e "s/^\(dn: .*\),dc=lsc-project, *dc=org$/\1/g"

exit 1

0 comments on commit 9462769

Please sign in to comment.