-
Notifications
You must be signed in to change notification settings - Fork 102
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
Freshen up realistic tests #78
Changes from 3 commits
786de55
377d2e1
79e2404
904e34c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
<licenses> | ||
<license> | ||
<name>The MIT license</name> | ||
<url>https://www.opensource.org/licenses/mit-license.php</url> | ||
<url>https://opensource.org/licenses/MIT</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
@@ -28,9 +28,8 @@ | |
<changelist>-SNAPSHOT</changelist> | ||
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo> | ||
<apacheds.version>2.0.0.AM25</apacheds.version> | ||
<jenkins.version>2.266</jenkins.version> | ||
<jenkins.version>2.277.1</jenkins.version> | ||
<java.level>8</java.level> | ||
<configuration-as-code.version>1.47</configuration-as-code.version> | ||
</properties> | ||
|
||
<scm> | ||
|
@@ -83,18 +82,20 @@ | |
<dependency> | ||
<groupId>org.jenkins-ci.plugins</groupId> | ||
<artifactId>mailer</artifactId> | ||
<version>1.32.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jenkins-ci.test</groupId> | ||
<artifactId>docker-fixtures</artifactId> | ||
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. Deprecated. |
||
<version>1.10</version> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>testcontainers</artifactId> | ||
<version>1.15.2</version> | ||
<scope>test</scope> | ||
<exclusions> | ||
<!-- Required: 2.2.3, JCasC includes: 2.10.2 --> | ||
<exclusion> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-compress</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<artifactId>jackson-annotations</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
@@ -279,18 +280,28 @@ | |
<dependency> | ||
<groupId>io.jenkins</groupId> | ||
<artifactId>configuration-as-code</artifactId> | ||
<version>${configuration-as-code.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.jenkins.configuration-as-code</groupId> | ||
<artifactId>test-harness</artifactId> | ||
<version>${configuration-as-code.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.jenkins.tools.bom</groupId> | ||
<artifactId>bom-2.277.x</artifactId> | ||
<version>26</version> | ||
<scope>import</scope> | ||
<type>pom</type> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,58 +4,69 @@ | |
import hudson.security.LDAPSecurityRealm; | ||
import hudson.tasks.MailAddressResolver; | ||
import hudson.util.Secret; | ||
import org.springframework.security.ldap.userdetails.LdapUserDetails; | ||
import org.jenkinsci.test.acceptance.docker.DockerContainer; | ||
import org.jenkinsci.test.acceptance.docker.DockerFixture; | ||
import org.jenkinsci.test.acceptance.docker.DockerRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.hamcrest.core.StringContains.containsString; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assume.assumeFalse; | ||
import static org.junit.Assume.assumeTrue; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.RealJenkinsRule; | ||
import org.springframework.security.ldap.userdetails.LdapUserDetails; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
/** | ||
* Tests the plugin when logging in to rroemhild/test-openldap | ||
*/ | ||
public class PlanetExpressTest { | ||
|
||
static final String TEST_IMAGE = "rroemhild/test-openldap@sha256:b4e433bbcba1f17899d6bcb0a8e854bbe52c754faa4e785d0c27a2b55eb12cd8"; | ||
static final String DN = "dc=planetexpress,dc=com"; | ||
static final String MANAGER_DN = "cn=admin,dc=planetexpress,dc=com"; | ||
static final String MANAGER_SECRET = "GoodNewsEveryone"; | ||
|
||
@BeforeClass public static void requiresDocker() { | ||
assumeTrue(DockerClientFactory.instance().isDockerAvailable()); | ||
} | ||
|
||
@BeforeClass public static void linuxOnly() { | ||
assumeFalse("Windows CI builders now have Docker installed…but it does not support Linux images", Functions.isWindows() && System.getenv("JENKINS_URL") != null); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Rule | ||
public DockerRule<PlanetExpress> docker = new DockerRule<>(PlanetExpress.class); | ||
public GenericContainer container = new GenericContainer(TEST_IMAGE).withExposedPorts(389); | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
public RealJenkinsRule rr = new RealJenkinsRule(); | ||
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. See jenkinsci/jenkins-test-harness#280. Would have increased my confidence about class loading issues during #48 in particular. 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. (I merged #77 to make this possible.) |
||
|
||
@Test | ||
public void login() throws Exception { | ||
PlanetExpress d = docker.get(); | ||
LDAPSecurityRealm realm = new LDAPSecurityRealm(d.ipBound(389) + ":" + d.port(389), PlanetExpress.DN, null, null, null, null, null, PlanetExpress.MANAGER_DN, Secret.fromString(PlanetExpress.MANAGER_SECRET), false, false, null, null, "cn", "mail", null,null); | ||
j.jenkins.setSecurityRealm(realm); | ||
j.configRoundtrip(); | ||
String content = j.createWebClient().login("fry", "fry").goTo("whoAmI").getBody().getTextContent(); | ||
assertThat(content, containsString("Philip J. Fry")); | ||
|
||
|
||
LdapUserDetails zoidberg = (LdapUserDetails) j.jenkins.getSecurityRealm().loadUserByUsername2("zoidberg"); | ||
assertEquals("cn=John A. Zoidberg,ou=people,dc=planetexpress,dc=com", zoidberg.getDn()); | ||
|
||
String leelaEmail = MailAddressResolver.resolve(j.jenkins.getUser("leela")); | ||
assertEquals("leela@planetexpress.com", leelaEmail); | ||
|
||
public void login() throws Throwable { | ||
String server = container.getHost() + ":" + container.getFirstMappedPort(); | ||
rr.then(new Login(server)); | ||
} | ||
private static class Login implements RealJenkinsRule.Step { | ||
private final String server; | ||
Login(String server) { | ||
this.server = server; | ||
} | ||
@Override | ||
public void run(JenkinsRule j) throws Throwable { | ||
LDAPSecurityRealm realm = new LDAPSecurityRealm(server, DN, null, null, null, null, null, MANAGER_DN, Secret.fromString(MANAGER_SECRET), false, false, null, null, "cn", "mail", null,null); | ||
j.jenkins.setSecurityRealm(realm); | ||
j.configRoundtrip(); | ||
String content = j.createWebClient().login("fry", "fry").goTo("whoAmI").getBody().getTextContent(); | ||
assertThat(content, containsString("Philip J. Fry")); | ||
|
||
@DockerFixture(id = "openldap-express", ports = {389, 636}) | ||
public static class PlanetExpress extends DockerContainer { | ||
|
||
static final String DN = "dc=planetexpress,dc=com"; | ||
static final String MANAGER_DN = "cn=admin,dc=planetexpress,dc=com"; | ||
static final String MANAGER_SECRET = "GoodNewsEveryone"; | ||
LdapUserDetails zoidberg = (LdapUserDetails) j.jenkins.getSecurityRealm().loadUserByUsername2("zoidberg"); | ||
assertEquals("cn=John A. Zoidberg,ou=people,dc=planetexpress,dc=com", zoidberg.getDn()); | ||
|
||
String leelaEmail = MailAddressResolver.resolve(j.jenkins.getUser("leela")); | ||
assertEquals("leela@planetexpress.com", leelaEmail); | ||
} | ||
} | ||
|
||
} |
This file was deleted.
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.
supersedes #76