@@ -120,7 +120,7 @@ private void ensureDefaultDatabaseStarted() throws Exception {
120120 cliArgs .setPassword ("neo" , "" );
121121 cliArgs .setDatabase ("system" );
122122 ShellAndConnection sac = getShell (cliArgs );
123- main .connectMaybeInteractively (sac .shell , sac .connectionConfig , true , false );
123+ main .connectMaybeInteractively (sac .shell , sac .connectionConfig , true , false , true );
124124 sac .shell .execute ("START DATABASE " + DatabaseManager .DEFAULT_DEFAULT_DB_NAME );
125125 }
126126
@@ -130,7 +130,7 @@ public void promptsOnWrongAuthenticationIfInteractive() throws Exception {
130130 assertEquals ("" , connectionConfig .username ());
131131 assertEquals ("" , connectionConfig .password ());
132132
133- main .connectMaybeInteractively (shell , connectionConfig , true , true );
133+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
134134
135135 // then
136136 // should be connected
@@ -152,7 +152,7 @@ public void promptsOnPasswordChangeRequired() throws Exception {
152152 // when
153153 inputBuffer .put (String .format ("foo%npass%nnewpass%n" ).getBytes ());
154154 baos .reset ();
155- main .connectMaybeInteractively (shell , connectionConfig , true , true );
155+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
156156
157157 // then
158158 assertTrue (shell .isConnected ());
@@ -235,6 +235,23 @@ public void shouldBePromptedIfRunningNonInteractiveCypherThatDoesntUpdatePasswor
235235 "foo" , "pass2" , "RETURN 42 AS n" ) ) );
236236 }
237237
238+ @ Test
239+ public void shouldNotBePromptedIfRunningWithExplicitNonInteractiveCypherThatDoesntUpdatePassword () throws Exception {
240+ //given a user that require a password change
241+ int majorVersion = getVersionAndCreateUserWithPasswordChangeRequired ();
242+
243+ //when
244+ assumeTrue ( majorVersion >= 4 );
245+
246+ //when interactively asked for a password use this
247+ inputBuffer .put ( String .format ( "pass2%n" ).getBytes () );
248+ baos .reset ();
249+ CliArgs args = args ( DEFAULT_DEFAULT_DB_NAME , "foo" , "pass" ,
250+ "MATCH (n) RETURN n" );
251+ args .setNonInteractive ( true );
252+ assertEquals ( EXIT_FAILURE , main .runShell ( args , shell , mock ( Logger .class ) ) );
253+ }
254+
238255 @ Test
239256 public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected () throws Exception {
240257 // when
@@ -250,7 +267,7 @@ public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected() throw
250267 // Create a Main with the standard in and out
251268 try {
252269 Main realMain = new Main ();
253- realMain .connectMaybeInteractively (shell , connectionConfig , true , false );
270+ realMain .connectMaybeInteractively (shell , connectionConfig , true , false , true );
254271
255272 // then
256273 // should be connected
@@ -282,7 +299,7 @@ public void wrongPortWithBolt() throws Exception
282299
283300 exception .expect ( ServiceUnavailableException .class );
284301 exception .expectMessage ( "Unable to connect to localhost:1234, ensure the database is running and that there is a working network connection to it" );
285- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
302+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
286303 }
287304
288305 @ Test
@@ -299,7 +316,7 @@ public void wrongPortWithNeo4j() throws Exception
299316
300317 exception .expect ( ServiceUnavailableException .class );
301318 // The error message here may be subject to change and is not stable across versions so let us not assert on it
302- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
319+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
303320 }
304321
305322 @ Test
@@ -315,7 +332,7 @@ public void shouldAskForCredentialsWhenConnectingWithAFile() throws Exception {
315332 ShellAndConnection sac = getShell (cliArgs );
316333 CypherShell shell = sac .shell ;
317334 ConnectionConfig connectionConfig = sac .connectionConfig ;
318- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
335+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
319336
320337 // then we should have prompted and set the username and password
321338 assertEquals ( format ( "username: neo4j%npassword: ***%n" ), baos .toString () );
@@ -447,7 +464,7 @@ public void doesNotStartWhenDefaultDatabaseUnavailableIfInteractive() throws Exc
447464 assertEquals ("" , connectionConfig .password ());
448465
449466 // when
450- main .connectMaybeInteractively (shell , connectionConfig , true , true );
467+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
451468
452469 // Multiple databases are only available from 4.0
453470 assumeTrue ( majorVersion ( shell .getServerVersion () ) >= 4 );
@@ -469,7 +486,7 @@ public void doesNotStartWhenDefaultDatabaseUnavailableIfInteractive() throws Exc
469486 shell .disconnect ();
470487
471488 // Should get exception that database is unavailable when trying to connect
472- main .connectMaybeInteractively (shell , connectionConfig , true , true );
489+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
473490 fail ("No exception thrown" );
474491 } catch (TransientException |ServiceUnavailableException e ) {
475492 expectDatabaseUnavailable (e , "neo4j" );
@@ -487,7 +504,7 @@ public void startsAgainstSystemDatabaseWhenDefaultDatabaseUnavailableIfInteracti
487504 assertEquals ("" , connectionConfig .password ());
488505
489506 // when
490- main .connectMaybeInteractively (shell , connectionConfig , true , true );
507+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
491508
492509 // Multiple databases are only available from 4.0
493510 assumeTrue ( majorVersion ( shell .getServerVersion () ) >= 4 );
@@ -517,7 +534,7 @@ public void startsAgainstSystemDatabaseWhenDefaultDatabaseUnavailableIfInteracti
517534 // Use the new shell and connection config from here on
518535 shell = sac .shell ;
519536 connectionConfig = sac .connectionConfig ;
520- main .connectMaybeInteractively (shell , connectionConfig , true , false );
537+ main .connectMaybeInteractively (shell , connectionConfig , true , false , true );
521538
522539 // then
523540 assertTrue (shell .isConnected ());
@@ -536,7 +553,7 @@ public void switchingToUnavailableDatabaseIfInteractive() throws Exception {
536553 assertEquals ("" , connectionConfig .password ());
537554
538555 // when
539- main .connectMaybeInteractively (shell , connectionConfig , true , true );
556+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
540557
541558 // Multiple databases are only available from 4.0
542559 assumeTrue (majorVersion ( shell .getServerVersion () ) >= 4 );
@@ -575,7 +592,7 @@ public void switchingToUnavailableDefaultDatabaseIfInteractive() throws Exceptio
575592 assertEquals ("" , connectionConfig .password ());
576593
577594 // when
578- main .connectMaybeInteractively (shell , connectionConfig , true , true );
595+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
579596
580597 // Multiple databases are only available from 4.0
581598 assumeTrue (majorVersion ( shell .getServerVersion () ) >= 4 );
@@ -648,7 +665,7 @@ private CypherShell interactiveShell( LinePrinter linePrinter ) throws Exception
648665 {
649666 PrettyConfig prettyConfig = new PrettyConfig ( new CliArgs () );
650667 CypherShell shell = new CypherShell ( linePrinter , prettyConfig , true , new ShellParameterMap () );
651- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
668+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
652669 shell .setCommandHelper ( new CommandHelper ( mock ( Logger .class ), Historian .empty , shell ) );
653670 return shell ;
654671 }
@@ -705,7 +722,7 @@ private CliArgs args(String db, String user, String pass, String cypher)
705722 private int getVersionAndCreateUserWithPasswordChangeRequired () throws Exception {
706723 shell .setCommandHelper ( new CommandHelper ( mock ( Logger .class ), Historian .empty , shell ) );
707724
708- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
725+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
709726 String expectedLoginOutput = format ( "username: neo4j%npassword: ***%n" );
710727 assertEquals ( expectedLoginOutput , baos .toString () );
711728 ensureUser ();
0 commit comments