Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<useBeta>true</useBeta> <!-- FailureHandler -->
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
</properties>
<licenses>
<license>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,41 @@
import hudson.util.Secret;
import net.sf.json.JSONObject;
import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.kohsuke.stapler.StaplerRequest2;

import java.io.IOException;
import java.util.Collections;
import java.util.Map;

public class BuildWrapperOrderCredentialsBindingTest {
@WithJenkins
class BuildWrapperOrderCredentialsBindingTest {

private JenkinsRule r;

@Rule public JenkinsRule r = new JenkinsRule();
private static final String CREDENTIALS_ID = "creds_1";
private static final String PASSWORD = "p4ss";
private static final String BINDING_KEY = "PASS_1";

static String credentialsId = "creds_1";
static String password = "p4ss";
static String bindingKey = "PASS_1";
@BeforeEach
void beforeEach(JenkinsRule rule) {
r = rule;
}

@Issue("JENKINS-37871")
@Test public void secretBuildWrapperRunsBeforeNormalWrapper() throws Exception {
StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "sample1", Secret.fromString(password));
@Test
void secretBuildWrapperRunsBeforeNormalWrapper() throws Exception {
StringCredentialsImpl firstCreds = new StringCredentialsImpl(CredentialsScope.GLOBAL, CREDENTIALS_ID, "sample1", Secret.fromString(PASSWORD));

CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), firstCreds);

SecretBuildWrapper wrapper = new SecretBuildWrapper(Collections.singletonList(new StringBinding(bindingKey, credentialsId)));
SecretBuildWrapper wrapper = new SecretBuildWrapper(Collections.singletonList(new StringBinding(BINDING_KEY, CREDENTIALS_ID)));

FreeStyleProject f = r.createFreeStyleProject("buildWrapperOrder");

Expand All @@ -92,7 +101,7 @@ public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener l
// Lookup secret provided by SecretBuildWrapper.
// This only works if this BuildWrapper is executed AFTER the SecretBuildWrapper so the binding is already done.
for (Map.Entry<String, String> entry : env.entrySet()) {
if (entry.getKey().equals(bindingKey) && entry.getValue().equals(password)) {
if (entry.getKey().equals(BINDING_KEY) && entry.getValue().equals(PASSWORD)) {
listener.getLogger().format("Secret found!");
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import java.io.IOException;
Expand All @@ -46,12 +46,11 @@
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.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.BuildWatcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;

import org.jvnet.hudson.test.JenkinsRule;

import com.cloudbees.plugins.credentials.CredentialsProvider;
Expand All @@ -68,33 +67,37 @@
import hudson.model.Item;
import hudson.tasks.BatchFile;
import hudson.tasks.Shell;
import org.jvnet.hudson.test.junit.jupiter.BuildWatcherExtension;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;

public class CertificateMultiBindingTest {
@WithJenkins
class CertificateMultiBindingTest {

@ClassRule
public static BuildWatcher buildWatcher = new BuildWatcher();
@SuppressWarnings("unused")
@RegisterExtension
private static final BuildWatcherExtension BUILD_WATCHER = new BuildWatcherExtension();

@Rule
public JenkinsRule r = new JenkinsRule();
private JenkinsRule r;

@Rule
public TemporaryFolder tmp = new TemporaryFolder();
@TempDir
private File tmp;

File certificate;
private File certificate;

@Before
public void setUp() throws IOException {
@BeforeEach
void beforeEach(JenkinsRule rule) throws Exception {
r = rule;
/* do the dance to get a simple zip file into jenkins */
certificate = tmp.newFile("a.certificate");
certificate = newFile(tmp, "a.certificate");
final URL resource = this.getClass().getResource("certificate.p12");
assertThat(resource, is(not(nullValue())));
FileUtils.copyURLToFile(resource, certificate);
}

// TODO configRoundtrip to test form, null hygiene on @DataBoundSetter

Check warning on line 97 in src/test/java/org/jenkinsci/plugins/credentialsbinding/impl/CertificateMultiBindingTest.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: configRoundtrip to test form, null hygiene on @DataBoundSetter

@Test
public void basics() throws Exception {
@Test
void basics() throws Exception {
String alias = "androiddebugkey";
String password = "android";
StandardCertificateCredentials c = new CertificateCredentialsImpl(CredentialsScope.GLOBAL, null, alias,
Expand All @@ -108,22 +111,24 @@
.<MultiBinding<?>> singletonList(binding)));
if (Functions.isWindows()) {
p.getBuildersList().add(new BatchFile(
"echo | set /p=\"%alias%/%password%/\" > secrets.txt\r\n"
+ "IF EXIST \"%keystore%\" (\r\n"
+ "echo | set /p=\"exists\" >> secrets.txt\r\n"
+ ") ELSE (\r\n"
+ "echo | set /p=\"missing\" >> secrets.txt\r\n"
+ ")\r\n"
+ "exit 0"));
"""
echo | set /p="%alias%/%password%/" > secrets.txt\r
IF EXIST "%keystore%" (\r
echo | set /p="exists" >> secrets.txt\r
) ELSE (\r
echo | set /p="missing" >> secrets.txt\r
)\r
exit 0"""));
} else {
p.getBuildersList().add(new Shell(
"printf $alias/$password/ > secrets.txt\n"
+ "if [ -f \"$keystore\" ]\n"
+ "then\n"
+ "printf exists >> secrets.txt\n"
+ "else\n"
+ "printf missing >> secrets.txt\n"
+ "fi"));
"""
printf $alias/$password/ > secrets.txt
if [ -f "$keystore" ]
then
printf exists >> secrets.txt
else
printf missing >> secrets.txt
fi"""));
}
r.configRoundtrip((Item) p);
SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
Expand All @@ -142,8 +147,8 @@
assertThat(b.getSensitiveBuildVariables(), containsInAnyOrder("keystore", "password", "alias"));
}

@Test
public void basicsPipeline() throws Exception {
@Test
void basicsPipeline() throws Exception {
// create the Credentials
String alias = "androiddebugkey";
String password = "android";
Expand Down Expand Up @@ -186,4 +191,10 @@
}
}

private static File newFile(File parent, String child) throws IOException {
File result = new File(parent, child);
result.createNewFile();
return result;
}

}
Loading
Loading