Skip to content

Commit

Permalink
Improve error message of set-initial-password
Browse files Browse the repository at this point in the history
  • Loading branch information
Lojjs committed Sep 20, 2018
1 parent 910eb1b commit 4d2d67c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Expand Up @@ -81,9 +81,13 @@ public void execute( String[] args ) throws IncorrectUsage, CommandFailed
private void setPassword( String password ) throws Throwable
{
Config config = loadNeo4jConfig();
if ( realUsersExist( config ) )
File authFile = CommunitySecurityModule.getUserRepositoryFile( config );

if ( realUsersExist( authFile ) )
{
throw new CommandFailed( "initial password was not set because live Neo4j-users were detected." );
throw new CommandFailed( "the provided initial password was not set because existing Neo4j users were detected at `" +
authFile.getAbsolutePath() + "`. Please remove the existing `auth` and `roles` files if you want to reset your database " +
"to only have a default user with the provided password." );
}
else
{
Expand All @@ -107,9 +111,8 @@ private void setPassword( String password ) throws Throwable
}
}

private boolean realUsersExist( Config config )
private boolean realUsersExist( File authFile )
{
File authFile = CommunitySecurityModule.getUserRepositoryFile( config );
return outsideWorld.fileSystem().fileExists( authFile );
}

Expand Down
Expand Up @@ -151,7 +151,9 @@ public void shouldErrorIfRealUsersAlreadyExist() throws Throwable
// Then
assertNoAuthIniFile();
verify( out, times( 1 ) )
.stdErrLine( "command failed: initial password was not set because live Neo4j-users were detected." );
.stdErrLine( "command failed: the provided initial password was not set because existing Neo4j users were " +
"detected at `" + authFile.getAbsolutePath() + "`. Please remove the existing `auth` and `roles` files if you " +
"want to reset your database to only have a default user with the provided password." );
verify( out ).exit( 1 );
verify( out, times( 0 ) ).stdOutLine( anyString() );
}
Expand Down

0 comments on commit 4d2d67c

Please sign in to comment.