Skip to content
Permalink
Browse files

[JENKINS-50590] do not remove all request parameters when adding a crumb

If you had a WebRequest with existing Parameters specified then adding a
crumb would remove all of those headers.  THis is somewhat suprising.

I thought about making getCrumbHeaderNVP() public but went with the
option that should anyway cause the least suprise.  The crumb is now
added to the list of parameters rather than replacing them.  It is added
first such that if there where existing crumb fields the newly added one
should be first.
  • Loading branch information...
jtnord committed Apr 5, 2018
1 parent 618723e commit 4821d0fe49f37d699a5ca294f0719f3287839eef
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/main/java/org/jvnet/hudson/test/JenkinsRule.java
@@ -2300,8 +2300,13 @@ public String getContextPath() throws IOException {
* Use {@link #createCrumbedUrl} instead if you intend to call {@link WebRequest#setRequestBody}, typical of a POST request.
*/
public WebRequest addCrumb(WebRequest req) {
NameValuePair crumb = getCrumbHeaderNVP();
req.setRequestParameters(Arrays.asList(crumb));
ArrayList<NameValuePair> params = new ArrayList<>();
params.add(getCrumbHeaderNVP());
List<NameValuePair> oldParams = req.getRequestParameters();
if (oldParams != null && !oldParams.isEmpty()) {
params.addAll(oldParams);
}
req.setRequestParameters(params);
return req;
}

0 comments on commit 4821d0f

Please sign in to comment.
You can’t perform that action at this time.