@@ -118,7 +118,7 @@ private void ensureDefaultDatabaseStarted() throws Exception {
118118 cliArgs .setPassword ("neo" , "" );
119119 cliArgs .setDatabase ("system" );
120120 ShellAndConnection sac = getShell (cliArgs );
121- main .connectMaybeInteractively (sac .shell , sac .connectionConfig , true , false );
121+ main .connectMaybeInteractively (sac .shell , sac .connectionConfig , true , false , true );
122122 sac .shell .execute ("START DATABASE " + DatabaseManager .DEFAULT_DEFAULT_DB_NAME );
123123 }
124124
@@ -128,7 +128,7 @@ public void promptsOnWrongAuthenticationIfInteractive() throws Exception {
128128 assertEquals ("" , connectionConfig .username ());
129129 assertEquals ("" , connectionConfig .password ());
130130
131- main .connectMaybeInteractively (shell , connectionConfig , true , true );
131+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
132132
133133 // then
134134 // should be connected
@@ -150,7 +150,7 @@ public void promptsOnPasswordChangeRequired() throws Exception {
150150 // when
151151 inputBuffer .put (String .format ("foo%npass%nnewpass%n" ).getBytes ());
152152 baos .reset ();
153- main .connectMaybeInteractively (shell , connectionConfig , true , true );
153+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
154154
155155 // then
156156 assertTrue (shell .isConnected ());
@@ -233,6 +233,23 @@ public void shouldBePromptedIfRunningNonInteractiveCypherThatDoesntUpdatePasswor
233233 "foo" , "pass2" , "RETURN 42 AS n" ) ) );
234234 }
235235
236+ @ Test
237+ public void shouldNotBePromptedIfRunningWithExplicitNonInteractiveCypherThatDoesntUpdatePassword () throws Exception {
238+ //given a user that require a password change
239+ int majorVersion = getVersionAndCreateUserWithPasswordChangeRequired ();
240+
241+ //when
242+ assumeTrue ( majorVersion >= 4 );
243+
244+ //when interactively asked for a password use this
245+ inputBuffer .put ( String .format ( "pass2%n" ).getBytes () );
246+ baos .reset ();
247+ CliArgs args = args ( DEFAULT_DEFAULT_DB_NAME , "foo" , "pass" ,
248+ "MATCH (n) RETURN n" );
249+ args .setNonInteractive ( true );
250+ assertEquals ( EXIT_FAILURE , main .runShell ( args , shell , mock ( Logger .class ) ) );
251+ }
252+
236253 @ Test
237254 public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected () throws Exception {
238255 // when
@@ -248,7 +265,7 @@ public void doesNotPromptToStdOutOnWrongAuthenticationIfOutputRedirected() throw
248265 // Create a Main with the standard in and out
249266 try {
250267 Main realMain = new Main ();
251- realMain .connectMaybeInteractively (shell , connectionConfig , true , false );
268+ realMain .connectMaybeInteractively (shell , connectionConfig , true , false , true );
252269
253270 // then
254271 // should be connected
@@ -280,7 +297,7 @@ public void wrongPortWithBolt() throws Exception
280297
281298 exception .expect ( ServiceUnavailableException .class );
282299 exception .expectMessage ( "Unable to connect to localhost:1234, ensure the database is running and that there is a working network connection to it" );
283- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
300+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
284301 }
285302
286303 @ Test
@@ -297,7 +314,7 @@ public void wrongPortWithNeo4j() throws Exception
297314
298315 exception .expect ( ServiceUnavailableException .class );
299316 // The error message here may be subject to change and is not stable across versions so let us not assert on it
300- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
317+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
301318 }
302319
303320 @ Test
@@ -313,7 +330,7 @@ public void shouldAskForCredentialsWhenConnectingWithAFile() throws Exception {
313330 ShellAndConnection sac = getShell (cliArgs );
314331 CypherShell shell = sac .shell ;
315332 ConnectionConfig connectionConfig = sac .connectionConfig ;
316- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
333+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
317334
318335 // then we should have prompted and set the username and password
319336 assertEquals ( format ( "username: neo4j%npassword: ***%n" ), baos .toString () );
@@ -445,7 +462,7 @@ public void doesNotStartWhenDefaultDatabaseUnavailableIfInteractive() throws Exc
445462 assertEquals ("" , connectionConfig .password ());
446463
447464 // when
448- main .connectMaybeInteractively (shell , connectionConfig , true , true );
465+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
449466
450467 // Multiple databases are only available from 4.0
451468 assumeTrue ( majorVersion ( shell .getServerVersion () ) >= 4 );
@@ -469,7 +486,7 @@ public void doesNotStartWhenDefaultDatabaseUnavailableIfInteractive() throws Exc
469486 // Should get exception that database is unavailable when trying to connect
470487 exception .expect (TransientException .class );
471488 exception .expectMessage ("Database 'neo4j' is unavailable" );
472- main .connectMaybeInteractively (shell , connectionConfig , true , true );
489+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
473490
474491 // then
475492 assertFalse (shell .isConnected ());
@@ -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 );
@@ -574,7 +591,7 @@ public void switchingToUnavailableDefaultDatabaseIfInteractive() throws Exceptio
574591 assertEquals ("" , connectionConfig .password ());
575592
576593 // when
577- main .connectMaybeInteractively (shell , connectionConfig , true , true );
594+ main .connectMaybeInteractively (shell , connectionConfig , true , true , true );
578595
579596 // Multiple databases are only available from 4.0
580597 assumeTrue (majorVersion ( shell .getServerVersion () ) >= 4 );
@@ -638,7 +655,7 @@ private CypherShell interactiveShell( LinePrinter linePrinter ) throws Exception
638655 {
639656 PrettyConfig prettyConfig = new PrettyConfig ( new CliArgs () );
640657 CypherShell shell = new CypherShell ( linePrinter , prettyConfig , true , new ShellParameterMap () );
641- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
658+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
642659 shell .setCommandHelper ( new CommandHelper ( mock ( Logger .class ), Historian .empty , shell ) );
643660 return shell ;
644661 }
@@ -695,7 +712,7 @@ private CliArgs args(String db, String user, String pass, String cypher)
695712 private int getVersionAndCreateUserWithPasswordChangeRequired () throws Exception {
696713 shell .setCommandHelper ( new CommandHelper ( mock ( Logger .class ), Historian .empty , shell ) );
697714
698- main .connectMaybeInteractively ( shell , connectionConfig , true , true );
715+ main .connectMaybeInteractively ( shell , connectionConfig , true , true , true );
699716 String expectedLoginOutput = format ( "username: neo4j%npassword: ***%n" );
700717 assertEquals ( expectedLoginOutput , baos .toString () );
701718 ensureUser ();
0 commit comments