diff --git a/src/com/unboundid/ldap/listener/InMemoryDirectoryServer.java b/src/com/unboundid/ldap/listener/InMemoryDirectoryServer.java index 10141b5b9..fb8faba1c 100644 --- a/src/com/unboundid/ldap/listener/InMemoryDirectoryServer.java +++ b/src/com/unboundid/ldap/listener/InMemoryDirectoryServer.java @@ -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()); } @@ -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); } diff --git a/tests/unit/src/com/unboundid/ldap/listener/InMemoryDirectoryServerAddEmptyEntryTestCase.java b/tests/unit/src/com/unboundid/ldap/listener/InMemoryDirectoryServerAddEmptyEntryTestCase.java new file mode 100644 index 000000000..aa40053df --- /dev/null +++ b/tests/unit/src/com/unboundid/ldap/listener/InMemoryDirectoryServerAddEmptyEntryTestCase.java @@ -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 . + */ +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"); + } +}