Skip to content

Commit

Permalink
test-case to demonstrate casc-support
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Nov 16, 2018
1 parent 7308909 commit 5672265
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@
<artifactId>credentials</artifactId>
<version>2.1.5</version>
</dependency>

<dependency>
<groupId>io.jenkins</groupId>
<artifactId>configuration-as-code</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jenkins.configuration-as-code</groupId>
<artifactId>configuration-as-code-support</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
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()));
}
}
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==

0 comments on commit 5672265

Please sign in to comment.