-
Notifications
You must be signed in to change notification settings - Fork 37
allow file to be null for use in CasC #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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== |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not look right. You are referring to
SecretBytes.StaplerConverterImpl
? I am not sure what normally causes it to be registered, but if it is not being registered implicitly by the rest of the test case, something is broken and that needs to be fixed first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why it doesn't get loaded, static initializer isn't executed as demonstrated running with a debugger. No idea what could go wrong here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this code, the converter is used by virtue of its class name. That would mean that the abovementioned line could be deleted and the test would still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And jenkinsci/configuration-as-code-plugin#317 does not have such a trick, so…?