Skip to content

Commit

Permalink
[#393] FIX DIT SUP delimiter (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
vharseko authored Sep 12, 2024
1 parent 6f98193 commit 39e4e3e
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* Copyright 2009-2010 Sun Microsystems, Inc.
* Portions copyright 2012-2015 ForgeRock AS.
* Portions Copyright 2024 3A Systems, LLC.
*/

package com.forgerock.opendj.util;
Expand Down Expand Up @@ -141,6 +142,15 @@ public int skipWhitespaces() {
return skipped;
}

public int skipDelims() {
int skipped = 0;
while (pos < length && (source.charAt(pos) == ' ' || source.charAt(pos) == '$')) {
skipped++;
pos++;
}
return skipped;
}

@Override
public String toString() {
return getClass().getSimpleName() + "("
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* Copyright 2009 Sun Microsystems, Inc.
* Portions copyright 2011-2016 ForgeRock AS.
* Portions Copyright 2024 3A Systems, LLC.
*/
package org.forgerock.opendj.ldap.schema;

Expand Down Expand Up @@ -509,10 +510,13 @@ static Set<Integer> readRuleIDs(final SubstringReader reader) throws DecodeExcep
if (c == '(') {
values = new LinkedHashSet<>();
do {
if (!values.isEmpty()) {
reader.reset();
}
values.add(readRuleID(reader));

// Skip over any trailing spaces
reader.skipWhitespaces();
// Skip over any delims spaces
reader.skipDelims();
reader.mark();
} while (reader.read() != ')');
values = Collections.unmodifiableSet(values);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2013-2016 ForgeRock AS.
* Portions Copyright 2024 3A Systems, LLC.
*/
package org.opends.server.backends;

Expand Down Expand Up @@ -3430,6 +3431,93 @@ public void testAddDITStructureRuleSuccessful() throws Exception
}
}

@Test
public void testAddDITStructureRuleSupSuccessful() throws Exception
{
String ldif = toLdif(
"dn: cn=schema",
"changetype: modify",
"add: nameForms",
"nameForms: ( 1.3.6.1.4.1.56521.999.8.1.7 NAME 'commonNameForm' DESC 'Name Form for a commonName orgRole structure' OC organizationalRole MUST cn )",
"-",
"add: ditStructureRules",
"dITStructureRules: ( 150 NAME 'commonNameStructureRule' FORM commonNameForm )",
"dITStructureRules: ( 151 NAME 'commonNameStructureRule2' FORM commonNameForm )",
"dITStructureRules: ( 152 NAME 'commonNameStructureRule3' FORM commonNameForm SUP ( 150 $ 151 ) )"

);

int ruleID = 152;
assertSchemaHasDITStructureRule(ruleID, false);

try
{
runModify(argsNotPermissive(), ldif, System.err, SUCCESS);
assertSchemaHasDITStructureRule(ruleID, true);
}
finally
{
// delete in reverse order
String ldif2 = toLdif(
"dn: cn=schema",
"changetype: modify",
"delete: ditStructureRules",
"dITStructureRules: ( 152 NAME 'commonNameStructureRule3' FORM commonNameForm SUP ( 150 151 ) )",
"dITStructureRules: ( 150 NAME 'commonNameStructureRule' FORM commonNameForm )",
"dITStructureRules: ( 151 NAME 'commonNameStructureRule2' FORM commonNameForm )",
"-",
"delete: nameForms",
"nameForms: ( 1.3.6.1.4.1.56521.999.8.1.7 NAME 'commonNameForm' DESC 'Name Form for a commonName orgRole structure' OC organizationalRole MUST cn )"
);
runModify(argsNotPermissive(), ldif2, System.err, SUCCESS);
assertSchemaHasDITStructureRule(ruleID, false);
}
}

@Test
public void testAddDITStructureRuleSupSuccessful2() throws Exception
{
String ldif = toLdif(
"dn: cn=schema",
"changetype: modify",
"add: nameForms",
"nameForms: ( 1.3.6.1.4.1.56521.999.8.1.7 NAME 'commonNameForm' DESC 'Name Form for a commonName orgRole structure' OC organizationalRole MUST cn )",
"-",
"add: ditStructureRules",
"dITStructureRules: ( 150 NAME 'commonNameStructureRule' FORM commonNameForm )",
"dITStructureRules: ( 151 NAME 'commonNameStructureRule2' FORM commonNameForm )",
"dITStructureRules: ( 152 NAME 'commonNameStructureRule3' FORM commonNameForm )",
"dITStructureRules: ( 153 NAME 'commonNameStructureRule4' FORM commonNameForm SUP ( 150 151 152 ) )"

);

int ruleID = 153;
assertSchemaHasDITStructureRule(ruleID, false);

try
{
runModify(argsNotPermissive(), ldif, System.err, SUCCESS);
assertSchemaHasDITStructureRule(ruleID, true);
}
finally
{
// delete in reverse order
String ldif2 = toLdif(
"dn: cn=schema",
"changetype: modify",
"delete: ditStructureRules",
"dITStructureRules: ( 153 NAME 'commonNameStructureRule4' FORM commonNameForm SUP ( 150 $ 151 $ 152 ) )",
"dITStructureRules: ( 150 NAME 'commonNameStructureRule' FORM commonNameForm )",
"dITStructureRules: ( 151 NAME 'commonNameStructureRule2' FORM commonNameForm )",
"dITStructureRules: ( 152 NAME 'commonNameStructureRule3' FORM commonNameForm )",
"-",
"delete: nameForms",
"nameForms: ( 1.3.6.1.4.1.56521.999.8.1.7 NAME 'commonNameForm' DESC 'Name Form for a commonName orgRole structure' OC organizationalRole MUST cn )"
);
runModify(argsNotPermissive(), ldif2, System.err, SUCCESS);
assertSchemaHasDITStructureRule(ruleID, false);
}
}
private void assertSchemaHasDITStructureRule(int ruleID, boolean expected)
{
boolean hasDITStructureRule = getSchema().hasDITStructureRule(ruleID);
Expand Down

0 comments on commit 39e4e3e

Please sign in to comment.