Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Nov 19, 2024
1 parent 4717505 commit dd5c732
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public void deleteSecret(String id) {

}

public Secret getSecret(String name) {
List<Credentials> credentials = SystemCredentialsProvider.getInstance().getCredentials();
for (Credentials credential : credentials) {
if (credential instanceof StringCredentialsImpl && ((StringCredentialsImpl) credential).getId().equals(name)) {
return ((StringCredentialsImpl) credential).getSecret();
}
}
return null;
}

public boolean secretExists(String name) {
List<Credentials> credentials = SystemCredentialsProvider.getInstance().getCredentials();
for (Credentials credential : credentials) {
Expand Down
39 changes: 20 additions & 19 deletions src/test/java/io/jenkins/plugins/jfrog/CliEnvConfiguratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hudson.EnvVars;
import io.jenkins.plugins.jfrog.actions.JFrogCliConfigEncryption;
import io.jenkins.plugins.jfrog.configuration.JenkinsProxyConfiguration;
import io.jenkins.plugins.jfrog.configuration.JenkinsSecretManager;
import jenkins.model.Jenkins;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -39,26 +40,26 @@ public void configureCliEnvBasicTest() {
assertEnv(envVars, JFROG_CLI_HOME_DIR, "a/b/c");
}

// @Test
// public void configEncryptionTest() {
// JFrogCliConfigEncryption configEncryption = new JFrogCliConfigEncryption(envVars);
// assertTrue(configEncryption.shouldEncrypt());
// assertEquals(32, configEncryption.getKey().length());
//
// invokeConfigureCliEnv("a/b/c", configEncryption);
// assertEnv(envVars, JFROG_CLI_ENCRYPTION_KEY, configEncryption.getKey());
// }
@Test
public void configEncryptionTest() {
JFrogCliConfigEncryption configEncryption = new JFrogCliConfigEncryption(envVars);
assertTrue(configEncryption.shouldEncrypt());
assertEquals(32, configEncryption.getKey().length());

invokeConfigureCliEnv("a/b/c", configEncryption);
assertEquals(configEncryption.getKey(), new JenkinsSecretManager().getSecret(JFROG_CLI_ENCRYPTION_KEY).getPlainText());
}

// @Test
// public void configEncryptionWithHomeDirTest() {
// // Config JFROG_CLI_HOME_DIR to disable key encryption
// envVars.put(JFROG_CLI_HOME_DIR, "/a/b/c");
// JFrogCliConfigEncryption configEncryption = new JFrogCliConfigEncryption(envVars);
// invokeConfigureCliEnv("", configEncryption);
//
// assertFalse(configEncryption.shouldEncrypt());
// assertFalse(envVars.containsKey(JFROG_CLI_ENCRYPTION_KEY));
// }
@Test
public void configEncryptionWithHomeDirTest() {
// Config JFROG_CLI_HOME_DIR to disable key encryption
envVars.put(JFROG_CLI_HOME_DIR, "/a/b/c");
JFrogCliConfigEncryption configEncryption = new JFrogCliConfigEncryption(envVars);
invokeConfigureCliEnv("", configEncryption);

assertFalse(configEncryption.shouldEncrypt());
assertNull(new JenkinsSecretManager().getSecret(JFROG_CLI_ENCRYPTION_KEY));
}

void assertEnv(EnvVars envVars, String key, String expectedValue) {
assertEquals(expectedValue, envVars.get(key));
Expand Down

0 comments on commit dd5c732

Please sign in to comment.