Skip to content
This repository was archived by the owner on Jul 6, 2023. It is now read-only.

Commit 3404687

Browse files
voutiladpontusmelke
authored andcommitted
Check non-interactive cli arg before checking tty
Lots of checks are done if stdin is connected to a tty and somewhere in the mess of logic a check doesn't work properly (at least on Linux) when using --non-interactive via a shell. For instance, if the user account requires a password being changed, it still prompts the user. This checks the cli arg first before bothering to check the System.console() / isatty() results. This trickles down to checks again during the initial exception handling AuthenticationException or Neo4jException handling.
1 parent f4155f5 commit 3404687

File tree

1 file changed

+7
-3
lines changed
  • cypher-shell/src/main/java/org/neo4j/shell

1 file changed

+7
-3
lines changed

cypher-shell/src/main/java/org/neo4j/shell/Main.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,18 @@ int runShell(@Nonnull CliArgs cliArgs, @Nonnull CypherShell shell, Logger logger
104104
if ( cliArgs.getCypher().isPresent() )
105105
{
106106
// Can only prompt for password if input has not been redirected
107-
connectMaybeInteractively( shell, connectionConfig, isInputInteractive(), isOutputInteractive(),
107+
connectMaybeInteractively( shell, connectionConfig,
108+
!cliArgs.getNonInteractive() && isInputInteractive(),
109+
!cliArgs.getNonInteractive() && isOutputInteractive(),
108110
() -> shell.execute( cliArgs.getCypher().get() ) );
109111
return EXIT_SUCCESS;
110112
}
111113
else
112114
{
113115
// Can only prompt for password if input has not been redirected
114-
connectMaybeInteractively( shell, connectionConfig, isInputInteractive(), isOutputInteractive());
116+
connectMaybeInteractively( shell, connectionConfig,
117+
!cliArgs.getNonInteractive() && isInputInteractive(),
118+
!cliArgs.getNonInteractive() && isOutputInteractive());
115119
// Construct shellrunner after connecting, due to interrupt handling
116120
ShellRunner shellRunner = ShellRunner.getShellRunner( cliArgs, shell, logger, connectionConfig );
117121
CommandHelper commandHelper = new CommandHelper( logger, shellRunner.getHistorian(), shell );
@@ -173,7 +177,7 @@ private void connectMaybeInteractively( @Nonnull CypherShell shell,
173177
promptForUsernameAndPassword(connectionConfig, outputInteractive);
174178
didPrompt = true;
175179
} catch (Neo4jException e) {
176-
if (isPasswordChangeRequiredException(e)) {
180+
if (inputInteractive && isPasswordChangeRequiredException(e)) {
177181
promptForPasswordChange(connectionConfig, outputInteractive);
178182
shell.changePassword(connectionConfig);
179183
didPrompt = true;

0 commit comments

Comments
 (0)