Search in sources :

Example 6 with EnvironmentVariable

use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.

the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedEncryptedEnvironmentVariable.

@Test
public void shouldScheduleAPipelineWithTheProvidedEncryptedEnvironmentVariable() throws InvalidCipherTextException {
    pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
    pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), new HttpLocalizedOperationResult());
    assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
    PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
    String overriddenEncryptedValue = new GoCipher().encrypt("overridden_value");
    pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", overriddenEncryptedValue));
    pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
    assertThat(result.isSuccess(), is(true));
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
    assertNotNull(buildCause);
    EnvironmentVariable secureVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {

        @Override
        public boolean evaluate(Object o) {
            EnvironmentVariable variable = (EnvironmentVariable) o;
            return variable.getName().equals("SECURE_VAR1");
        }
    });
    assertThat(secureVariable.getValue(), is("overridden_value"));
    assertThat(secureVariable.isSecure(), is(true));
}
Also used : EnvironmentVariableConfig(com.thoughtworks.go.config.EnvironmentVariableConfig) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) GoCipher(com.thoughtworks.go.security.GoCipher) PipelineScheduleOptions(com.thoughtworks.go.server.domain.PipelineScheduleOptions) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) MaterialUpdateSuccessfulMessage(com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Predicate(org.apache.commons.collections.Predicate) Test(org.junit.Test)

Aggregations

EnvironmentVariable (com.thoughtworks.go.domain.EnvironmentVariable)6 Test (org.junit.Test)5 EnvironmentVariables (com.thoughtworks.go.domain.EnvironmentVariables)4 EnvironmentVariableConfig (com.thoughtworks.go.config.EnvironmentVariableConfig)2 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)2 GoCipher (com.thoughtworks.go.security.GoCipher)2 PipelineScheduleOptions (com.thoughtworks.go.server.domain.PipelineScheduleOptions)2 MaterialUpdateSuccessfulMessage (com.thoughtworks.go.server.materials.MaterialUpdateSuccessfulMessage)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 Predicate (org.apache.commons.collections.Predicate)2 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 List (java.util.List)1 Criteria (org.hibernate.Criteria)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1