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'");
}
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()));
}
Aggregations