-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from jglick/null-file-for-casc
Allow file to be null for JCasC
- Loading branch information
Showing
4 changed files
with
63 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/org/jenkinsci/plugins/plaincredentials/ConfigurationAsCodeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.jenkinsci.plugins.plaincredentials; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsMatchers; | ||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.domains.DomainRequirement; | ||
import hudson.security.ACL; | ||
import io.jenkins.plugins.casc.ConfigurationAsCode; | ||
import org.apache.commons.io.IOUtils; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
/** | ||
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a> | ||
*/ | ||
public class ConfigurationAsCodeTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void should_configure_file_credentials() throws Exception { | ||
ConfigurationAsCode.get().configure(getClass().getResource("ConfigurationAsCode.yaml").toString()); | ||
final FileCredentials credentials = CredentialsMatchers.firstOrNull( | ||
CredentialsProvider.lookupCredentials(FileCredentials.class, j.jenkins, ACL.SYSTEM, (DomainRequirement) null), | ||
CredentialsMatchers.withId("secret-file")); | ||
Assert.assertNotNull(credentials); | ||
Assert.assertEquals("Some secret file", credentials.getDescription()); | ||
Assert.assertEquals("my-secret-file", credentials.getFileName()); | ||
Assert.assertEquals("FOO_BAR", IOUtils.toString(credentials.getContent())); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/resources/org/jenkinsci/plugins/plaincredentials/ConfigurationAsCode.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
credentials: | ||
system: | ||
domainCredentials: | ||
# global credentials | ||
- credentials: | ||
- file: | ||
id: secret-file | ||
scope: SYSTEM | ||
description: "Some secret file" | ||
fileName: my-secret-file | ||
# FOO_BAR base64 encoded | ||
secretBytes: Rk9PX0JBUg== |