Skip to content

Commit

Permalink
Use a better filter for IMDS.getEntry
Browse files Browse the repository at this point in the history
Updated InMemoryDirectoryServer.getEntry to use a filter of "(&)"
instead of "(objectClass=*)" when searching for the specified entry.
This should be logically equivalent in the vast majority of cases,
but there may be a difference in a corner case in which the server
is configured without schema and you add an entry without the
objectClass attribute.
  • Loading branch information
dirmgr committed May 9, 2023
1 parent 55b7740 commit effd5ea
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/com/unboundid/ldap/listener/InMemoryDirectoryServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1579,8 +1579,7 @@ public Schema getSchema(@Nullable final String entryDN)
public SearchResultEntry getEntry(@NotNull final String dn)
throws LDAPException
{
return searchForEntry(dn, SearchScope.BASE,
Filter.createPresenceFilter("objectClass"));
return searchForEntry(dn, SearchScope.BASE, Filter.createANDFilter());
}


Expand All @@ -1598,8 +1597,8 @@ public SearchResultEntry getEntry(@NotNull final String dn,
@Nullable final String... attributes)
throws LDAPException
{
return searchForEntry(dn, SearchScope.BASE,
Filter.createPresenceFilter("objectClass"), attributes);
return searchForEntry(dn, SearchScope.BASE, Filter.createANDFilter(),
attributes);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2023 Ping Identity Corporation
* All Rights Reserved.
*/
/*
* Copyright 2023 Ping Identity Corporation
*
* Licensed 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.
*/
/*
* Copyright (C) 2023 Ping Identity Corporation
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPLv2 only)
* or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses>.
*/
package com.unboundid.ldap.listener;



import org.testng.annotations.Test;

import com.unboundid.ldap.sdk.Entry;
import com.unboundid.ldap.sdk.LDAPResult;
import com.unboundid.ldap.sdk.LDAPSDKTestCase;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.ldap.sdk.SearchResultEntry;



/**
* This class provides a test that examines the behavior of the in-memory
* directory server when an entry with no attributes is added and then
* retrieved.
*/
public final class InMemoryDirectoryServerAddEmptyEntryTestCase
extends LDAPSDKTestCase
{
/**
* Tests the behavior when trying to add and retrieve an empty entry.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testAddAndRetrieveEmptyEntry()
throws Exception
{
// Create an in-memory directory server instance without any schema.
final InMemoryDirectoryServerConfig cfg =
new InMemoryDirectoryServerConfig("dc=example,dc=com");
cfg.setSchema(null);

final InMemoryDirectoryServer ds = new InMemoryDirectoryServer(cfg);


// Try to add an empty "dc=example,dc=com" entry.
final Entry emptyEntry = new Entry("dc=example,dc=com");
final LDAPResult addResult = ds.add(emptyEntry);
assertResultCodeEquals(addResult, ResultCode.SUCCESS);

final SearchResultEntry searchEntry = ds.getEntry("dc=example,dc=com");
assertNotNull(searchEntry);
assertDNsEqual(searchEntry.getDN(), "dc=example,dc=com");
}
}

0 comments on commit effd5ea

Please sign in to comment.