use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class DefaultJobPlanTest method shouldApplyEnvironmentVariablesWhenRunningTheJob.
@Test
public void shouldApplyEnvironmentVariablesWhenRunningTheJob() {
EnvironmentVariablesConfig variables = new EnvironmentVariablesConfig();
variables.add("VARIABLE_NAME", "variable value");
DefaultJobPlan plan = new DefaultJobPlan(new Resources(), new ArtifactPlans(), new ArtifactPropertiesGenerators(), -1, null, null, variables, new EnvironmentVariablesConfig(), null);
EnvironmentVariableContext variableContext = new EnvironmentVariableContext();
plan.applyTo(variableContext);
assertThat(variableContext.getProperty("VARIABLE_NAME"), is("variable value"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class DefaultJobPlanTest method shouldRespectTriggerVariablesOverConfigVariables.
@Test
public void shouldRespectTriggerVariablesOverConfigVariables() {
DefaultJobPlan original = new DefaultJobPlan(new Resources(), new ArtifactPlans(), new ArtifactPropertiesGenerators(), 0, new JobIdentifier(), "uuid", env(new String[] { "blah", "foo" }, new String[] { "value", "bar" }), new EnvironmentVariablesConfig(), null);
original.setTriggerVariables(env(new String[] { "blah", "another" }, new String[] { "override", "anotherValue" }));
EnvironmentVariableContext variableContext = new EnvironmentVariableContext();
original.applyTo(variableContext);
assertThat(variableContext.getProperty("blah"), is("override"));
assertThat(variableContext.getProperty("foo"), is("bar"));
//becuase its a security issue to let operator set values for unconfigured variables
assertThat(variableContext.getProperty("another"), is(nullValue()));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableSCMMaterialTest method shouldMarkEnvironmentContextCreatedForAdditionalDataAsSecureIfTheValueContainsAnySpecialCharacters.
@Test
public void shouldMarkEnvironmentContextCreatedForAdditionalDataAsSecureIfTheValueContainsAnySpecialCharacters() throws UnsupportedEncodingException {
ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", true, "!secure_value:with_special_chars");
SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1, k2));
PluggableSCMMaterial material = new PluggableSCMMaterial();
material.setSCMConfig(scmConfig);
material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
HashMap<String, String> map = new HashMap<>();
map.put("ADDITIONAL_DATA_ONE", "foobar:!secure_value:with_special_chars");
map.put("ADDITIONAL_DATA_URL_ENCODED", "something:%21secure_value%3Awith_special_chars");
map.put("ADDITIONAL_DATA_TWO", "foobar:secure_value_with_regular_chars");
Modification modification = new Modification("loser", "comment", "email", new Date(), "revision-123", JsonHelper.toJsonString(map));
Modifications modifications = new Modifications(modification);
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1"));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K2"), is("!secure_value:with_special_chars"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_SCM_TW_DEV_GO_AGENT_K2"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_ADDITIONAL_DATA_ONE"), is("foobar:!secure_value:with_special_chars"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_SCM_TW_DEV_GO_AGENT_ADDITIONAL_DATA_ONE"), is("foobar:!secure_value:with_special_chars"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_SCM_TW_DEV_GO_AGENT_ADDITIONAL_DATA_TWO"), is("foobar:secure_value_with_regular_chars"));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_ADDITIONAL_DATA_URL_ENCODED"), is("something:%21secure_value%3Awith_special_chars"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_SCM_TW_DEV_GO_AGENT_ADDITIONAL_DATA_URL_ENCODED"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class P4MaterialTest method shouldAddClientNameEnvironmentVariable.
@Test
public void shouldAddClientNameEnvironmentVariable() {
TempFiles tempFiles = new TempFiles();
File p4_working_dir = tempFiles.mkdir("p4_working_dir");
P4Material p4 = new P4Material("host:10", "beautiful", "user");
p4.setPassword("loser");
EnvironmentVariableContext envVarCtx;
envVarCtx = new EnvironmentVariableContext();
p4.populateEnvironmentContext(envVarCtx, new MaterialRevision(p4, new Modification("loser", "loserish commit", "loser@boozer.com", new Date(), "123")), p4_working_dir);
assertThat(envVarCtx.getProperty("GO_P4_CLIENT"), is(p4.clientName(p4_working_dir)));
//sanity check
assertThat(envVarCtx.getProperty("GO_REVISION"), is("123"));
}
use of com.thoughtworks.go.util.command.EnvironmentVariableContext in project gocd by gocd.
the class PluggableSCMMaterialTest method shouldPopulateEnvironmentContext.
@Test
public void shouldPopulateEnvironmentContext() {
ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
ConfigurationProperty k2 = ConfigurationPropertyMother.create("scm-secure", true, "value");
SCM scmConfig = SCMMother.create("scm-id", "tw-dev", "pluginid", "version", new Configuration(k1, k2));
PluggableSCMMaterial material = new PluggableSCMMaterial();
material.setSCMConfig(scmConfig);
material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
Modifications modifications = new Modifications(new Modification(null, null, null, new Date(), "revision-123"));
EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_K1"), is("v1"));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_SCM_SECURE"), is("value"));
assertThat(environmentVariableContext.getPropertyForDisplay("GO_SCM_TW_DEV_GO_AGENT_SCM_SECURE"), is(EnvironmentVariableContext.EnvironmentVariable.MASK_VALUE));
assertThat(environmentVariableContext.getProperty("GO_SCM_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
}
Aggregations