Skip to content

Commit

Permalink
[FIXED JENKINS-21254] Ensuring that all <link>s offered on the /login…
Browse files Browse the repository at this point in the history
… page can be read even by anonymous users without Jenkins.READ.

Originally-Committed-As: 7c91c402a7c491d51f776178898ee473989ab6c9
  • Loading branch information
jglick committed Jan 7, 2014
1 parent 46d34d7 commit 8ca93af
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Expand Up @@ -30,6 +30,7 @@
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.WebRequestSettings;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
Expand Down Expand Up @@ -206,6 +207,7 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;

import jenkins.model.JenkinsLocationConfiguration;

Expand Down Expand Up @@ -250,11 +252,12 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
protected Server server;

/**
* Where in the {@link Server} is Hudson deployed?
* Where in the {@link Server} is Jenkins deployed?
* <p>
* Just like {@link javax.servlet.ServletContext#getContextPath()}, starts with '/' but doesn't end with '/'.
* Unlike {@link WebClient#getContextPath} this is not a complete URL.
*/
protected String contextPath = "/jenkins";
public String contextPath = "/jenkins";

/**
* {@link Runnable}s to be invoked at {@link #after()} .
Expand Down Expand Up @@ -1913,10 +1916,10 @@ public Page getPage(String url) throws IOException, FailingHttpStatusCodeExcepti
}

/**
* Requests a page within Hudson.
* Requests an HTML page within Jenkins.
*
* @param relative
* Relative path within Hudson. Starts without '/'.
* Relative path within Jenkins. Starts without '/'.
* For example, "job/test/" to go to a job top page.
*/
public HtmlPage goTo(String relative) throws IOException, SAXException {
Expand All @@ -1928,14 +1931,24 @@ public HtmlPage goTo(String relative) throws IOException, SAXException {
}
}

public Page goTo(String relative, String expectedContentType) throws IOException, SAXException {
/**
* Requests a page within Jenkins.
*
* @param relative
* Relative path within Jenkins. Starts without '/'.
* For example, "job/test/" to go to a job top page.
* @param expectedContentType the expected {@link WebResponse#getContentType}, or null to do no such check
*/
public Page goTo(String relative, @CheckForNull String expectedContentType) throws IOException, SAXException {
assert !relative.startsWith("/");
Page p = super.getPage(getContextPath() + relative);
assertThat(p.getWebResponse().getContentType(), is(expectedContentType));
if (expectedContentType != null) {
assertThat(p.getWebResponse().getContentType(), is(expectedContentType));
}
return p;
}

/** Loads a page as XML. Useful for testing Hudson's xml api, in concert with
/** Loads a page as XML. Useful for testing Jenkins's XML API, in concert with
* assertXPath(DomNode page, String xpath)
* @param path the path part of the url to visit
* @return the XmlPage found at that url
Expand Down Expand Up @@ -1968,6 +1981,7 @@ public void assertFails(String url, int statusCode) throws Exception {
/**
* Returns the URL of the webapp top page.
* URL ends with '/'.
* <p>This is actually the same as {@link #getURL} and should not be confused with {@link #contextPath}.
*/
public String getContextPath() throws IOException {
return getURL().toExternalForm();
Expand Down

0 comments on commit 8ca93af

Please sign in to comment.