Skip to content
Permalink
Browse files
[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
  • Loading branch information
josiahhaswell authored and oleg-nenashev committed Aug 12, 2017
1 parent ee3600c commit 34bf393255bb603bb3b0fb921a41fc3916d16f42
Showing with 29 additions and 0 deletions.
  1. +4 −0 core/src/main/java/hudson/model/View.java
  2. +25 −0 test/src/test/java/hudson/model/ViewTest.java
@@ -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;
@@ -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;
@@ -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;
@@ -85,6 +90,26 @@
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.
*/

0 comments on commit 34bf393

Please sign in to comment.