[tomcat] 01/10: Start to expand JNDIRealm unit tests
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git commit a1d06d540e74ee9a7eda27d97da33bc92ed2cbf4 Author: Mark Thomas AuthorDate: Tue Apr 13 10:13:12 2021 +0100 Start to expand JNDIRealm unit tests --- build.properties.default | 9 ++ build.xml | 9 ++ .../catalina/realm/TestJNDIRealmIntegration.java | 144 + webapps/docs/changelog.xml | 8 ++ 4 files changed, 170 insertions(+) diff --git a/build.properties.default b/build.properties.default index 922064c..616ef3d 100644 --- a/build.properties.default +++ b/build.properties.default @@ -254,6 +254,15 @@ objenesis.home=${base.path}/objenesis-${objenesis.version} objenesis.jar=${objenesis.home}/objenesis-${objenesis.version}.jar objenesis.loc=${base-maven.loc}/org/objenesis/objenesis/${objenesis.version}/objenesis-${objenesis.version}.jar +# - UnboundID, used by unit tests, version 5.1.4 or later - +unboundid.version=5.1.4 +unboundid.checksum.enabled=true +unboundid.checksum.algorithm=SHA-512 +unboundid.checksum.value=04cf7f59eddebdd5b51e5be55021f9d9c667cca6101eac954e7a8d5b51f4c23372cd8f041640157f082435a166b75d85e79252b516130ede7d966dae6d3eae67 +unboundid.home=${base.path}/unboundid-${unboundid.version} +unboundid.jar=${unboundid.home}/unboundid-ldapsdk-${unboundid.version}.jar +unboundid.loc=${base-maven.loc}/com/unboundid/unboundid-ldapsdk/${unboundid.version}/unboundid-ldapsdk-${unboundid.version}.jar + # - Checkstyle, version 6.16 or later - # Checkstyle 7 requires Java 8 # Therefore, use checkstyle-backport-jre6 diff --git a/build.xml b/build.xml index 3368c10..fffa5c1 100644 --- a/build.xml +++ b/build.xml @@ -2905,6 +2905,15 @@ skip.installer property in build.properties" /> + + + + + + + + + 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.catalina.realm; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; + +import org.apache.juli.logging.LogFactory; + +import com.unboundid.ldap.listener.InMemoryDirectoryServer; +import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; +import com.unboundid.ldap.sdk.AddRequest; +import com.unboundid.ldap.sdk.LDAPConnection; +import com.unboundid.ldap.sdk.LDAPResult; +import com.unboundid.ldap.sdk.ResultCode; + +@RunWith(Parameterized.class) +public class TestJNDIRealmIntegration { + +private static InMemoryDirectoryServer ldapServer; + +@Parameterized.Parameters(name = "{index}: in[{0}], out[{1}]") +public static Collection parameters() { +List parameterSets = new ArrayList<>(); + +parameterSets.add(new Object[] { "test", "test", new String[] {"TestGroup"} }); + +return parameterSets; +} + + +@Parameter(0) +public String username; +@Parameter(1) +public String credentials; +@Parameter(2) +public String[] groups; + +@Test +public void testAuthenication() throws Exception { +JNDIRealm realm = new JNDIRealm(); +realm.containerLog = LogFactory.getLog(TestJNDIRealmIntegration.class); + +realm.setConnectionURL("ldap://localhost:"; + ldapServer.getListenPort()); +realm.setUserPattern("cn={0},ou=people,dc=example,dc=com"); +realm.setRoleName("cn"); +realm.setRoleBase("ou=people,dc=example,dc=com"); +realm.setRoleSearch("member={0}"); + +GenericPrincipal p = (GenericPrincipal) realm.authenticate(username, credentials); + +Assert.assertNotNull(p); +Assert.assertEquals(username, p.name); + +Set actualGroups = new HashSet<>(Arrays.asList(p.getRoles())); +Set expectedGroups = new HashSet<>(Arrays.asList(groups)); + +Assert.assertEquals(expectedGroups.size(), actualGroups.size()); +Set tmp = new HashSet<>(); +tmp.addAll(expectedGroups); +tmp.removeAll(actualGroups); +Assert.assertEquals(0, tmp.size()); +} + + +@BeforeClass +public static void createLDAP() throws Exception { +InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com"); +
[tomcat] 01/10: Start to expand JNDIRealm unit tests
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git commit 2a13dd88639e92a04543585f2a9d9542e0d89f2c Author: Mark Thomas AuthorDate: Tue Apr 13 10:13:12 2021 +0100 Start to expand JNDIRealm unit tests --- build.properties.default | 9 ++ build.xml | 9 ++ .../catalina/realm/TestJNDIRealmIntegration.java | 144 + webapps/docs/changelog.xml | 4 + 4 files changed, 166 insertions(+) diff --git a/build.properties.default b/build.properties.default index 94b5663..77622d8 100644 --- a/build.properties.default +++ b/build.properties.default @@ -250,6 +250,15 @@ objenesis.home=${base.path}/objenesis-${objenesis.version} objenesis.jar=${objenesis.home}/objenesis-${objenesis.version}.jar objenesis.loc=${base-maven.loc}/org/objenesis/objenesis/${objenesis.version}/objenesis-${objenesis.version}.jar +# - UnboundID, used by unit tests, version 5.1.4 or later - +unboundid.version=5.1.4 +unboundid.checksum.enabled=true +unboundid.checksum.algorithm=SHA-512 +unboundid.checksum.value=04cf7f59eddebdd5b51e5be55021f9d9c667cca6101eac954e7a8d5b51f4c23372cd8f041640157f082435a166b75d85e79252b516130ede7d966dae6d3eae67 +unboundid.home=${base.path}/unboundid-${unboundid.version} +unboundid.jar=${unboundid.home}/unboundid-ldapsdk-${unboundid.version}.jar +unboundid.loc=${base-maven.loc}/com/unboundid/unboundid-ldapsdk/${unboundid.version}/unboundid-ldapsdk-${unboundid.version}.jar + # - Checkstyle, version 6.16 or later - checkstyle.version=8.22 checkstyle.checksum.enabled=true diff --git a/build.xml b/build.xml index 15d27fb..b186186 100644 --- a/build.xml +++ b/build.xml @@ -3243,6 +3243,15 @@ skip.installer property in build.properties" /> + + + + + + + + + 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.catalina.realm; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; + +import org.apache.juli.logging.LogFactory; + +import com.unboundid.ldap.listener.InMemoryDirectoryServer; +import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; +import com.unboundid.ldap.sdk.AddRequest; +import com.unboundid.ldap.sdk.LDAPConnection; +import com.unboundid.ldap.sdk.LDAPResult; +import com.unboundid.ldap.sdk.ResultCode; + +@RunWith(Parameterized.class) +public class TestJNDIRealmIntegration { + +private static InMemoryDirectoryServer ldapServer; + +@Parameterized.Parameters(name = "{index}: in[{0}], out[{1}]") +public static Collection parameters() { +List parameterSets = new ArrayList<>(); + +parameterSets.add(new Object[] { "test", "test", new String[] {"TestGroup"} }); + +return parameterSets; +} + + +@Parameter(0) +public String username; +@Parameter(1) +public String credentials; +@Parameter(2) +public String[] groups; + +@Test +public void testAuthenication() throws Exception { +JNDIRealm realm = new JNDIRealm(); +realm.containerLog = LogFactory.getLog(TestJNDIRealmIntegration.class); + +realm.setConnectionURL("ldap://localhost:"; + ldapServer.getListenPort()); +realm.setUserPattern("cn={0},ou=people,dc=example,dc=com"); +realm.setRoleName("cn"); +realm.setRoleBase("ou=people,dc=example,dc=com"); +realm.setRoleSearch("member={0}"); + +GenericPrincipal p = (GenericPrincipal) realm.authenticate(username, credentials); + +Assert.assertNotNull(p); +Assert.assertEquals(username, p.name); + +Set actualGroups = new HashSet<>(Arrays.asList(p.getRoles())); +Set expectedGroups = new HashSet<>(Arrays.asList(groups)); + +Assert.assertEquals(expectedGroups.size(), actualGroups.size()); +Set tmp = new HashSet<>(); +tmp.addAll(expectedGroups); +tmp.removeAll(actualGroups); +Assert.assertEquals(0, tmp.size()); +} + + +@BeforeClass +public static void createLDAP() throws Exception { +InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com"); +config.addAdditio
[tomcat] 01/10: Start to expand JNDIRealm unit tests
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git commit fa4d19c0c6ea28eae41c29ed5b16a2ccbd7e9ba1 Author: Mark Thomas AuthorDate: Tue Apr 13 10:13:12 2021 +0100 Start to expand JNDIRealm unit tests --- build.properties.default | 9 ++ build.xml | 9 ++ .../catalina/realm/TestJNDIRealmIntegration.java | 144 + webapps/docs/changelog.xml | 8 ++ 4 files changed, 170 insertions(+) diff --git a/build.properties.default b/build.properties.default index fd8d153..2c3323a 100644 --- a/build.properties.default +++ b/build.properties.default @@ -250,6 +250,15 @@ objenesis.home=${base.path}/objenesis-${objenesis.version} objenesis.jar=${objenesis.home}/objenesis-${objenesis.version}.jar objenesis.loc=${base-maven.loc}/org/objenesis/objenesis/${objenesis.version}/objenesis-${objenesis.version}.jar +# - UnboundID, used by unit tests, version 5.1.4 or later - +unboundid.version=5.1.4 +unboundid.checksum.enabled=true +unboundid.checksum.algorithm=SHA-512 +unboundid.checksum.value=04cf7f59eddebdd5b51e5be55021f9d9c667cca6101eac954e7a8d5b51f4c23372cd8f041640157f082435a166b75d85e79252b516130ede7d966dae6d3eae67 +unboundid.home=${base.path}/unboundid-${unboundid.version} +unboundid.jar=${unboundid.home}/unboundid-ldapsdk-${unboundid.version}.jar +unboundid.loc=${base-maven.loc}/com/unboundid/unboundid-ldapsdk/${unboundid.version}/unboundid-ldapsdk-${unboundid.version}.jar + # - Checkstyle, version 6.16 or later - checkstyle.version=8.22 checkstyle.checksum.enabled=true diff --git a/build.xml b/build.xml index 38aeaf2..835cc36 100644 --- a/build.xml +++ b/build.xml @@ -3271,6 +3271,15 @@ skip.installer property in build.properties" /> + + + + + + + + + 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.catalina.realm; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; + +import org.apache.juli.logging.LogFactory; + +import com.unboundid.ldap.listener.InMemoryDirectoryServer; +import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig; +import com.unboundid.ldap.sdk.AddRequest; +import com.unboundid.ldap.sdk.LDAPConnection; +import com.unboundid.ldap.sdk.LDAPResult; +import com.unboundid.ldap.sdk.ResultCode; + +@RunWith(Parameterized.class) +public class TestJNDIRealmIntegration { + +private static InMemoryDirectoryServer ldapServer; + +@Parameterized.Parameters(name = "{index}: in[{0}], out[{1}]") +public static Collection parameters() { +List parameterSets = new ArrayList<>(); + +parameterSets.add(new Object[] { "test", "test", new String[] {"TestGroup"} }); + +return parameterSets; +} + + +@Parameter(0) +public String username; +@Parameter(1) +public String credentials; +@Parameter(2) +public String[] groups; + +@Test +public void testAuthenication() throws Exception { +JNDIRealm realm = new JNDIRealm(); +realm.containerLog = LogFactory.getLog(TestJNDIRealmIntegration.class); + +realm.setConnectionURL("ldap://localhost:"; + ldapServer.getListenPort()); +realm.setUserPattern("cn={0},ou=people,dc=example,dc=com"); +realm.setRoleName("cn"); +realm.setRoleBase("ou=people,dc=example,dc=com"); +realm.setRoleSearch("member={0}"); + +GenericPrincipal p = (GenericPrincipal) realm.authenticate(username, credentials); + +Assert.assertNotNull(p); +Assert.assertEquals(username, p.name); + +Set actualGroups = new HashSet<>(Arrays.asList(p.getRoles())); +Set expectedGroups = new HashSet<>(Arrays.asList(groups)); + +Assert.assertEquals(expectedGroups.size(), actualGroups.size()); +Set tmp = new HashSet<>(); +tmp.addAll(expectedGroups); +tmp.removeAll(actualGroups); +Assert.assertEquals(0, tmp.size()); +} + + +@BeforeClass +public static void createLDAP() throws Exception { +InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig("dc=example,dc=com"); +config.addAddit