-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding integration test for ActiveDirectoryDomain
- Loading branch information
1 parent
4862027
commit d0e482f
Showing
8 changed files
with
362 additions
and
2 deletions.
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
src/test/java/hudson/plugins/active_directory/ActiveDirectoryDomainIntegrationTest.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,159 @@ | ||
package hudson.plugins.active_directory; | ||
|
||
import org.htmlunit.FailingHttpStatusCodeException; | ||
import org.htmlunit.html.HtmlButton; | ||
import org.htmlunit.html.HtmlElement; | ||
import org.htmlunit.html.HtmlForm; | ||
import org.htmlunit.html.HtmlInput; | ||
import org.htmlunit.html.HtmlPage; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.jvnet.hudson.test.FlagRule; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class ActiveDirectoryDomainIntegrationTest { | ||
@Rule | ||
public JenkinsRule jenkins = new JenkinsRule(); | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@ClassRule | ||
public static FlagRule<String> fipsSystemPropertyRule = | ||
FlagRule.systemProperty("jenkins.security.FIPS140.COMPLIANCE", "true"); | ||
|
||
|
||
/** | ||
* Tests the behavior of the "Test Domain" button when a short password is configured. | ||
* | ||
* <p>For the preconfigured value, the password is "small" in the local data. | ||
* When the "Test Domain" button is clicked, the page should display an error message | ||
* indicating that the password is too short, along with an "angry Jenkins" error message.</p> | ||
* | ||
*/ | ||
@LocalData | ||
@Test | ||
public void testActiveDirectoryDomainTestDomainButtonClickWithShortPassword() throws Exception { | ||
JenkinsRule.WebClient webClient = jenkins.createWebClient(); | ||
// Navigate to the configuration page | ||
HtmlPage configPage = webClient.goTo("configureSecurity"); | ||
HtmlForm form = configPage.getFormByName("config"); | ||
|
||
//Check that the password is too short message is present | ||
assertTrue(form.asNormalizedText().contains(Messages.passwordTooShortFIPS())); | ||
|
||
// Click the "Test Domain" button | ||
HtmlPage resultPage = getButtonByText(form, "Test Domain").click(); | ||
|
||
webClient.waitForBackgroundJavaScript(2000); // Wait for up to 5 seconds | ||
|
||
String responseContent = resultPage.asNormalizedText(); | ||
// Assert that the error message is present in the page content | ||
assertTrue(responseContent.contains("A problem occurred while processing the request")); | ||
|
||
//Check that the password is too short message is present | ||
assertTrue(responseContent.contains(Messages.passwordTooShortFIPS())); | ||
} | ||
|
||
/** | ||
* Tests the behavior of the "Save" button when a short password is configured. | ||
* | ||
* <p>For the preconfigured value, the password is "small" in the local data. | ||
* When the "Save" button is clicked, an exception is expected because the password | ||
* does not meet the minimum length requirement.</p> | ||
* | ||
*/ | ||
@LocalData | ||
@Test | ||
public void testActiveDirectoryDomainSaveButtonClick() throws Exception { | ||
JenkinsRule.WebClient webClient = jenkins.createWebClient(); | ||
// Navigate to the configuration page | ||
HtmlPage configPage = webClient.goTo("configureSecurity"); | ||
HtmlForm form = configPage.getFormByName("config"); | ||
|
||
//Check that the password is too short message is present | ||
assertTrue(form.asNormalizedText().contains(Messages.passwordTooShortFIPS())); | ||
|
||
// Expect FailingHttpStatusCodeException | ||
thrown.expect(FailingHttpStatusCodeException.class); | ||
|
||
// Find the "Submit" button and click it | ||
getButtonByText(form, "Save").click(); | ||
} | ||
|
||
/** | ||
* Tests the behavior of the "Save" button when a short password is configured. | ||
* | ||
* <p>For the preconfigured value, the password is "small" in the local data. | ||
* When the "Apply" button is clicked, an exception is expected because the password | ||
* does not meet the minimum length requirement.</p> | ||
* | ||
*/ | ||
@LocalData | ||
@Test | ||
public void testActiveDirectoryDomainApplyButtonClick() throws Exception { | ||
JenkinsRule.WebClient webClient = jenkins.createWebClient(); | ||
// Navigate to the configuration page | ||
HtmlPage configPage = webClient.goTo("configureSecurity"); | ||
HtmlForm form = configPage.getFormByName("config"); | ||
|
||
//Check that the password is too short message is present | ||
assertTrue(form.asNormalizedText().contains(Messages.passwordTooShortFIPS())); | ||
|
||
// Expect FailingHttpStatusCodeException | ||
thrown.expect(FailingHttpStatusCodeException.class); | ||
|
||
// Find the "Apply" button and click it | ||
getButtonByText(form, "Apply").click(); | ||
} | ||
|
||
/** | ||
* Tests the behavior of the "Apply" button when a valid password is initially configured. then updated to a | ||
* short password | ||
* | ||
* <p>For the preconfigured value, the password is "samell" in the local data. | ||
* When the "Apply" button is clicked, an exception is expected because the password | ||
* does not meet the minimum length requirement.</p> | ||
* | ||
*/ | ||
@LocalData | ||
@Test | ||
public void testActiveDirectoryDomainSettingShortPassword() throws Exception { | ||
JenkinsRule.WebClient webClient = jenkins.createWebClient(); | ||
// Navigate to the configuration page | ||
HtmlPage configPage = webClient.goTo("configureSecurity"); | ||
HtmlForm form = configPage.getFormByName("config"); | ||
|
||
//Since password is valid is should not contain password too short message | ||
assertFalse(form.asNormalizedText().contains(Messages.passwordTooShortFIPS())); | ||
//Since password is valid, it should not throw exception oon clicking apply | ||
assertEquals(200, getButtonByText(form, "Apply").click().getWebResponse().getStatusCode()); | ||
|
||
// Find the binf password filed and set an invalid password | ||
HtmlInput bindPasswordField = form.getInputByName("_.bindPassword"); | ||
bindPasswordField.setValueAttribute("small"); // Replace with your password value | ||
|
||
// Expect FailingHttpStatusCodeException | ||
thrown.expect(FailingHttpStatusCodeException.class); | ||
|
||
// Find the "Submit" button and click it | ||
getButtonByText(form, "Apply").click(); | ||
} | ||
|
||
private HtmlButton getButtonByText(HtmlForm form, String text) throws Exception { | ||
for (HtmlElement e : form.getElementsByTagName("button")) { | ||
if (e.getTextContent().contains(text)) { | ||
return ((HtmlButton) e); | ||
} | ||
} | ||
throw new AssertionError(String.format("Button [%s] not found", text)); | ||
} | ||
|
||
} |
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
50 changes: 50 additions & 0 deletions
50
...ActiveDirectoryDomainIntegrationTest/testActiveDirectoryDomainApplyButtonClick/config.xml
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,50 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.0</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<useSecurity>true</useSecurity> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.plugins.active_directory.ActiveDirectorySecurityRealm" plugin="[email protected]"> | ||
<domains> | ||
<hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
<name>samdom.example.com</name> | ||
<bindName>CN=Administrator,CN=Users,DC=samdom,DC=example,DC=com</bindName> | ||
<bindPassword>small</bindPassword> | ||
<tlsConfiguration>TRUST_ALL_CERTIFICATES</tlsConfiguration> | ||
<internalUsersDatabase>admin</internalUsersDatabase> | ||
</hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
</domains> | ||
<startTls>true</startTls> | ||
<groupLookupStrategy>RECURSIVE</groupLookupStrategy> | ||
<removeIrrelevantGroups>false</removeIrrelevantGroups> | ||
<internalUsersDatabase> | ||
<jenkinsInternalUser>admin</jenkinsInternalUser> | ||
</internalUsersDatabase> | ||
</securityRealm> | ||
<disableRememberMe>false</disableRememberMe> | ||
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/> | ||
<workspaceDir>${ITEM_ROOTDIR}/workspace</workspaceDir> | ||
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir> | ||
<markupFormatter class="hudson.markup.EscapedMarkupFormatter"/> | ||
<jdks/> | ||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/> | ||
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/> | ||
<clouds/> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
<filterExecutors>false</filterExecutors> | ||
<filterQueue>false</filterQueue> | ||
<properties class="hudson.model.View$PropertyList"/> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>-1</slaveAgentPort> | ||
<label></label> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
</hudson> |
50 changes: 50 additions & 0 deletions
50
.../ActiveDirectoryDomainIntegrationTest/testActiveDirectoryDomainSaveButtonClick/config.xml
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,50 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.0</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<useSecurity>true</useSecurity> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.plugins.active_directory.ActiveDirectorySecurityRealm" plugin="[email protected]"> | ||
<domains> | ||
<hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
<name>samdom.example.com</name> | ||
<bindName>CN=Administrator,CN=Users,DC=samdom,DC=example,DC=com</bindName> | ||
<bindPassword>small</bindPassword> | ||
<tlsConfiguration>TRUST_ALL_CERTIFICATES</tlsConfiguration> | ||
<internalUsersDatabase>admin</internalUsersDatabase> | ||
</hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
</domains> | ||
<startTls>true</startTls> | ||
<groupLookupStrategy>RECURSIVE</groupLookupStrategy> | ||
<removeIrrelevantGroups>false</removeIrrelevantGroups> | ||
<internalUsersDatabase> | ||
<jenkinsInternalUser>admin</jenkinsInternalUser> | ||
</internalUsersDatabase> | ||
</securityRealm> | ||
<disableRememberMe>false</disableRememberMe> | ||
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/> | ||
<workspaceDir>${ITEM_ROOTDIR}/workspace</workspaceDir> | ||
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir> | ||
<markupFormatter class="hudson.markup.EscapedMarkupFormatter"/> | ||
<jdks/> | ||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/> | ||
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/> | ||
<clouds/> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
<filterExecutors>false</filterExecutors> | ||
<filterQueue>false</filterQueue> | ||
<properties class="hudson.model.View$PropertyList"/> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>-1</slaveAgentPort> | ||
<label></label> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
</hudson> |
50 changes: 50 additions & 0 deletions
50
...veDirectoryDomainIntegrationTest/testActiveDirectoryDomainSettingShortPassword/config.xml
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,50 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.0</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<useSecurity>true</useSecurity> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.plugins.active_directory.ActiveDirectorySecurityRealm" plugin="[email protected]"> | ||
<domains> | ||
<hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
<name>samdom.example.com</name> | ||
<bindName>CN=Administrator,CN=Users,DC=samdom,DC=example,DC=com</bindName> | ||
<bindPassword>verylargepassword12345</bindPassword> | ||
<tlsConfiguration>TRUST_ALL_CERTIFICATES</tlsConfiguration> | ||
<internalUsersDatabase>admin</internalUsersDatabase> | ||
</hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
</domains> | ||
<startTls>true</startTls> | ||
<groupLookupStrategy>RECURSIVE</groupLookupStrategy> | ||
<removeIrrelevantGroups>false</removeIrrelevantGroups> | ||
<internalUsersDatabase> | ||
<jenkinsInternalUser>admin</jenkinsInternalUser> | ||
</internalUsersDatabase> | ||
</securityRealm> | ||
<disableRememberMe>false</disableRememberMe> | ||
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/> | ||
<workspaceDir>${ITEM_ROOTDIR}/workspace</workspaceDir> | ||
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir> | ||
<markupFormatter class="hudson.markup.EscapedMarkupFormatter"/> | ||
<jdks/> | ||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/> | ||
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/> | ||
<clouds/> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
<filterExecutors>false</filterExecutors> | ||
<filterQueue>false</filterQueue> | ||
<properties class="hudson.model.View$PropertyList"/> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>-1</slaveAgentPort> | ||
<label></label> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
</hudson> |
50 changes: 50 additions & 0 deletions
50
...ntegrationTest/testActiveDirectoryDomainTestDomainButtonClickWithShortPassword/config.xml
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,50 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
<disabledAdministrativeMonitors/> | ||
<version>1.0</version> | ||
<numExecutors>2</numExecutors> | ||
<mode>NORMAL</mode> | ||
<useSecurity>true</useSecurity> | ||
<authorizationStrategy class="hudson.security.AuthorizationStrategy$Unsecured"/> | ||
<securityRealm class="hudson.plugins.active_directory.ActiveDirectorySecurityRealm" plugin="[email protected]"> | ||
<domains> | ||
<hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
<name>samdom.example.com</name> | ||
<bindName>CN=Administrator,CN=Users,DC=samdom,DC=example,DC=com</bindName> | ||
<bindPassword>small</bindPassword> | ||
<tlsConfiguration>TRUST_ALL_CERTIFICATES</tlsConfiguration> | ||
<internalUsersDatabase>admin</internalUsersDatabase> | ||
</hudson.plugins.active__directory.ActiveDirectoryDomain> | ||
</domains> | ||
<startTls>true</startTls> | ||
<groupLookupStrategy>RECURSIVE</groupLookupStrategy> | ||
<removeIrrelevantGroups>false</removeIrrelevantGroups> | ||
<internalUsersDatabase> | ||
<jenkinsInternalUser>admin</jenkinsInternalUser> | ||
</internalUsersDatabase> | ||
</securityRealm> | ||
<disableRememberMe>false</disableRememberMe> | ||
<projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/> | ||
<workspaceDir>${ITEM_ROOTDIR}/workspace</workspaceDir> | ||
<buildsDir>${ITEM_ROOTDIR}/builds</buildsDir> | ||
<markupFormatter class="hudson.markup.EscapedMarkupFormatter"/> | ||
<jdks/> | ||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/> | ||
<myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/> | ||
<clouds/> | ||
<scmCheckoutRetryCount>0</scmCheckoutRetryCount> | ||
<views> | ||
<hudson.model.AllView> | ||
<owner class="hudson" reference="../../.."/> | ||
<name>All</name> | ||
<filterExecutors>false</filterExecutors> | ||
<filterQueue>false</filterQueue> | ||
<properties class="hudson.model.View$PropertyList"/> | ||
</hudson.model.AllView> | ||
</views> | ||
<primaryView>All</primaryView> | ||
<slaveAgentPort>-1</slaveAgentPort> | ||
<label></label> | ||
<nodeProperties/> | ||
<globalNodeProperties/> | ||
</hudson> |
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