From 70fba9c48387e93ee5ed2669c21f18fc9817eac7 Mon Sep 17 00:00:00 2001 From: James McMullan Date: Thu, 12 Sep 2024 08:27:30 -0400 Subject: [PATCH] HPCC4J-642 DFSClient FileUtilityTest failing due to credential prompting - Added a non-interactive flag to FileUtility - Updated FileUtilityTest to use the non-interactive flag Signed-off-by: James McMullan James.McMullan@lexisnexis.com --- .../java/org/hpccsystems/dfs/client/FileUtility.java | 12 +++++++++--- .../org/hpccsystems/dfs/client/FileUtilityTest.java | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java b/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java index 8389138d6..2aab0bd7b 100644 --- a/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java +++ b/dfsclient/src/main/java/org/hpccsystems/dfs/client/FileUtility.java @@ -335,9 +335,11 @@ private static String[] getCredentials(CommandLine cmd) { Console console = System.console(); + boolean nonInteractive = cmd.hasOption("non_interactive"); + String user = cmd.getOptionValue("user"); boolean userIsEmpty = user == null || user.isEmpty(); - if (userIsEmpty) + if (userIsEmpty && !nonInteractive) { user = new String(console.readLine("Enter username: ")); userIsEmpty = user == null || user.isEmpty(); @@ -345,7 +347,7 @@ private static String[] getCredentials(CommandLine cmd) String pass = cmd.getOptionValue("pass"); boolean passIsEmpty = pass == null || pass.isEmpty(); - if (!userIsEmpty && passIsEmpty) + if (!userIsEmpty && passIsEmpty & !nonInteractive) { pass = new String(console.readPassword("Enter password for " + user + ": ")); } @@ -642,6 +644,7 @@ private static Options getReadOptions() options.addOption("socket_timeout_seconds", true, "Sets the socket operation timeout in seconds."); options.addOption("connection_startup_limit", true, "Specifies the maximum number of connections to startup concurrently." + " useful in cases where starting up connections too quickly can overwhelm intermediate processes."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("read") .argName("files") @@ -672,6 +675,7 @@ private static Options getReadTestOptions() options.addOption("socket_timeout_seconds", true, "Sets the socket operation timeout in seconds."); options.addOption("connection_startup_limit", true, "Specifies the maximum number of connections to startup concurrently." + " useful in cases where starting up connections too quickly can overwhelm intermediate processes."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("file_parts") .argName("_file_parts") @@ -697,6 +701,7 @@ private static Options getCopyOptions() options.addOption("socket_timeout_seconds", true, "Sets the socket operation timeout in seconds."); options.addOption("connection_startup_limit", true, "Specifies the maximum number of connections to startup concurrently." + " useful in cases where starting up connections too quickly can overwhelm intermediate processes."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("copy") .argName("files") @@ -721,6 +726,7 @@ private static Options getWriteOptions() options.addOption("socket_timeout_seconds", true, "Sets the socket operation timeout in seconds."); options.addOption("connection_startup_limit", true, "Specifies the maximum number of connections to startup concurrently." + " useful in cases where starting up connections too quickly can overwhelm intermediate processes."); + options.addOption("non_interactive", false, "Disables prompting for credentials if they are not provided."); options.addOption(Option.builder("write") .argName("files") @@ -2280,4 +2286,4 @@ public static void main(String[] args) return; } -} +} diff --git a/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java b/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java index f62c3d39a..eeb068b8e 100644 --- a/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java +++ b/dfsclient/src/test/java/org/hpccsystems/dfs/client/FileUtilityTest.java @@ -46,7 +46,7 @@ public void thorFileTests() { { String readArgs[] = {"-read", "benchmark::integer::20kb", "-url", this.connString, - "-format", "thor", "-user", this.hpccUser, "-pass", this.hpccPass }; + "-format", "thor", "-user", this.hpccUser, "-pass", this.hpccPass, "-non_interactive" }; JSONArray results = FileUtility.run(readArgs); JSONObject result = results.optJSONObject(0); @@ -58,7 +58,7 @@ public void thorFileTests() { String readArgs[] = {"-read_test", "benchmark::integer::20kb", "-url", this.connString, - "-user", this.hpccUser, "-pass", this.hpccPass, "-file_parts", "1" }; + "-user", this.hpccUser, "-pass", this.hpccPass, "-file_parts", "1", "-non_interactive" }; JSONArray results = FileUtility.run(readArgs); JSONObject result = results.optJSONObject(0); @@ -72,7 +72,7 @@ public void thorFileTests() String copyArgs[] = {"-copy", "benchmark::integer::20kb benchmark::integer::20kb-copy", "-url", this.connString, "-dest_url", this.connString, "-dest_cluster", this.thorClusterFileGroup, - "-user", this.hpccUser, "-pass", this.hpccPass }; + "-user", this.hpccUser, "-pass", this.hpccPass, "-non_interactive" }; JSONArray results = FileUtility.run(copyArgs); JSONObject result = results.optJSONObject(0); @@ -87,7 +87,7 @@ public void thorFileTests() String writeArgs[] = {"-write", localDir + "benchmark__integer__20kb* benchmark::integer::20kb_write", "-url", this.connString, "-dest_url", this.connString, "-dest_cluster", this.thorClusterFileGroup, - "-user", this.hpccUser, "-pass", this.hpccPass }; + "-user", this.hpccUser, "-pass", this.hpccPass, "-non_interactive" }; JSONArray results = FileUtility.run(writeArgs); JSONObject result = results.optJSONObject(0);