Skip to content

Commit

Permalink
[JENKINS-41760] Reproduced bad output in test: blank (but not empty) …
Browse files Browse the repository at this point in the history
…creds for freestyle; blank or empty for Pipeline.
  • Loading branch information
jglick committed Aug 8, 2017
1 parent b141c6f commit f982299
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Expand Up @@ -80,6 +80,7 @@
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.*;
import org.junit.ClassRule;
import org.junit.Ignore;

import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -428,6 +429,21 @@ public void testTrackingOfCredential() {
});
}

@Ignore("TODO")
@Issue("JENKINS-41760")
@Test public void emptyOrBlankCreds() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {withCredentials([]) {echo 'normal output'}}", true));
story.j.assertLogContains("normal output", story.j.buildAndAssertSuccess(p));
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", null, Secret.fromString("")));
p.setDefinition(new CpsFlowDefinition("node {withCredentials([string(variable: 'SECRET', credentialsId: 'creds')]) {echo 'normal output'}}", true));
story.j.assertLogContains("normal output", story.j.buildAndAssertSuccess(p));
}
});
}

private static Set<String> grep(File dir, String text) throws IOException {
Set<String> matches = new TreeSet<String>();
grep(dir, text, "", matches);
Expand Down
Expand Up @@ -44,9 +44,13 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.jvnet.hudson.test.BuildWatcher;

public class SecretBuildWrapperTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public JenkinsRule r = new JenkinsRule();

@Issue("JENKINS-24805")
Expand Down Expand Up @@ -96,4 +100,15 @@ public class SecretBuildWrapperTest {
FreeStyleBuild b = r.buildAndAssertSuccess(f);
r.assertLogContains("PASSES", b);
}

@Ignore("TODO")
@Issue("JENKINS-41760")
@Test public void emptySecret() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), new StringCredentialsImpl(CredentialsScope.GLOBAL, "creds", null, Secret.fromString("")));
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.singletonList(new StringBinding("SECRET", "creds"))));
p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo PASSES") : new Shell("echo PASSES"));
r.assertLogContains("PASSES", r.buildAndAssertSuccess(p));
}

}

0 comments on commit f982299

Please sign in to comment.