// Path: src/test/java/org/jenkinsci/plugins/credentialsbinding/test/CredentialsTestUtil.java
// public class CredentialsTestUtil {
// 
//     /**
//      * Registers the given value as a {@link StringCredentials} into the default {@link CredentialsProvider}.
//      * Returns the generated credential id for the registered credentials.
//      */
//     public static String registerStringCredentials(ModelObject context, String value) throws IOException {
//         String credentialsId = UUID.randomUUID().toString();
//         setStringCredentials(context, credentialsId, value);
//         return credentialsId;
//     }
// 
//     /**
//      * Registers the given value as a {@link StringCredentials} into the default {@link CredentialsProvider} using the
//      * specified credentials id.
//      */
//     public static void setStringCredentials(ModelObject context, String credentialsId, String value) throws IOException {
//         StringCredentials creds = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, null, Secret.fromString(value));
//         CredentialsProvider.lookupStores(context).iterator().next().addCredentials(Domain.global(), creds);
//     }
// }
// 
// Path: src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java
// public class Executables {
//     private static final String LOCATOR = Functions.isWindows() ? "where.exe" : "which";
// 
//     public static @CheckForNull
//     String getPathToExecutable(@NonNull String executable) {
//         try {
//             Process process = new ProcessBuilder(LOCATOR, executable).start();
//             List<String> output = IOUtils.readLines(process.getInputStream(), Charset.defaultCharset());
//             if (process.waitFor() != 0) {
//                 return null;
//             }
//             return output.isEmpty() ? null : output.get(0);
//         } catch (IOException | InterruptedException e) {
//             return null;
//         }
//     }
// 
//     public static Matcher<String> executable() {
//         return new CustomTypeSafeMatcher<String>("executable") {
//             @Override
//             protected boolean matchesSafely(String item) {
//                 try {
//                     return new ProcessBuilder(LOCATOR, item).start().waitFor() == 0;
//                 } catch (InterruptedException | IOException e) {
//                     return false;
//                 }
//             }
//         };
//     }
// }
// 
// Path: src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java
// public static Matcher<String> executable() {
//     return new CustomTypeSafeMatcher<String>("executable") {
//         @Override
//         protected boolean matchesSafely(String item) {
//             try {
//                 return new ProcessBuilder(LOCATOR, item).start().waitFor() == 0;
//             } catch (InterruptedException | IOException e) {
//                 return false;
//             }
//         }
//     };
// }


