outContent.reset();
KnoxCLI cli = new KnoxCLI();
cli.setConf(config);
rc = cli.run(args);
assertThat( rc, is( 0 ) );
MasterService ms = cli.getGatewayServices().getService("MasterService");
String master = String.copyValueOf( ms.getMasterSecret() );
assertThat( master.length(), is( 36 ) );
assertThat( master.indexOf( '-' ), is( 8 ) );
assertThat( master.indexOf( '-', 9 ), is( 13 ) );
assertThat( master.indexOf( '-', 14 ), is( 18 ) );
assertThat( master.indexOf( '-', 19 ), is( 23 ) );
assertThat( UUID.fromString( master ), notNullValue() );
assertThat( outContent.toString(), containsString( "Master secret has been persisted to disk." ) );
// Need to delete the master file so that the change isn't ignored.
if( masterFile.exists() ) {
assertThat( "Failed to delete existing master file.", masterFile.delete(), is( true ) );
}
outContent.reset();
cli = new KnoxCLI();
rc = cli.run(args);
ms = cli.getGatewayServices().getService("MasterService");
String master2 = String.copyValueOf( ms.getMasterSecret() );
assertThat( master2.length(), is( 36 ) );
assertThat( UUID.fromString( master2 ), notNullValue() );
assertThat( master2, not( is( master ) ) );
assertThat( rc, is( 0 ) );
assertThat(outContent.toString(), containsString("Master secret has been persisted to disk."));