Skip to content
Permalink
Browse files Browse the repository at this point in the history
#000 - Validate stage counter in GETs as well.
Continuation of commit c22e042
  • Loading branch information
arvindsv committed Oct 25, 2021
1 parent f626d8c commit 4c4bb47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -259,6 +259,10 @@ public ModelAndView consoleout(@RequestParam("pipelineName") String pipelineName
) {
start = start == null ? 0L : start;

if (!isValidStageCounter(stageCounter)) {
return buildNotFound(pipelineName, pipelineCounter, stageName, stageCounter, buildName);
}

try {
JobIdentifier identifier = restfulService.findJob(pipelineName, pipelineCounter, stageName, stageCounter, buildName);
if (jobInstanceDao.isJobCompleted(identifier) && !consoleService.doesLogExist(identifier)) {
Expand All @@ -281,6 +285,11 @@ public ModelAndView handleError(HttpServletRequest request, HttpServletResponse

ModelAndView getArtifact(String filePath, ArtifactFolderViewFactory folderViewFactory, String pipelineName, String counterOrLabel, String stageName, String stageCounter, String buildName, String sha, String serverAlias) throws Exception {
LOGGER.info("[Artifact Download] Trying to resolve '{}' for '{}/{}/{}/{}/{}'", filePath, pipelineName, counterOrLabel, stageName, stageCounter, buildName);

if (!isValidStageCounter(stageCounter)) {
return buildNotFound(pipelineName, counterOrLabel, stageName, stageCounter, buildName);
}

long before = System.currentTimeMillis();
ArtifactsView view;
//Work out the job that we are trying to retrieve
Expand Down
Expand Up @@ -136,6 +136,18 @@ void shouldFailToPostAndPutWhenStageCounterIsNotAPositiveInteger() throws Except
assertThat(((ResponseCodeView) modelAndView.getView()).getStatusCode(), is(SC_NOT_FOUND));
}

@Test
void shouldFailToGetConsoleOutWhenStageCounterIsNotAPositiveInteger() throws Exception {
ModelAndView modelAndView = artifactsController.consoleout("pipeline-1", "1", "stage-1", "job-1", "NOT_AN_INTEGER", 122L);
assertThat(((ResponseCodeView) modelAndView.getView()).getStatusCode(), is(SC_NOT_FOUND));
}

@Test
void shouldFailToGetArtifactWhenStageCounterIsNotAPositiveInteger() throws Exception {
ModelAndView modelAndView = artifactsController.getArtifactAsHtml("pipeline-1", "1", "stage-1", "NOT_AN_INTEGER", "job-1", "some-path", "sha1", "alias");
assertThat(((ResponseCodeView) modelAndView.getView()).getStatusCode(), is(SC_NOT_FOUND));
}

@Test
public void shouldFunnelAll_GET_calls() throws Exception {
final ModelAndView returnVal = new ModelAndView();
Expand Down

0 comments on commit 4c4bb47

Please sign in to comment.