Skip to content

Commit

Permalink
Add skipping validation for system runners
Browse files Browse the repository at this point in the history
  • Loading branch information
akorneta committed Oct 22, 2015
1 parent 243ea2f commit 4f4406f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ protected void validateProjectRunnerNames(Factory factory) throws BadRequestExce
NewProject project = factory.getProject();
if (project != null && project.getRunners() != null && project.getRunners().getConfigs() != null) {
for (String runnerName : project.getRunners().getConfigs().keySet()) {
if (!RUNNER_NAME_VALIDATOR.matcher(runnerName).matches()) {
if (!runnerName.startsWith("system:") && !RUNNER_NAME_VALIDATOR.matcher(runnerName).matches()) {
throw new BadRequestException("Invalid runner name " + runnerName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ void checkProjectName(String name) throws BadRequestException {
void checkProjectRunners(RunnersDescriptor runnersDescriptor) throws BadRequestException {
if (runnersDescriptor != null && runnersDescriptor.getConfigs() != null && !runnersDescriptor.getConfigs().isEmpty()) {
for (String runnerName : runnersDescriptor.getConfigs().keySet()) {
if (!RUNNER_NAME_VALIDATOR.matcher(runnerName).matches()) {
if (!runnerName.startsWith("system:") && !RUNNER_NAME_VALIDATOR.matcher(runnerName).matches()) {
throw new BadRequestException("Runner name " + runnerName + " is invalid");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3036,6 +3036,16 @@ public void shouldThrowExceptionWhenProjectNameIsInvalid() throws Exception {
projectService.checkProjectName("!#project-name#!");
}

@Test
public void shouldNotThrowExceptionIfRunnerIsSystemScope() throws Exception {
RunnersDescriptor runnersDescriptor = mock(RunnersDescriptor.class);
ProjectService projectService = spy(new ProjectService());
RunnerConfiguration config = mock(RunnerConfiguration.class);
when(runnersDescriptor.getConfigs()).thenReturn(ImmutableMap.of("system:/javascript/web/simple", config));

projectService.checkProjectRunners(runnersDescriptor);
}

@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Runner name !#runenr#! is invalid")
public void shouldThrowExceptionWhenRunnerNameIsInvalid() throws Exception {
RunnersDescriptor runnersDescriptor = mock(RunnersDescriptor.class);
Expand Down

0 comments on commit 4f4406f

Please sign in to comment.