-
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.
test-case to demonstrate casc-support
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
package org.jenkinsci.plugins.plaincredentials; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsMatchers; | ||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.SecretBytes; | ||
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 { | ||
SecretBytes.decrypt(null); // force class loading to get Stapler converter registered | ||
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== |