Search in sources :

Example 1 with EchoStep

use of org.jenkinsci.plugins.workflow.steps.EchoStep in project workflow-cps-plugin by jenkinsci.

the class SnippetizerTest method basics.

@Test
public void basics() throws Exception {
    st.assertRoundTrip(new EchoStep("hello world"), "echo 'hello world'");
    ReadFileStep s = new ReadFileStep("build.properties");
    st.assertRoundTrip(s, "readFile 'build.properties'");
    s.setEncoding("ISO-8859-1");
    st.assertRoundTrip(s, "readFile encoding: 'ISO-8859-1', file: 'build.properties'");
}
Also used : EchoStep(org.jenkinsci.plugins.workflow.steps.EchoStep) ReadFileStep(org.jenkinsci.plugins.workflow.steps.ReadFileStep) Test(org.junit.Test)

Example 2 with EchoStep

use of org.jenkinsci.plugins.workflow.steps.EchoStep in project workflow-cps-plugin by jenkinsci.

the class ArgumentsActionImplTest method testRecursiveSanitizationOfContent.

@Test
public void testRecursiveSanitizationOfContent() {
    int maxLen = ArgumentsActionImpl.getMaxRetainedLength();
    ArgumentsActionImpl impl = new ArgumentsActionImpl();
    EnvVars env = new EnvVars();
    String secretUsername = "secretuser";
    // assume secretuser is a bound credential
    env.put("USERVARIABLE", secretUsername);
    char[] oversized = new char[maxLen + 10];
    Arrays.fill(oversized, 'a');
    String oversizedString = new String(oversized);
    // Simplest masking of secret and oversized value
    Assert.assertEquals(ArgumentsAction.NotStoredReason.MASKED_VALUE, impl.sanitizeObjectAndRecordMutation(secretUsername, env));
    Assert.assertFalse(impl.isUnmodifiedArguments());
    impl.isUnmodifiedBySanitization = true;
    Assert.assertEquals(ArgumentsAction.NotStoredReason.OVERSIZE_VALUE, impl.sanitizeObjectAndRecordMutation(oversizedString, env));
    Assert.assertFalse(impl.isUnmodifiedArguments());
    impl.isUnmodifiedBySanitization = true;
    // Test explosion of Step & UninstantiatedDescribable objects
    Step mystep = new EchoStep("I have a " + secretUsername);
    Map<String, ?> singleSanitization = (Map<String, Object>) (impl.sanitizeObjectAndRecordMutation(mystep, env));
    Assert.assertEquals(1, singleSanitization.size());
    Assert.assertEquals(ArgumentsAction.NotStoredReason.MASKED_VALUE, singleSanitization.get("message"));
    Assert.assertFalse(impl.isUnmodifiedArguments());
    impl.isUnmodifiedBySanitization = true;
    singleSanitization = ((UninstantiatedDescribable) (impl.sanitizeObjectAndRecordMutation(mystep.getDescriptor().uninstantiate(mystep), env))).getArguments();
    Assert.assertEquals(1, singleSanitization.size());
    Assert.assertEquals(ArgumentsAction.NotStoredReason.MASKED_VALUE, singleSanitization.get("message"));
    Assert.assertFalse(impl.isUnmodifiedArguments());
    impl.isUnmodifiedBySanitization = true;
    // Maps
    HashMap<String, Object> dangerous = new HashMap<>();
    dangerous.put("name", secretUsername);
    Map<String, Object> sanitizedMap = impl.sanitizeMapAndRecordMutation(dangerous, env);
    Assert.assertNotEquals(sanitizedMap, dangerous);
    Assert.assertEquals(ArgumentsAction.NotStoredReason.MASKED_VALUE, sanitizedMap.get("name"));
    Assert.assertFalse(impl.isUnmodifiedArguments());
    impl.isUnmodifiedBySanitization = true;
    // String is no longer dangerous
    Map<String, Object> identicalMap = impl.sanitizeMapAndRecordMutation(dangerous, new EnvVars());
    Assert.assertEquals(identicalMap, dangerous);
    Assert.assertTrue(impl.isUnmodifiedArguments());
    // Lists
    List unsanitizedList = Arrays.asList("cheese", null, secretUsername);
    List sanitized = (List) impl.sanitizeListAndRecordMutation(unsanitizedList, env);
    Assert.assertEquals(3, sanitized.size());
    Assert.assertFalse(impl.isUnmodifiedArguments());
    Assert.assertEquals(ArgumentsAction.NotStoredReason.MASKED_VALUE, sanitized.get(2));
    impl.isUnmodifiedBySanitization = true;
    Assert.assertEquals(unsanitizedList, impl.sanitizeObjectAndRecordMutation(unsanitizedList, new EnvVars()));
    Assert.assertEquals(unsanitizedList, impl.sanitizeListAndRecordMutation(unsanitizedList, new EnvVars()));
}
Also used : EchoStep(org.jenkinsci.plugins.workflow.steps.EchoStep) HashMap(java.util.HashMap) Step(org.jenkinsci.plugins.workflow.steps.Step) StateMetaStep(org.jenkinsci.plugins.workflow.testMetaStep.StateMetaStep) EchoStep(org.jenkinsci.plugins.workflow.steps.EchoStep) SemaphoreStep(org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep) BindingStep(org.jenkinsci.plugins.credentialsbinding.impl.BindingStep) EnvVars(hudson.EnvVars) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

EchoStep (org.jenkinsci.plugins.workflow.steps.EchoStep)2 Test (org.junit.Test)2 EnvVars (hudson.EnvVars)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 BindingStep (org.jenkinsci.plugins.credentialsbinding.impl.BindingStep)1 ReadFileStep (org.jenkinsci.plugins.workflow.steps.ReadFileStep)1 Step (org.jenkinsci.plugins.workflow.steps.Step)1 SemaphoreStep (org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep)1 StateMetaStep (org.jenkinsci.plugins.workflow.testMetaStep.StateMetaStep)1