Skip to content
Permalink
Browse files

Merge pull request #10 from andresrc/JENKINS-30588

[JENKINS-30588] Value for "Group membership attribute" not saved
  • Loading branch information
andresrc committed Jan 23, 2017
2 parents 4ced65b + 052fe9f commit c4431e690f2e01284fc994e7919342bd014c2d13
@@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.6</version>
<version>2.21</version>
</parent>

<artifactId>ldap</artifactId>
@@ -13,7 +13,7 @@

<name>LDAP Plugin</name>
<description>Adds LDAP authentication to Jenkins</description>
<url>http://wiki.jenkins-ci.org/display/JENKINS/LDAP+Plugin</url>
<url>https://wiki.jenkins-ci.org/display/JENKINS/LDAP+Plugin</url>
<licenses>
<license>
<name>The MIT license</name>
@@ -36,13 +36,13 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

@@ -25,7 +25,7 @@ THE SOFTWARE.

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<f:entry field="attribute" title="${%Group membership attribute}">
<f:entry field="attributeName" title="${%Group membership attribute}">
<f:textbox default="memberOf"/>
</f:entry>
</j:jelly>
@@ -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;
@@ -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 c4431e6

Please sign in to comment.
You can’t perform that action at this time.