Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisYaoA committed Sep 17, 2024
1 parent 3380f46 commit bd62b15
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,6 +51,9 @@ public class LDAPConfigurationTest {
@Rule
public JenkinsRule r = new JenkinsRule();

@ClassRule
public static FlagRule<String> 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);
Expand Down Expand Up @@ -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<LDAPConfiguration> 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() {

}
}

0 comments on commit bd62b15

Please sign in to comment.