Skip to content

Commit

Permalink
Correcting X-Gitlab-Token #186
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Oct 28, 2020
1 parent 8cc4ea3 commit aeec75f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import static java.util.logging.Level.SEVERE;
import static org.jenkinsci.plugins.gwt.GenericResponse.jsonResponse;
import static org.kohsuke.stapler.HttpResponses.ok;

import com.google.common.annotations.VisibleForTesting;
import hudson.Extension;
import hudson.model.UnprotectedRootAction;
import hudson.security.csrf.CrumbExclusion;

import java.io.IOException;
import java.util.Collections;
import java.util.Enumeration;
Expand All @@ -18,17 +17,21 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.jenkinsci.plugins.gwt.jobfinder.JobFinder;
import org.jenkinsci.plugins.gwt.whitelist.WhitelistException;
import org.jenkinsci.plugins.gwt.whitelist.WhitelistVerifier;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;

import com.google.common.annotations.VisibleForTesting;

@Extension
public class GenericWebHookRequestReceiver extends CrumbExclusion implements UnprotectedRootAction {

Expand Down Expand Up @@ -91,8 +94,8 @@ String getGivenToken(
}
}
}
if (headers.containsKey("X-Gitlab-Token")) {
return headers.get("X-Gitlab-Token").get(0);
if (headers.containsKey("x-gitlab-token")) {
return headers.get("x-gitlab-token").get(0);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.kohsuke.stapler.StaplerRequest;

Expand Down Expand Up @@ -86,7 +87,7 @@ public void testThatGitLabTokenHeaderTokenGivesThatToken() {
final GenericWebHookRequestReceiver sut = new GenericWebHookRequestReceiver();
final Map<String, List<String>> headers =
of( //
"X-Gitlab-Token", (List<String>) newArrayList("gitlabtoken"));
"x-gitlab-token", (List<String>) newArrayList("gitlabtoken"));
final Map<String, String[]> parameterMap = newHashMap();

final String actual = sut.getGivenToken(headers, parameterMap);
Expand Down

0 comments on commit aeec75f

Please sign in to comment.