// 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 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 org.jenkinsci.plugins.credentialsbinding.test.CredentialsTestUtil;
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.Rule;
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;
/*
 * The MIT License
 *
 * Copyright (c) 2019 CloudBees, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.jenkinsci.plugins.credentialsbinding.masking;




@RunWith(Theories.class)
public class BourneShellSecretPatternFactoryTest {

    public static final @DataPoint String SAMPLE_PASSWORD = "}#T14'GAz&H!{$U_";
    public static final @DataPoint String ANOTHER_SAMPLE_PASSWORD = "a'b\"c\\d(e)#";

    @DataPoints
    public static List<String> generatePasswords() {
        Random random = new Random(100);
        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++) {
                char next = (char) (random.nextInt('~' - ' ' + 1) + ' '); // space = 0x20, tilde = 0x7E
                sb.append(next);
            }
            passwords.add(sb.toString());
        }
        return passwords;
    }

    @Rule public JenkinsRule j = new JenkinsRule();

    private WorkflowJob project;
    private String credentialsId;

    @BeforeClass
    public static void assumeBash() {
// 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 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/BourneShellSecretPatternFactoryTest.java
import org.jenkinsci.plugins.credentialsbinding.test.CredentialsTestUtil;
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.Rule;
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;

/*
 * The MIT License
 *
 * Copyright (c) 2019 CloudBees, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.jenkinsci.plugins.credentialsbinding.masking;




@RunWith(Theories.class)
public class BourneShellSecretPatternFactoryTest {

    public static final @DataPoint String SAMPLE_PASSWORD = "}#T14'GAz&H!{$U_";
    public static final @DataPoint String ANOTHER_SAMPLE_PASSWORD = "a'b\"c\\d(e)#";

    @DataPoints
    public static List<String> generatePasswords() {
        Random random = new Random(100);
        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++) {
                char next = (char) (random.nextInt('~' - ' ' + 1) + ' '); // space = 0x20, tilde = 0x7E
                sb.append(next);
            }
            passwords.add(sb.toString());
        }
        return passwords;
    }

    @Rule public JenkinsRule j = new JenkinsRule();

    private WorkflowJob project;
    private String credentialsId;

    @BeforeClass
    public static void assumeBash() {
        assumeThat("sh", is(executable()));