Skip to content
Permalink
Browse files

Merge pull request #97 from jtnord/JENKINS-50590

[JENKINS-50590] do not remove all request parameters when adding a crumb
  • Loading branch information...
jglick committed Apr 9, 2018
2 parents 4ffe000 + 100cc61 commit 23e497bfa9d729e4aecea5626cd4899ea8fa690a
Showing with 11 additions and 4 deletions.
  1. +11 −4 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) {
params.addAll(oldParams);
}
req.setRequestParameters(params);
return req;
}

@@ -2312,8 +2317,10 @@ public URL createCrumbedUrl(String relativePath) throws IOException {
CrumbIssuer issuer = jenkins.getCrumbIssuer();
String crumbName = issuer.getDescriptor().getCrumbRequestField();
String crumb = issuer.getCrumb(null);

return new URL(getContextPath()+relativePath+"?"+crumbName+"="+crumb);
if (relativePath.indexOf('?') == -1) {
return new URL(getContextPath()+relativePath+"?"+crumbName+"="+crumb);
}
return new URL(getContextPath()+relativePath+"&"+crumbName+"="+crumb);
}

/**

0 comments on commit 23e497b

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