You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Stefan Seelmann <ma...@stefan-seelmann.de> on 2018/05/20 21:22:57 UTC
Re: [directory-ldap-api] branch master updated: Fix value equals.
Don't normalize already normalized value which fails e.g. for DN
Hi Emmanuel,
please review this change.
There was a failing test in Studio, it was not possible to delete a
complex DN in member attribute because the server respondes withe "non
existing value".
The problem was in the Value.equals() method, where an already
normalized value was normalized a 2nd time. For complex DNs this 2nd
normalizing fails. I added a test ModifyMemberIT to demonstrate the problem.
Kind Regards,
Stefan
On 05/20/2018 10:51 PM, seelmann@apache.org wrote:
> This is an automated email from the ASF dual-hosted git repository.
>
> seelmann pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git
>
>
> The following commit(s) were added to refs/heads/master by this push:
> new 1b54c95 Fix value equals. Don't normalize already normalized value which fails e.g. for DN
> 1b54c95 is described below
>
> commit 1b54c95aa4bf59099205e8fac1dfc2fce543209a
> Author: Stefan Seelmann <ma...@stefan-seelmann.de>
> AuthorDate: Sun May 20 22:51:41 2018 +0200
>
> Fix value equals. Don't normalize already normalized value which fails e.g. for DN
> ---
> .../directory/api/ldap/model/entry/Value.java | 19 +----
> .../api/ldap/model/entry/DnValueTest.java | 87 ++++++++++++++++++++++
> 2 files changed, 89 insertions(+), 17 deletions(-)
>
> diff --git a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java
> index 0e731a2..ecf46cb 100644
> --- a/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java
> +++ b/ldap/model/src/main/java/org/apache/directory/api/ldap/model/entry/Value.java
> @@ -1382,30 +1382,15 @@ public class Value implements Cloneable, Externalizable, Comparable<Value>
> return stringComparator.compare( normValue, other.normValue ) == 0;
> }
>
> - Normalizer normalizer = other.attributeType.getEquality().getNormalizer();
> -
> - if ( normalizer == null )
> - {
> - if ( comparator == null )
> - {
> - return normValue.equals( other.normValue );
> - }
> - else
> - {
> - return comparator.compare( normValue, other.normValue ) == 0;
> - }
> - }
>
> - String thisNormValue = normalizer.normalize( normValue );
> -
> // Compare normalized values
> if ( comparator == null )
> {
> - return thisNormValue.equals( other.normValue );
> + return normValue.equals( other.normValue );
> }
> else
> {
> - return comparator.compare( thisNormValue, other.normValue ) == 0;
> + return comparator.compare( normValue, other.normValue ) == 0;
> }
> }
> catch ( LdapException ne )
> diff --git a/ldap/model/src/test/java/org/apache/directory/api/ldap/model/entry/DnValueTest.java b/ldap/model/src/test/java/org/apache/directory/api/ldap/model/entry/DnValueTest.java
> new file mode 100644
> index 0000000..031aaea
> --- /dev/null
> +++ b/ldap/model/src/test/java/org/apache/directory/api/ldap/model/entry/DnValueTest.java
> @@ -0,0 +1,87 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.directory.api.ldap.model.entry;
> +
> +
> +import static org.junit.Assert.assertEquals;
> +
> +import org.apache.directory.api.ldap.model.exception.LdapException;
> +import org.apache.directory.api.ldap.model.schema.comparators.DnComparator;
> +import org.apache.directory.api.ldap.model.schema.normalizers.DnNormalizer;
> +import org.apache.directory.api.ldap.model.schema.syntaxCheckers.DnSyntaxChecker;
> +import org.junit.BeforeClass;
> +import org.junit.Test;
> +import org.junit.runner.RunWith;
> +
> +import com.mycila.junit.concurrent.Concurrency;
> +import com.mycila.junit.concurrent.ConcurrentJunitRunner;
> +
> +
> +/**
> + * Test the Value class with Dn values
> + *
> + * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
> + */
> +@RunWith(ConcurrentJunitRunner.class)
> +@Concurrency()
> +public class DnValueTest
> +{
> + private static EntryUtils.S s;
> + private static EntryUtils.AT at;
> + private static EntryUtils.MR mr;
> +
> +
> + /**
> + * Initialize an AttributeType and the associated MatchingRule
> + * and Syntax
> + */
> + @BeforeClass
> + public static void initAT()
> + {
> + s = new EntryUtils.S( "1.1.1.1", true );
> + s.setSyntaxChecker( DnSyntaxChecker.INSTANCE );
> + mr = new EntryUtils.MR( "1.1.2.1" );
> + mr.setSyntax( s );
> + mr.setLdapComparator( new DnComparator( "1.1.2.1" ) );
> + mr.setNormalizer( new DnNormalizer() );
> + at = new EntryUtils.AT( "1.1.3.1" );
> + at.setEquality( mr );
> + at.setOrdering( mr );
> + at.setSubstring( mr );
> + at.setSyntax( s );
> + }
> +
> +
> + @Test
> + public void testEqualsSimpleDn() throws LdapException
> + {
> + Value sv1 = new Value( at, "cn=user2,ou=system" );
> + Value sv2 = new Value( at, " cn = user2 , ou = system " );
> + assertEquals( sv1, sv2 );
> + }
> +
> +
> + @Test
> + public void testEqualsComplexDn() throws LdapException
> + {
> + Value sv1 = new Value( at, "cn=\\#\\\\\\+\\, \\\"\u00F6\u00E9\\\",ou=system" );
> + Value sv2 = new Value( at, " cn = \\#\\\\\\+\\, \\\"\u00F6\u00E9\\\" , ou = system " );
> + assertEquals( sv1, sv2 );
> + }
> +}
>
Re: [directory-ldap-api] branch master updated: Fix value equals.
Don't normalize already normalized value which fails e.g. for DN
Posted by Emmanuel Lécharny <el...@gmail.com>.
Le 20/05/2018 à 23:22, Stefan Seelmann a écrit :
> Hi Emmanuel,
Hi Stefan,
>
> please review this change.
>
> There was a failing test in Studio, it was not possible to delete a
> complex DN in member attribute because the server respondes withe "non
> existing value".
>
> The problem was in the Value.equals() method, where an already
> normalized value was normalized a 2nd time. For complex DNs this 2nd
> normalizing fails. I added a test ModifyMemberIT to demonstrate the problem.
Your change makes totally sense : a Value is always already normalized
as soon as it has an AttributeType.
--
Emmanuel Lecharny
Symas.com
directory.apache.org