/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2011 profiq s.r.o.
* Portions Copyright 2013-2015 ForgeRock AS
*/
/**
* Tests for the attribute cleanup plugin.
*/
@SuppressWarnings("javadoc")
{
{
}
{
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin",
"",
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin",
"ds-cfg-remove-inbound-attributes: modifyTimeStamp",
"ds-cfg-remove-inbound-attributes: createTimeStamp",
"",
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin",
"ds-cfg-rename-inbound-attributes: cn:uid");
return toArrayArray(entries);
}
throws Exception
{
}
{
/* local attribute is not defined */
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin",
"ds-cfg-rename-inbound-attributes: cn:badAttr",
"",
/* duplicate attributes */
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin",
"ds-cfg-rename-inbound-attributes: cn:uid",
"ds-cfg-rename-inbound-attributes: cn:description",
"",
/* self mapping */
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin",
"ds-cfg-rename-inbound-attributes: cn:cn");
return toArrayArray(entries);
}
{
{
}
return array;
}
expectedExceptions = { ConfigException.class } )
{
}
/**
* Verifies the attribute renaming in the incoming ADD operation.
*
* @throws Exception in case of bugs.
*/
@Test
{
// Configure the plugin to rename incoming 'cn' attributes to 'description'.
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-rename-inbound-attributes: cn:description",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin");
/* Construct the ADD operation as follows:
*
* dn: uid=test,dc=example,dc=com
* objectClass: top
* objectClass: person
* objectClass: organizationalPerson
* objectClass: inetOrgPerson
* uid: test
* cn: Name Surname
* sn: Surname
*/
1,
1,
null,
/* Process the operation. The processing should continue. */
/* Verify that the 'cn' attribute has been renamed to 'description'
* by getting the 'decription' attribute and matching the value with
* the original 'cn' value.
*/
{
{
return;
}
}
fail();
}
/**
* Verifies the attribute removal in the incoming ADD request.
* @throws Exception in case of bugs.
*/
@Test
{
/* Configure the plugin to remove 'modifyTimeStamp' and
* 'createTimeStamp' attributes from the incoming ADD requests.
*/
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-remove-inbound-attributes: modifyTimeStamp",
"ds-cfg-remove-inbound-attributes: createTimeStamp",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin");
/* Create the ADD operation as follows:
*
* dn: uid=test,dc=example,dc=com
* objectClass: top
* objectClass: person
* objectClass: organizationalPerson
* objectClass: inetOrgPerson
* uid: test
* cn: Name Surname
* sn: Surname
* modifyTimeStamp: 2011091212400000Z
* createTimeStamp: 2011091212400000Z
*/
1,
1,
null,
/* Process the operation and expect the server to continue
* processing the operation.
*/
/* Verify that the '*TimeStamp' attributes have been removed. */
{
}
}
/**
* In some cases the plugin might remove all attributes from the
* incoming MODIFY request which would make the request invalid by the
* LDAP standards. However, this is a special case and the request
* should be silently dropped while the client should be notified of
* SUCCESS.
* @throws Exception in case of a bug.
*/
@Test
{
/* Configure the plugin to remove 'modifyTimeStamp' and
* 'createTimeStamp' attributes from the incoming MODIFY request.
*/
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-remove-inbound-attributes: modifyTimeStamp",
"ds-cfg-remove-inbound-attributes: createTimeStamp",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin");
/* Create the MODIFY request as follows:
*
* dn: uid=test,dc=example,dc=com
* changetype: modify
* replace: modifyTimeStamp
* modifyTimeStamp: 2011091212400000Z
* -
* replace: createTimeStamp
* createTimeStamp: 2011091212400000Z
* -
*/
"modifyTimeStamp",
"2011091212400000Z"));
"createTimeStamp",
"2011091212400000Z"));
1,
1,
null,
rawMods);
/* Process the request. The result should be SUCCESS and the server
* should stop the processing.
*/
}
/**
* Verify the attribute renaming for a MODIFY operation.
* @throws Exception in case of a bug.
*/
@Test
{
/* Configure the plugin to remove 'modifyTimeStamp' and
* 'createTimeStamp' attributes from the incoming requests.
*/
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-remove-inbound-attributes: modifyTimeStamp",
"ds-cfg-remove-inbound-attributes: createTimeStamp",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin");
/* Create the MODIFY operation as follows:
*
* dn: uid=test,dc=example,dc=com
* changetype: modify
* replace: cn
* cn: Test User
* -
* replace: sn
* sn: User
* -
* replace: modifyTimeStamp
* modifyTimeStamp: 2011091212400000Z
* -
* replace: createTimeStamp
* createTimeStamp: 2011091212400000Z
* -
*/
"cn",
"Test User"));
"sn",
"User"));
"modifyTimeStamp",
"2011091212400000Z"));
"createTimeStamp",
"2011091212400000Z"));
1,
1,
null,
rawMods);
/* Process the MODIFY operation making sure the remaining number of
* modifications is 2 and that the '*TimeStamp' modifications are
* removed.
*/
{
{
+ "' exists and it shouldn't");
}
}
}
/**
* Verify the attribute renaming for the MODIFY operation.
*/
@Test
{
/* Configure the plugin to rename the 'modifyTimeStamp' attribute to
* 'description'.
*/
"dn: cn=Attribute Cleanup,cn=Plugins,cn=config",
"objectClass: top",
"objectClass: ds-cfg-plugin",
"objectClass: ds-cfg-attribute-cleanup-plugin",
"cn: Attribute Cleanup",
"ds-cfg-enabled: true",
"ds-cfg-plugin-type: preparseadd",
"ds-cfg-plugin-type: preparsemodify",
"ds-cfg-rename-inbound-attributes: modifyTimeStamp:description",
"ds-cfg-java-class: org.opends.server.plugins.AttributeCleanupPlugin");
/* Create the MODIFY operation as follows:
*
* dn: uid=test,dc=exampple,dc=com
* changetype: modify
* replace: cn
* cn: Test User
* -
* replace: sn
* sn: User
* -
* replace: modifyTimeStamp
* modifyTimeStamp: 2011091212400000Z
*/
"cn",
"Test User"));
"sn",
"User"));
"modifyTimeStamp",
"2011091212400000Z"));
1,
1,
null,
rawMods);
/* Process the MODIFY operation. */
/* Verify that the attribute has been properly renamed by comparing
* the value of the attribute 'description' with the original value
* of the 'modifyTimeStamp' attribute.
*/
{
{
return;
}
"modifyTimeStamp shouldn't exist but it does.");
}
fail();
}
}