Skip to content
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

IPV6 follow-up #776

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/org/jvnet/hudson/test/RealJenkinsRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public final class RealJenkinsRule implements TestRule {

private int timeout = Integer.getInteger("jenkins.test.timeout", new DisableOnDebug(null).isDebugging() ? 0 : 600);

private String host = httpListenAddress;
private String host = "localhost";

Process proc;

Expand Down Expand Up @@ -292,13 +292,13 @@ public RealJenkinsRule withTimeout(int timeout) {

/**
* Sets a custom host name for the Jenkins root URL.
* <p>By default, this is the same as the {@link #httpListenAddress}.
* But you may wish to set it to something else that resolves to the loopback address,
* <p>By default, this is just {@code localhost}.
* But you may wish to set it to something else that resolves to localhost,
* such as {@code some-id.127.0.0.1.nip.io}.
Vlatombe marked this conversation as resolved.
Show resolved Hide resolved
* This is particularly useful when running multiple copies of Jenkins (and/or other services) in one test case,
* since browser cookies are sensitive to host but not port and so otherwise {@link HttpServletRequest#getSession}
* might accidentally be shared across otherwise distinct services.
* <p>Calling this method does <em>not</em> change the fact that Jenkins will be configured to listen only on the loopback address for security reasons
* <p>Calling this method does <em>not</em> change the fact that Jenkins will be configured to listen only on localhost for security reasons
* (so others in the same network cannot access your system under test, especially if it lacks authentication).
*/
public RealJenkinsRule withHost(String host) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/org/jvnet/hudson/test/RealJenkinsRuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayContainingInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
Expand All @@ -53,6 +54,8 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.HttpURLConnection;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -92,6 +95,14 @@ private static void _smokes(JenkinsRule r) throws Throwable {
assertEquals(rr.getUrl().toExternalForm(), rr.runRemotely(RealJenkinsRuleTest::_getJenkinsUrlFromRemote));
}

@Test public void ipv6() throws Throwable {
// Use -Djava.net.preferIPv6Addresses=true if dualstack
assumeThat(InetAddress.getLoopbackAddress(), instanceOf(Inet6Address.class));
rr.withHost("::1").startJenkins();
var externalForm = rr.getUrl().toExternalForm();
assertEquals(externalForm, rr.runRemotely(RealJenkinsRuleTest::_getJenkinsUrlFromRemote));
}

@Test public void testThrowsException() {
assertThat(assertThrows(RealJenkinsRule.StepException.class, () -> rr.then(RealJenkinsRuleTest::throwsException)).getMessage(),
containsString("IllegalStateException: something is wrong"));
Expand Down
Loading