@Test
public void testAddPDUExceedingMaxSizeLdapApi() throws Exception
{
// Limit the PDU size to 1024
getLdapServer().getDirectoryService().setMaxPDUSize( 1024 );
LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
connection.bind( "uid=admin,ou=system", "secret" );
// Inject a 1024 bytes long description
StringBuilder sb = new StringBuilder();
for ( int i = 0; i < 128; i++ )
{
sb.append( "0123456789ABCDEF" );
}
Attribute description = new DefaultAttribute( "description", sb.toString() );
try
{
Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, description );
connection.modify( "cn=the person, ou=system", modification );
fail();
}
catch ( Exception e )
{
// We are expecting the session to be close here.
if ( connection.isConnected() )
{
// Race condition:
// Upon NoticeOfDisconnection the API sends an abandon request but does not immediately close the connection.
// So at this point it is not guaranteed that the connnection is already closed.
// TODO: This is just a workaround, better check the connection for any outstanding abandon requests
Thread.sleep( 1000 );
}
assertFalse( connection.isConnected() );
}
}