public boolean validateTree(ValidationContext validationContext) { validate(validationContext); return errors().isEmpty(); }
@Test public void shouldNotErrorOutWhenValidationIsSuccessfulForSecureVariables() throws CryptoException { String plainText = "secure_value"; String cipherText = "cipherText"; when(goCipher.encrypt(plainText)).thenReturn(cipherText); when(goCipher.decrypt(cipherText)).thenReturn(plainText); EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(goCipher, "secure_key", plainText, true); environmentVariableConfig.validate(null); assertThat(environmentVariableConfig.errors().isEmpty(), is(true)); }
@Test public void shouldErrorOutOnValidateWhenEncryptedValueIsForceChanged() throws CryptoException { String plainText = "secure_value"; String cipherText = "cipherText"; when(goCipher.encrypt(plainText)).thenReturn(cipherText); when(goCipher.decrypt(cipherText)).thenThrow(new CryptoException("last block incomplete in decryption")); EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(goCipher, "secure_key", plainText, true); environmentVariableConfig.validate(null); ConfigErrors error = environmentVariableConfig.errors(); assertThat(error.isEmpty(), is(false)); assertThat(error.on(EnvironmentVariableConfig.VALUE), is("Encrypted value for variable named 'secure_key' is invalid. This usually happens when the cipher text is modified to have an invalid value.")); }
@Test public void shouldNotErrorOutWhenValidationIsSuccessfulForPlainTextVariables() { EnvironmentVariableConfig environmentVariableConfig = new EnvironmentVariableConfig(goCipher, "plain_key", "plain_value", false); environmentVariableConfig.validate(null); assertThat(environmentVariableConfig.errors().isEmpty(), is(true)); }
@Override public void build(ScheduleOptions scheduleOptions, HttpOperationResult result, String pipelineName, PipelineScheduleOptions pipelineScheduleOptions, HealthStateType healthStateType) { for (EnvironmentVariableConfig environmentVariable : pipelineScheduleOptions.getSecureEnvironmentVariables()) { if (!goConfigService.hasVariableInScope(pipelineName, environmentVariable.getName())) { String variableUnconfiguredMessage = String.format("Variable '%s' has not been configured for pipeline '%s'", environmentVariable.getName(), pipelineName); result.unprocessibleEntity("Request to schedule pipeline rejected", variableUnconfiguredMessage, healthStateType); return; } environmentVariable.validate(null); if (!environmentVariable.errors().isEmpty()) { result.unprocessibleEntity("Request to schedule pipeline rejected", environmentVariable.errors().asString(), healthStateType); return; } scheduleOptions.getVariables().add(environmentVariable); } } }