Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIX JENKINS-43848] - Lack of cache-invalidation headers results in s…
…tale item list (#2973)

* Saving progress for review

* Adding licenses

* Adding integration test for headers

* Removing proposal for refactoring to method objects

* Removing whitespace changeswq

* Fixing test

(cherry picked from commit 34bf393)
  • Loading branch information
josiahhaswell authored and olivergondza committed Aug 24, 2017
1 parent c01a597 commit 9a8fdb9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/hudson/model/View.java
Expand Up @@ -1053,6 +1053,10 @@ public FormValidation doCheckJobName(@QueryParameter String value) {
*/
@Restricted(DoNotUse.class)
public Categories doItemCategories(StaplerRequest req, StaplerResponse rsp, @QueryParameter String iconStyle) throws IOException, ServletException {

rsp.addHeader("Cache-Control", "no-cache, no-store, must-revalidate");
rsp.addHeader("Pragma", "no-cache");
rsp.addHeader("Expires", "0");
getOwner().checkPermission(Item.CREATE);
Categories categories = new Categories();
int order = 0;
Expand Down
25 changes: 25 additions & 0 deletions test/src/test/java/hudson/model/ViewTest.java
Expand Up @@ -25,6 +25,7 @@

import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.DomNodeUtil;
import com.gargoylesoftware.htmlunit.util.NameValuePair;
import jenkins.model.Jenkins;
import org.jvnet.hudson.test.Issue;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
Expand Down Expand Up @@ -53,11 +54,15 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import jenkins.model.ProjectNamingStrategy;
import jenkins.security.NotReallyRoleSensitiveCallable;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import org.junit.Ignore;
import org.junit.Rule;
Expand Down Expand Up @@ -85,6 +90,26 @@ public class ViewTest {
assertNotNull(j.createWebClient().goTo("").getWebResponse().getResponseHeaderValue("X-Hudson"));
}

@Issue("JENKINS-43848")
@Test public void testNoCacheHeadersAreSet() throws Exception {
List<NameValuePair> responseHeaders = j.createWebClient()
.goTo("view/all/itemCategories", "application/json")
.getWebResponse()
.getResponseHeaders();


final Map<String, String> values = new HashMap<>();

for(NameValuePair p : responseHeaders) {
values.put(p.getName(), p.getValue());
}

String resp = values.get("Cache-Control");
assertThat(resp, is("no-cache, no-store, must-revalidate"));
assertThat(values.get("Expires"), is("0"));
assertThat(values.get("Pragma"), is("no-cache"));
}

/**
* Creating two views with the same name.
*/
Expand Down

0 comments on commit 9a8fdb9

Please sign in to comment.