From 34bd27bc201143f6f993bccc62c812bef426c6dc Mon Sep 17 00:00:00 2001 From: mlbiam Date: Mon, 9 Mar 2020 10:10:44 -0400 Subject: [PATCH] for #75 --- pom.xml | 17 +- .../test/setrdn/TestSetRDNMutlValueRDN.java | 56 ++ .../TestSetRDNMutlValueRDNNoMapping.java | 532 ++++++++++++++++++ test/TestServer/setrdnmulti.props | 1 + 4 files changed, 603 insertions(+), 3 deletions(-) create mode 100644 src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDNNoMapping.java diff --git a/pom.xml b/pom.xml index fdeddae..376da95 100644 --- a/pom.xml +++ b/pom.xml @@ -28,16 +28,20 @@ tremolosecurity-dependencies - Tremolo Security Inc Custom Repository + https://nexus.tremolo.io/repository/dependencies/ + + + nexus.tremolo.io tremolo.io-releases - https://nexus.tremolo.io/repository/releases/ + s3://tremolosecurity-maven/repository/betas + @@ -241,6 +245,13 @@ + + + com.gkatzioura.maven.cloud + s3-storage-wagon + 2.3 + + maven-compiler-plugin @@ -268,7 +279,7 @@ maven-antrun-plugin - 1.7 + 1.8 package diff --git a/src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDN.java b/src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDN.java index fdfcdb0..5ba59e7 100644 --- a/src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDN.java +++ b/src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDN.java @@ -115,6 +115,62 @@ public void testUidSearch() throws LDAPException { con.disconnect(); } + + @Test + public void testUidSearchWithAttributes() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "Test User")); + attribs.add(new LDAPAttribute("sn", "User")); + attribs.add(new LDAPAttribute("givenName", "Test")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + attribs.add(new LDAPAttribute("uid", "testmultiuser")); + + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("uid=testmultiuser,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("cn=users2,dc=ad,dc=com", 2, "(&(objectclass=inetorgperson)(uid=testmultiuser))", new String[] {"uid","sn"}, false); + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry2; + } else if (size == 1) { + controlEntry = null; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct : " + fromDir.toString()); + return; + } + + size++; + } + + if (size != 1) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + + } @Test public void testOCSearch() throws LDAPException { diff --git a/src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDNNoMapping.java b/src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDNNoMapping.java new file mode 100644 index 0000000..1e1ee1f --- /dev/null +++ b/src/test/java/net/sourceforge/myvd/test/setrdn/TestSetRDNMutlValueRDNNoMapping.java @@ -0,0 +1,532 @@ +/* + * Copyright 2008 Marc Boorshtein + * + * 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. + */ + +package net.sourceforge.myvd.test.setrdn; + +import com.novell.ldap.LDAPAttribute; +import com.novell.ldap.LDAPAttributeSet; +import com.novell.ldap.LDAPConnection; +import com.novell.ldap.LDAPEntry; +import com.novell.ldap.LDAPException; +import com.novell.ldap.LDAPSearchResults; + +import net.sourceforge.myvd.test.util.OpenLDAPUtils; +import net.sourceforge.myvd.test.util.StartMyVD; +import net.sourceforge.myvd.test.util.StartOpenLDAP; +import net.sourceforge.myvd.test.util.Util; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import static org.junit.Assert.*; + +public class TestSetRDNMutlValueRDNNoMapping { + + private static StartOpenLDAP externalServer; + private static StartMyVD server; + private static StartOpenLDAP adServer; + + @BeforeClass + public static void setUp() throws Exception { + OpenLDAPUtils.killAllOpenLDAPS(); + externalServer = new StartOpenLDAP(); + externalServer.startServer(System.getenv("PROJ_DIR") + "/test/ExternalUsers", 12983, + "cn=admin,ou=external,dc=domain,dc=com", "manager"); + + adServer = new StartOpenLDAP(); + adServer.startServer(System.getenv("PROJ_DIR") + "/test/TestAD2", 13983, "cn=admin,dc=test,dc=mydomain,dc=com", + "manager"); + + server = new StartMyVD(); + server.startServer(System.getenv("PROJ_DIR") + "/test/TestServer/setrdnmulti2.props", 50983); + } + + @Test + public void testStartup() { + // do nothing + } + + @Test + public void testsamAccountNameSearch() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "Test User")); + attribs.add(new LDAPAttribute("sn", "User")); + attribs.add(new LDAPAttribute("givenName", "Test")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + attribs.add(new LDAPAttribute("samAccountName", "testmultiuser")); + + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("samAccountName=testmultiuser,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("cn=users2,dc=ad,dc=com", 2, "(samAccountName=testmultiuser)", new String[0], false); + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry2; + } else if (size == 1) { + controlEntry = null; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct : " + fromDir.toString()); + return; + } + + size++; + } + + if (size != 1) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + + } + + @Test + public void testsamAccountNameSearchWithAttributes() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "Test User")); + attribs.add(new LDAPAttribute("sn", "User")); + attribs.add(new LDAPAttribute("givenName", "Test")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + attribs.add(new LDAPAttribute("samAccountName", "testmultiuser")); + + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("samAccountName=testmultiuser,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("cn=users2,dc=ad,dc=com", 2, "(&(objectClass=inetOrgPerson)(samAccountName=testmultiuser))", new String[] {"samAccountName","sn"}, false); + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry2; + } else if (size == 1) { + controlEntry = null; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct : " + fromDir.toString()); + return; + } + + size++; + } + + if (size != 1) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + + } + + @Test + public void testOCSearch() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "Test User")); + attribs.add(new LDAPAttribute("sn", "User")); + attribs.add(new LDAPAttribute("givenName", "Test")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + attribs.add(new LDAPAttribute("samAccountName", "testmultiuser")); + + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("samAccountName=testmultiuser,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("cn=users2,dc=ad,dc=com", 1, "(objectClass=*)", + new String[] { "objectClass", "hasSubordinates" }, false); + + int size = 3; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + + size++; + } + + if (size != 7) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + + } + + @Test + public void testsamAccountNameSearchOnlysamAccountName() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "Test User")); + attribs.add(new LDAPAttribute("sn", "User")); + attribs.add(new LDAPAttribute("givenName", "Test")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + attribs.add(new LDAPAttribute("samAccountName", "testmultiuser")); + + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("samAccountName=testmultiuser,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("cn=users2,dc=ad,dc=com", 2, "(samAccountName=testmultiuser)", new String[] { "samAccountName" }, false); + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry2; + } else if (size == 1) { + controlEntry = null; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct : " + fromDir.toString()); + return; + } + + size++; + } + + if (size != 1) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + + } + + + + @Test + public void testEntry() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "Test User")); + attribs.add(new LDAPAttribute("sn", "User")); + attribs.add(new LDAPAttribute("givenName", "Test")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + attribs.add(new LDAPAttribute("samAccountName", "testmultiuser")); + + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("samAccountName=testmultiuser,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("cn=users2,dc=ad,dc=com", 2, "(cn=Test User)", new String[0], false); + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry2; + } else if (size == 1) { + controlEntry = null; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct : " + fromDir.toString()); + return; + } + + size++; + } + + if (size != 1) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + + } + + @Test + public void testAnonBind() throws LDAPException { + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + con.bind(3, "anonymous", new byte[0]); + } + + @Test + public void testBaseSearch() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "inetOrgPerson")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "Test User")); + attribs.add(new LDAPAttribute("sn", "User")); + attribs.add(new LDAPAttribute("givenName", "Test")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + attribs.add(new LDAPAttribute("samAccountName", "testmultiuser")); + + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("samAccountName=testmultiuser,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("samAccountName=testmultiuser,cn=users2,dc=ad,dc=com", 0, "(objectClass=*)", + new String[0], false); + + /* + * if (results.size() != 3) { fail("incorrect number of result sets : " + * + results.size()); return; } + */ + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry2; + } else if (size == 1) { + controlEntry = null; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct : " + fromDir.toString()); + return; + } + + size++; + } + + if (size != 1) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + } + + @Test + public void testGroupMemberBase() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "groupOfUniqueNames")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "UNIX SUDO Usersx")); + attribs.add(new LDAPAttribute("uniqueMember", "samAccountName=testmultiuser,cn=users2,dc=ad,dc=com")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("cn=UNIX SUDO Usersx,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("cn=UNIX SUDO Usersx,cn=users2,dc=ad,dc=com", 0, "(objectClass=*)", + new String[0], false); + + /* + * if (results.size() != 3) { fail("incorrect number of result sets : " + * + results.size()); return; } + */ + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry2; + } else if (size == 1) { + controlEntry = null; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct : " + fromDir.toString()); + return; + } + + size++; + } + + if (size != 1) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + } + + @Test + public void testGroupMemberFilter() throws LDAPException { + + LDAPAttributeSet attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "groupOfUniqueNames")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "UNIX Usersx")); + LDAPAttribute attr = new LDAPAttribute("uniqueMember", "samAccountName=testmultiuser,cn=users2,dc=ad,dc=com"); + attr.addValue("samAccountName=testmultiuserx,cn=users2,dc=ad,dc=com"); + + attribs.add(attr); + + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry3 = new LDAPEntry("cn=UNIX Usersx,cn=users2,dc=ad,dc=com", attribs); + + attribs = new LDAPAttributeSet(); + attribs.add(new LDAPAttribute("objectClass", "groupOfUniqueNames")); + // attribs.getAttribute("objectClass").addValue("customPerson"); + attribs.add(new LDAPAttribute("cn", "UNIX SUDO Usersx")); + attribs.add(new LDAPAttribute("uniqueMember", "samAccountName=testmultiuser,cn=users2,dc=ad,dc=com")); + // attribs.add(new LDAPAttribute("testAttrib", "testVal")); + + // attribs.add(new LDAPAttribute("globalTestAttrib","globalTestVal")); + LDAPEntry entry2 = new LDAPEntry("cn=UNIX SUDO Usersx,cn=users2,dc=ad,dc=com", attribs); + + LDAPConnection con = new LDAPConnection(); + con.connect("localhost", 50983); + // con.bind(3,"cn=admin,o=mycompany","manager".getBytes()); + LDAPSearchResults res = con.search("dc=ad,dc=com", 2, "(uniqueMember=samAccountName=testmultiuser,cn=users2,dc=ad,dc=com)", + new String[0], false); + + /* + * if (results.size() != 3) { fail("incorrect number of result sets : " + * + results.size()); return; } + */ + + int size = 0; + + while (res.hasMore()) { + LDAPEntry fromDir = res.next(); + LDAPEntry controlEntry = null;// control.get(fromDir.getEntry().getDN()); + + if (size == 0) { + controlEntry = entry3; + } else if (size == 1) { + controlEntry = entry2; + } else { + controlEntry = null; + } + + if (controlEntry == null) { + fail("Entry " + fromDir.getDN() + " should not be returned"); + return; + } + + if (!Util.compareEntry(fromDir, controlEntry)) { + fail("The entry was not correct for " + size + " : " + fromDir.toString() + " / " + controlEntry); + return; + } + + size++; + } + + if (size != 2) { + fail("Not the correct number of entries : " + size); + } + + con.disconnect(); + } + + @AfterClass + public static void tearDown() throws Exception { + + server.stopServer(); + externalServer.stopServer(); + adServer.stopServer(); + } +} diff --git a/test/TestServer/setrdnmulti.props b/test/TestServer/setrdnmulti.props index 02cd9e0..e7c0661 100644 --- a/test/TestServer/setrdnmulti.props +++ b/test/TestServer/setrdnmulti.props @@ -7,6 +7,7 @@ server.nameSpaces=AD server.AD.chain=dump,SetRDN,objmap,membertrans,mapdn,unescape,ldap +#server.AD.chain=dump,SetRDN,unescape,ldap server.AD.nameSpace=dc=ad,dc=com server.AD.wieght=15