Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
package org.apache.directory.studio.ldapbrowser.common.widgets.entryeditor;


import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.apache.directory.studio.ldapbrowser.core.model.IAttribute;
import org.apache.directory.studio.ldapbrowser.core.model.impl.Attribute;
Expand Down Expand Up @@ -62,47 +61,47 @@ public void setup()
public void testEqual()
{
int result = sorter.compare( null, valueA1, valueA2 );
assertThat( result, equalTo( 0 ) );
assertEquals( 0, result );
}


@Test
public void testLeftIsSmaller()
{
int result = sorter.compare( null, valueA1, valueB );
assertThat( result, equalTo( -1 ) );
assertEquals( -1, result );
}


@Test
public void testRightIsSmaller()
{
int result = sorter.compare( null, valueB, valueA2 );
assertThat( result, equalTo( 1 ) );
assertEquals( 1, result );
}


@Test
public void testLeftIsEmpty()
{
int result = sorter.compare( null, empytValue1, valueA2 );
assertThat( result, equalTo( -1 ) );
assertEquals( -1, result );
}


@Test
public void testRightIsEmpty()
{
int result = sorter.compare( null, valueB, empytValue2 );
assertThat( result, equalTo( 1 ) );
assertEquals( 1, result );
}


@Test
public void testBothAreEmpty()
{
int result = sorter.compare( null, empytValue1, empytValue2 );
assertThat( result, equalTo( 0 ) );
assertEquals( 0, result );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -364,22 +364,22 @@ else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_KEY, false ) >= 0 )
parseTlsKey( chars, pos, syncRepl, parserException );
}

// tls_cacert
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CACERT, false ) >= 0 )
// tls_cacertdir (must be checked before its prefix tls_cacert)
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CACERTDIR, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_CACERT.length();
pos.start += KEYWORD_TLS_CACERTDIR.length();

parseTlsCacert( chars, pos, syncRepl, parserException );
parseTlsCacertDir( chars, pos, syncRepl, parserException );
}

// tls_cacertdir
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CACERTDIR, false ) >= 0 )
// tls_cacert
else if ( Strings.areEquals( chars, pos.start, KEYWORD_TLS_CACERT, false ) >= 0 )
{
foundAtLeastOneProperty = true;
pos.start += KEYWORD_TLS_CACERTDIR.length();
pos.start += KEYWORD_TLS_CACERT.length();

parseTlsCacertDir( chars, pos, syncRepl, parserException );
parseTlsCacert( chars, pos, syncRepl, parserException );
}

// tls_reqcert
Expand Down Expand Up @@ -1054,6 +1054,13 @@ else if ( ( quoteChar == '\'' ) && ( Strings.areEquals( chars, pos.start, "\\'"
pos.start += 2;
continue;
}
// Any other backslash is part of the value: slapd passes it
// through unchanged in cn=config values (strtok_quote_ldif)
else
{
v[current++] = c;
pos.start++;
}
}
// Any other char is part of a value
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Timeout.ThreadMode;


/**
Expand Down Expand Up @@ -724,4 +726,51 @@ public void testSymasDoc3WithSpacesMultilinesAllNotQuoted() throws Exception
assertEquals( "cn=syncuser,dc=example,dc=com", syncRepl.getBindDn() );
assertEquals( "secret", syncRepl.getCredentials() );
}


@Test
@Timeout(value = 5, threadMode = ThreadMode.SEPARATE_THREAD)
public void testQuotedValueKeepsBackslashes() throws Exception
{
// cn=config values are split by slapd's strtok_quote_ldif(), which passes backslashes through unchanged
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "rid=1 tls_cacert=\"C:\\certs\\ca.pem\"" );

assertNotNull( syncRepl );
assertEquals( "C:\\certs\\ca.pem", syncRepl.getTlsCacert() );
}


@Test
@Timeout(value = 5, threadMode = ThreadMode.SEPARATE_THREAD)
public void testFilterAndBindDnWithBackslashSurviveRoundTrip() throws Exception
{
SyncRepl syncRepl = new SyncRepl();
syncRepl.setRid( "1" );
syncRepl.setFilter( "(cn=a\\2ab)" );
syncRepl.setBindDn( "cn=Smith\\, John,dc=example,dc=com" );

String value = syncRepl.toString();

assertTrue( value.contains( "filter=\"(cn=a\\2ab)\"" ), value );
assertTrue( value.contains( "binddn=\"cn=Smith\\, John,dc=example,dc=com\"" ), value );

SyncRepl reparsed = new SyncReplParser().parse( value );

assertNotNull( reparsed );
assertEquals( "(cn=a\\2ab)", reparsed.getFilter() );
assertEquals( "cn=Smith\\, John,dc=example,dc=com", reparsed.getBindDn() );
}


@Test
public void testTlsCacertDir() throws Exception
{
SyncReplParser parser = new SyncReplParser();
SyncRepl syncRepl = parser.parse( "rid=1 tls_cacertdir=/etc/openldap/certs" );

assertNotNull( syncRepl );
assertEquals( "/etc/openldap/certs", syncRepl.getTlsCacertDir() );
assertNull( syncRepl.getTlsCacert() );
}
}
6 changes: 0 additions & 6 deletions plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,6 @@
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<!-- Set versions for dependencies -->
<antlr.version>2.7.7</antlr.version>
<antlr.bundleversion>2.7.7</antlr.bundleversion>
<junit.platform.version>1.10.2</junit.platform.version>
<junit.jupiter.version>5.10.2</junit.jupiter.version>
<log4j.log4j.version>1.2.17</log4j.log4j.version>
<log4j.log4j.bundleversion>1.2.17</log4j.log4j.bundleversion>
Expand Down