Search in sources :

Example 71 with EnvVars

use of hudson.EnvVars in project workflow-cps-plugin by jenkinsci.

the class ArgumentsActionImplTest method testArraySanitization.

@Test
public void testArraySanitization() {
    EnvVars env = new EnvVars();
    String secretUsername = "IAmA";
    // assume secretuser is a bound credential
    env.put("USERVARIABLE", secretUsername);
    Set<String> sensitiveVariables = new HashSet<>();
    sensitiveVariables.add("USERVARIABLE");
    HashMap<String, Object> args = new HashMap<>();
    args.put("ints", new int[] { 1, 2, 3 });
    args.put("strings", new String[] { "heh", secretUsername, "lumberjack" });
    ArgumentsActionImpl filtered = new ArgumentsActionImpl(args, env, sensitiveVariables);
    Map<String, Object> filteredArgs = filtered.getArguments();
    Assert.assertEquals(2, filteredArgs.size());
    Assert.assertThat(filteredArgs, IsMapContaining.hasEntry("ints", ArgumentsAction.NotStoredReason.UNSERIALIZABLE));
    Assert.assertThat(filteredArgs, IsMapContaining.hasKey("strings"));
    Object[] contents = (Object[]) (filteredArgs.get("strings"));
    Assert.assertArrayEquals(new Object[] { "heh", "${USERVARIABLE}", "lumberjack" }, (Object[]) (filteredArgs.get("strings")));
}
Also used : EnvVars(hudson.EnvVars) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 72 with EnvVars

use of hudson.EnvVars in project phabricator-jenkins-plugin by uber.

the class TestUtils method setEnvironmentVariables.

public static void setEnvironmentVariables(JenkinsRule j, Map<String, String> params) throws IOException {
    EnvironmentVariablesNodeProperty prop = new EnvironmentVariablesNodeProperty();
    EnvVars envVars = prop.getEnvVars();
    envVars.putAll(params);
    j.jenkins.getGlobalNodeProperties().add(prop);
}
Also used : EnvVars(hudson.EnvVars) EnvironmentVariablesNodeProperty(hudson.slaves.EnvironmentVariablesNodeProperty)

Aggregations

EnvVars (hudson.EnvVars)72 Test (org.junit.Test)25 IOException (java.io.IOException)17 FilePath (hudson.FilePath)11 TaskListener (hudson.model.TaskListener)9 AbortException (hudson.AbortException)8 ClientConfiguration (com.amazonaws.ClientConfiguration)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Computer (hudson.model.Computer)5 FreeStyleProject (hudson.model.FreeStyleProject)5 ArgumentListBuilder (hudson.util.ArgumentListBuilder)5 ParameterValue (hudson.model.ParameterValue)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Step (org.jenkinsci.plugins.workflow.steps.Step)4 ConduitAPIClient (com.uber.jenkins.phabricator.conduit.ConduitAPIClient)3 ConduitAPIException (com.uber.jenkins.phabricator.conduit.ConduitAPIException)3 Differential (com.uber.jenkins.phabricator.conduit.Differential)3 DifferentialClient (com.uber.jenkins.phabricator.conduit.DifferentialClient)3