ExtendedWorkflowValidator implements WorkflowValidator { @Override public List<String> validateWorkflow(Workflow workflow) { var e = new ArrayList<>(delegate.validateWorkflow(workflow)); var cfg = workflow.configuration(); cfg.runningTimeout().ifPresent(timeout -> upperLimit(e, timeout, maxRunningTimeout, "running timeout is too big")); cfg.secret().ifPresent(secret -> { if (!secretWhitelist.contains(secret.name())) { e.add("secret " + secret.name() + " is not whitelisted"); } }); return e; } ExtendedWorkflowValidator(WorkflowValidator delegate,
                                   Duration maxRunningTimeout,
                                   Set<String> secretWhitelist); @Override List<String> validateWorkflow(Workflow workflow);  }
@Test public void validateValidWorkflow() { assertThat(sut.validateWorkflow(Workflow.create("test", FULL_WORKFLOW_CONFIGURATION)), is(empty())); }
@Test public void shouldPropagateErrorFromDelegate() { var errors = List.of("foo", "bar"); when(basicWorkflowValidator.validateWorkflow(any())).thenReturn(errors); assertThat(sut.validateWorkflow(Workflow.create("test", FULL_WORKFLOW_CONFIGURATION)), is(errors)); }
@Test public void shouldEnforceMaxRunningTimeoutLimitWhenSpecified() { var runningTimeout = Duration.ofDays(365); var errors = sut.validateWorkflow( Workflow.create("test", WorkflowConfigurationBuilder.from(FULL_WORKFLOW_CONFIGURATION) .runningTimeout(runningTimeout) .build())); assertThat(errors, contains(limit("running timeout is too big", runningTimeout, MAX_RUNNING_TIMEOUT))); }
@Test public void shouldFailUsageOfNonWhitelistedSecret() { var errors = sut.validateWorkflow( Workflow.create("test", WorkflowConfigurationBuilder.from(FULL_WORKFLOW_CONFIGURATION) .secret(WorkflowConfiguration.Secret.create("foo-secret", "/path")) .build())); assertThat(errors, contains("secret foo-secret is not whitelisted")); }