Skip to content

Commit

Permalink
Merge pull request #97 from jtnord/JENKINS-50590
Browse files Browse the repository at this point in the history
[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 23e497b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/org/jvnet/hudson/test/JenkinsRule.java
Expand Up @@ -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;
}

Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 23e497b

Please sign in to comment.