-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JENKINS-73827] checkin password length at login with AD plugin in FIPS mode #202
Closed
nevingeorgesunny
wants to merge
1
commit into
jenkinsci:master
from
nevingeorgesunny:fips-check-password-lenght-at-login
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/test/java/hudson/plugins/active_directory/docker/FIPSActiveDirectoryLoginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package hudson.plugins.active_directory.docker; | ||
|
||
import java.net.InetAddress; | ||
import java.net.URI; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.acegisecurity.AuthenticationServiceException; | ||
import org.acegisecurity.userdetails.UserDetails; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.htmlunit.FailingHttpStatusCodeException; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
import org.jvnet.hudson.test.FlagRule; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.LoggerRule; | ||
|
||
import hudson.plugins.active_directory.ActiveDirectoryDomain; | ||
import hudson.plugins.active_directory.ActiveDirectoryInternalUsersDatabase; | ||
import hudson.plugins.active_directory.ActiveDirectorySecurityRealm; | ||
import hudson.plugins.active_directory.CacheConfiguration; | ||
import hudson.plugins.active_directory.DNSUtils; | ||
import hudson.plugins.active_directory.GroupLookupStrategy; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.matchers.JUnitMatchers.containsString; | ||
|
||
/** | ||
* Author: Nevin Sunny | ||
* Date: 26/09/24 | ||
* Time: 7:25 pm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed |
||
*/ | ||
public class FIPSActiveDirectoryLoginTest { | ||
|
||
@Rule(order = 0) | ||
public RequireDockerRule rdr = new RequireDockerRule(); | ||
|
||
@Rule(order = 1) | ||
public ActiveDirectoryGenericContainer<?> docker = new ActiveDirectoryGenericContainer<>().withDynamicPorts(); | ||
|
||
@Rule(order = 2) // start Jenkins after the container so that timeouts do not apply to container building. | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Rule | ||
public LoggerRule l = new LoggerRule(); | ||
|
||
@ClassRule | ||
public static TestRule fip140Prop = FlagRule.systemProperty("jenkins.security.FIPS140.COMPLIANCE", "false"); | ||
|
||
private final static String AD_DOMAIN = "samdom.example.com"; | ||
private final static String AD_MANAGER_DN = "CN=Administrator,CN=Users,DC=SAMDOM,DC=EXAMPLE,DC=COM"; | ||
private final static String AD_MANAGER_DN_PASSWORD = "ia4uV1EeKait"; | ||
private final static int MAX_RETRIES = 30; | ||
private String dockerIp; | ||
private int dockerPort; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
String DNS_URLs = new URI("dns", null, InetAddress.getByName(docker.getHost()).getHostAddress(), Integer.parseInt(docker.getDNSPort()), null, null, null).toASCIIString(); | ||
System.setProperty(DNSUtils.OVERRIDE_DNS_PROPERTY, DNS_URLs); | ||
|
||
dockerIp = docker.getHost(); | ||
dockerPort = docker.getMappedPort(3268); | ||
ActiveDirectoryDomain activeDirectoryDomain = new ActiveDirectoryDomain(AD_DOMAIN, | ||
dockerIp + ":" + dockerPort , null, AD_MANAGER_DN, AD_MANAGER_DN_PASSWORD); | ||
List<ActiveDirectoryDomain> domains = new ArrayList<>(1); | ||
domains.add(activeDirectoryDomain); | ||
ActiveDirectorySecurityRealm activeDirectorySecurityRealm = new ActiveDirectorySecurityRealm(null, domains, null, null, null | ||
, null, GroupLookupStrategy.RECURSIVE, false, true, null, false, null, true); | ||
j.getInstance().setSecurityRealm(activeDirectorySecurityRealm); | ||
UserDetails userDetails = null; | ||
int i = 0; | ||
while (i < MAX_RETRIES && userDetails == null) { | ||
try { | ||
userDetails = j.jenkins.getSecurityRealm().loadUserByUsername("Fred"); | ||
} catch (AuthenticationServiceException e) { | ||
Thread.sleep(1000); | ||
} | ||
i ++; | ||
} | ||
} | ||
|
||
@Test(expected = FailingHttpStatusCodeException.class) | ||
public void testLoginFailureWithShortPasswordInFIPSmode() throws Exception { | ||
// Try to login as Fred with a short password | ||
j.createWebClient().login("Fred", "ia4uV1EeKait"); | ||
} | ||
|
||
@Test | ||
public void simpleLoginSuccessful() throws Exception { | ||
JenkinsRule.WebClient wc = j.createWebClient().login("Dino", "p1bfdrMsqyHhbAm"); | ||
MatcherAssert.assertThat(wc.goToXml("whoAmI/api/xml").asXml().replaceAll("\\s+", "") | ||
, Matchers.containsString("<name>Dino</name>")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use package
org.apache.commons.lang