import hudson.tasks.Shell;
import org.jenkinsci.plugins.credentialsbinding.test.CredentialsTestUtil;
import org.jenkinsci.plugins.credentialsbinding.test.Executables;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import org.jvnet.hudson.test.JenkinsRule;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.jenkinsci.plugins.credentialsbinding.test.Executables.executable;
import static org.junit.Assume.assumeThat;
        List<String> passwords = new ArrayList<>(10);
        for (int i = 0; i < 10; i++) {
            int length = random.nextInt(24) + 8;
            StringBuilder sb = new StringBuilder(length);
            for (int j = 0; j < length; j++) {
                // choose a (printable) character in the closed range [' ', '~']
                // 0x7f is DEL, 0x7e is ~, and space is the first printable ASCII character
                char next = (char) (' ' + random.nextInt('\u007f' - ' '));
                sb.append(next);
            }
            passwords.add(sb.toString());
        }
        return passwords;
    }

    @ClassRule public static JenkinsRule j = new JenkinsRule();

    private WorkflowJob project;
    private String credentialsId;

    @BeforeClass
    public static void assumeBash() {
        assumeThat("bash", is(executable()));
        // due to https://github.com/jenkinsci/durable-task-plugin/blob/e75123eda986f20a390d92cc892c3d206e60aefb/src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java#L149
        // on Windows
        assumeThat("nohup", is(executable()));
    }

    @Before
    public void setUp() throws IOException {
// Path: src/test/java/org/jenkinsci/plugins/credentialsbinding/test/CredentialsTestUtil.java
// public class CredentialsTestUtil {
// 
//     /**
//      * Registers the given value as a {@link StringCredentials} into the default {@link CredentialsProvider}.
//      * Returns the generated credential id for the registered credentials.
//      */
//     public static String registerStringCredentials(ModelObject context, String value) throws IOException {
//         String credentialsId = UUID.randomUUID().toString();
//         setStringCredentials(context, credentialsId, value);
//         return credentialsId;
//     }
// 
//     /**
//      * Registers the given value as a {@link StringCredentials} into the default {@link CredentialsProvider} using the
//      * specified credentials id.
//      */
//     public static void setStringCredentials(ModelObject context, String credentialsId, String value) throws IOException {
//         StringCredentials creds = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, null, Secret.fromString(value));
//         CredentialsProvider.lookupStores(context).iterator().next().addCredentials(Domain.global(), creds);
//     }
// }
// 
// Path: src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java
// public class Executables {
//     private static final String LOCATOR = Functions.isWindows() ? "where.exe" : "which";
// 
//     public static @CheckForNull
//     String getPathToExecutable(@NonNull String executable) {
//         try {
//             Process process = new ProcessBuilder(LOCATOR, executable).start();
//             List<String> output = IOUtils.readLines(process.getInputStream(), Charset.defaultCharset());
//             if (process.waitFor() != 0) {
//                 return null;
//             }
//             return output.isEmpty() ? null : output.get(0);
//         } catch (IOException | InterruptedException e) {
//             return null;
//         }
//     }
// 
//     public static Matcher<String> executable() {
//         return new CustomTypeSafeMatcher<String>("executable") {
//             @Override
//             protected boolean matchesSafely(String item) {
//                 try {
//                     return new ProcessBuilder(LOCATOR, item).start().waitFor() == 0;
//                 } catch (InterruptedException | IOException e) {
//                     return false;
//                 }
//             }
//         };
//     }
// }
// 
// Path: src/test/java/org/jenkinsci/plugins/credentialsbinding/test/Executables.java
// public static Matcher<String> executable() {
//     return new CustomTypeSafeMatcher<String>("executable") {
//         @Override
//         protected boolean matchesSafely(String item) {
//             try {
//                 return new ProcessBuilder(LOCATOR, item).start().waitFor() == 0;
//             } catch (InterruptedException | IOException e) {
//                 return false;
//             }
//         }
//     };
// }


// Path: src/test/java/org/jenkinsci/plugins/credentialsbinding/masking/BashSecretPatternFactoryTest.java
import hudson.tasks.Shell;
import org.jenkinsci.plugins.credentialsbinding.test.CredentialsTestUtil;
import org.jenkinsci.plugins.credentialsbinding.test.Executables;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import org.jvnet.hudson.test.JenkinsRule;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.jenkinsci.plugins.credentialsbinding.test.Executables.executable;
import static org.junit.Assume.assumeThat;

        List<String> passwords = new ArrayList<>(10);
        for (int i = 0; i < 10; i++) {
            int length = random.nextInt(24) + 8;
            StringBuilder sb = new StringBuilder(length);
            for (int j = 0; j < length; j++) {
                // choose a (printable) character in the closed range [' ', '~']
                // 0x7f is DEL, 0x7e is ~, and space is the first printable ASCII character
                char next = (char) (' ' + random.nextInt('\u007f' - ' '));
                sb.append(next);
            }
            passwords.add(sb.toString());
        }
        return passwords;
    }

    @ClassRule public static JenkinsRule j = new JenkinsRule();

    private WorkflowJob project;
    private String credentialsId;

    @BeforeClass
    public static void assumeBash() {
        assumeThat("bash", is(executable()));
        // due to https://github.com/jenkinsci/durable-task-plugin/blob/e75123eda986f20a390d92cc892c3d206e60aefb/src/main/java/org/jenkinsci/plugins/durabletask/BourneShellScript.java#L149
        // on Windows
        assumeThat("nohup", is(executable()));
    }

    @Before
    public void setUp() throws IOException {
        j.jenkins.getDescriptorByType(Shell.DescriptorImpl.class).setShell(Executables.getPathToExecutable("bash"));