Skip to content
Permalink
Browse files
DIRAPI-370: Preserve user provided attribute name in LDIF reader
  • Loading branch information
seelmann committed Apr 18, 2021
1 parent 275b983 commit e6124efb09e57591b0c613d44833b8c3530218e9
Showing 2 changed files with 42 additions and 2 deletions.
@@ -981,10 +981,11 @@ public void parseAttributeValue( LdifEntry entry, String line, String lowerLine
{
int colonIndex = line.indexOf( ':' );

String attributeType = lowerLine.substring( 0, colonIndex );
String attributeType = line.substring( 0, colonIndex );
String attributeTypeLower = lowerLine.substring( 0, colonIndex );

// We should *not* have a Dn twice
if ( "dn".equals( attributeType ) )
if ( "dn".equals( attributeTypeLower ) )
{
LOG.error( I18n.err( I18n.ERR_13400_ENTRY_WITH_TWO_DNS, lineNumber ) );
throw new LdapLdifException( I18n.err( I18n.ERR_13439_LDIF_ENTRY_WITH_TWO_DNS ) );
@@ -277,6 +277,45 @@ public void testLdifParserEndSpaces() throws Exception
}


@Test
public void testEntryReaderPreservesAttributeCase() throws Exception
{
// content record
String ldif = "version: 1\n" +
"dn: dc=example,dc=com\n" +
"objectClass: top\n";

testEntryReaderPreservesAttributeCase( ldif );

// changetype add
ldif = "version: 1\n" +
"dn: dc=example,dc=com\n" +
"changetype: add\n" +
"objectClass: top\n";

testEntryReaderPreservesAttributeCase( ldif );
}


private void testEntryReaderPreservesAttributeCase( String ldif ) throws Exception
{
LdifReader reader = new LdifReader();

List<LdifEntry> entries = reader.parseLdif( ldif );
assertNotNull( entries );
reader.close();

LdifEntry entry = entries.get( 0 );

assertEquals( "dc=example,dc=com", entry.getDn().getName() );

assertEquals( 1, entry.getEntry().size() );
Attribute attr = entry.getEntry().get( "objectClass" );
assertEquals( "objectclass", attr.getId() );
assertEquals( "objectClass", attr.getUpId() );
}


@Test
public void testLdifParserAddAttrCaseInsensitiveAttrId() throws Exception
{

0 comments on commit e6124ef

Please sign in to comment.