From bd62b159932a647f4572a0097d93b033eeb22dc9 Mon Sep 17 00:00:00 2001 From: Boris Yao Date: Tue, 17 Sep 2024 17:14:14 +0200 Subject: [PATCH] Add test --- .../plugins/ldap/LDAPConfigurationTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/test/java/jenkins/security/plugins/ldap/LDAPConfigurationTest.java b/src/test/java/jenkins/security/plugins/ldap/LDAPConfigurationTest.java index 484cafe8..49090994 100644 --- a/src/test/java/jenkins/security/plugins/ldap/LDAPConfigurationTest.java +++ b/src/test/java/jenkins/security/plugins/ldap/LDAPConfigurationTest.java @@ -23,9 +23,20 @@ */ package jenkins.security.plugins.ldap; +import hudson.security.LDAPSecurityRealm; +import hudson.util.Secret; +import jenkins.model.IdStrategy; +import jenkins.security.FIPS140; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; +import org.jvnet.hudson.test.FlagRule; import org.jvnet.hudson.test.JenkinsRule; +import org.xml.sax.SAXException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize; @@ -40,6 +51,9 @@ public class LDAPConfigurationTest { @Rule public JenkinsRule r = new JenkinsRule(); + @ClassRule + public static FlagRule fipsFlag = FlagRule.systemProperty(FIPS140.class.getName() + ".COMPLIANCE", "true"); + @Test public void getId() { LDAPConfiguration c = new LDAPConfiguration("ldap.example.com", "dc=example,dc=com", true, null, null); @@ -142,4 +156,34 @@ public void normalizeServerSameButDifferentOrder() { assertThat(n1.split("\\s+"), arrayWithSize(s1.split("\\s+").length)); } + @Test + public void managerPasswordSizeInFipsMode() throws Exception { + final String server = "localhost"; + final String rootDN = "ou=umich,dc=ou.edu"; + final String userSearchBase = "cn=users,ou=umich,ou.edu"; + final String managerDN = "cn=admin,ou=umich,ou.edu"; + final String managerSecret = "secret"; + + LDAPConfiguration c = new LDAPConfiguration(server, rootDN, false, managerDN, Secret.fromString(managerSecret)); + + List configurations = new ArrayList<>(); + configurations.add(c); + LDAPSecurityRealm realm = new LDAPSecurityRealm( + configurations, + false, + null, + IdStrategy.CASE_INSENSITIVE, + IdStrategy.CASE_INSENSITIVE + ); + + r.jenkins.setSecurityRealm(realm); + final JenkinsRule.WebClient client = r.createWebClient(); + r.submit(client.goTo("configureSecurity").getFormByName("config")); + + } + + @Test + public void managerPasswordSizeWithoutFipsMode() { + + } } \ No newline at end of file