Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
EyalDelarea committed Nov 14, 2024
1 parent 4bb0c5a commit 9b974af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/main/java/io/jenkins/plugins/jfrog/JfStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
@SuppressWarnings("unused")
public class JfStep extends Builder implements SimpleBuildStep {
private final ObjectMapper mapper = createMapper();
private static final Version MIN_CLI_VERSION_PASSWORD_STDIN = new Version("2.31.3");
static final Version MIN_CLI_VERSION_PASSWORD_STDIN = new Version("2.31.3");
static final String STEP_NAME = "jf";

protected String[] args;
Expand Down Expand Up @@ -375,15 +375,17 @@ Version getJfrogCliVersion(Launcher.ProcStarter launcher) throws IOException, In
* @param launcher The command launcher.
* @return true if stdin-based password handling is supported; false otherwise.
*/
private boolean isPasswordStdSupported(FilePath workspace, EnvVars env, Launcher launcher) throws IOException, InterruptedException {
public boolean isPasswordStdSupported(FilePath workspace, EnvVars env, Launcher launcher) throws IOException, InterruptedException {
// Determine if the launcher is a plugin (custom) launcher
boolean isPluginLauncher = launcher.getClass().getName().contains("org.jenkinsci.plugins");
if (isPluginLauncher) {
return false;
}
// Check CLI version
Launcher.ProcStarter procStarter = launcher.launch().envs(env).pwd(workspace);
this.currentCliVersion = getJfrogCliVersion(procStarter);
if (this.currentCliVersion == null) {
this.currentCliVersion = getJfrogCliVersion(procStarter);
}
return this.currentCliVersion.isAtLeast(MIN_CLI_VERSION_PASSWORD_STDIN);
}
}
7 changes: 4 additions & 3 deletions src/test/java/io/jenkins/plugins/jfrog/JfStepTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.util.stream.Stream;

import static io.jenkins.plugins.jfrog.JfStep.MIN_CLI_VERSION_PASSWORD_STDIN;
import static io.jenkins.plugins.jfrog.JfStep.getJFrogCLIPath;
import static io.jenkins.plugins.jfrog.JfrogInstallation.JFROG_BINARY_PATH;
import static org.junit.jupiter.api.Assertions.*;
Expand Down Expand Up @@ -90,7 +91,7 @@ void getJfrogCliVersionTest() throws IOException, InterruptedException {
*/
@ParameterizedTest
@MethodSource("provideTestArguments")
void testAddCredentialsArguments(String cliVersion, boolean isPluginLauncher, String expectedOutput) throws IOException {
void testAddCredentialsArguments(String cliVersion, boolean isPluginLauncher, String expectedOutput) throws IOException, InterruptedException {
// Mock the necessary objects
JFrogPlatformInstance jfrogPlatformInstance = mock(JFrogPlatformInstance.class);
CredentialsConfig credentialsConfig = mock(CredentialsConfig.class);
Expand All @@ -103,9 +104,9 @@ void testAddCredentialsArguments(String cliVersion, boolean isPluginLauncher, St

// Create an instance of JfStep
JfStep jfStep = new JfStep("Mock Test");
// Mock CLI version
jfStep.currentCliVersion = new Version(cliVersion);
jfStep.isPluginLauncher = isPluginLauncher;

jfStep.usePasswordFromStdin = jfStep.currentCliVersion.isAtLeast(MIN_CLI_VERSION_PASSWORD_STDIN) && !isPluginLauncher;

// Create an ArgumentListBuilder
ArgumentListBuilder builder = new ArgumentListBuilder();
Expand Down

0 comments on commit 9b974af

Please sign in to comment.