Skip to content

Commit

Permalink
[JENKINS-30588] Add test.
Browse files Browse the repository at this point in the history
  • Loading branch information
andresrc committed Jan 19, 2017
1 parent 0734ece commit cd5869c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/test/java/hudson/security/LDAPSecurityRealm_Test.java
Expand Up @@ -29,7 +29,14 @@
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import jenkins.model.IdStrategy;
import jenkins.security.plugins.ldap.FromGroupSearchLDAPGroupMembershipStrategy;
import jenkins.security.plugins.ldap.FromUserRecordLDAPGroupMembershipStrategy;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -84,4 +91,52 @@ private void check() {
assertEquals("ldap://example.com/o=O%20O,c=C ldap://example.net/o=O%20O,c=C", LDAPSecurityRealm.toProviderUrl("example.com example.net", "o=O O,c=C "));
}

@Issue("JENKINS-30588")
@Test public void groupMembershipAttribute() throws Exception {
final String previousValue = "previousValue";
final String testValue = "testValue";
final LDAPSecurityRealm realm = new LDAPSecurityRealm(
"ldap.itd.umich.edu",
null,
null,
null,
null,
null,
new FromUserRecordLDAPGroupMembershipStrategy("previousValue"),
null,
null,
false,
false,
null,
null,
null,
null,
(IdStrategy)null,
(IdStrategy)null);
r.jenkins.setSecurityRealm(realm);
r.jenkins.getSecurityRealm().createSecurityComponents();
final JenkinsRule.WebClient c = r.createWebClient();
final HtmlPage security = c.goTo("configureSecurity");
final HtmlForm form = security.getFormByName("config");
getButtonByText(form, "Advanced...").click();
for (HtmlInput e : form.getInputsByName("_.attributeName")) {
if (e.getValueAttribute().equals(previousValue)) {
e.setValueAttribute(testValue);
}
}
getButtonByText(form, "Save").click();
final LDAPSecurityRealm changedRealm = ((LDAPSecurityRealm)r.jenkins.getSecurityRealm());
final String changedValue = ((FromUserRecordLDAPGroupMembershipStrategy)changedRealm.groupMembershipStrategy).getAttributeName();
assertEquals("Value should be changed", testValue, changedValue);
}

private HtmlButton getButtonByText(HtmlForm form, String text) throws Exception {
for (HtmlElement e : form.getElementsByTagName("button")) {
if (text.equals(e.getTextContent())) {
return ((HtmlButton)e);
}
}
throw new AssertionError(String.format("Button [%s] not found", text));
}

}

0 comments on commit cd5869c

Please sign in to comment.