HelloMessage extends MessageWithMetadata { @Override public String toString() { Map<String,Value> metadataCopy = new HashMap<>( metadata() ); metadataCopy.replace( CREDENTIALS_KEY, value( "******" ) ); return "HELLO " + metadataCopy; } HelloMessage( String userAgent, Map<String,Value> authToken, Map<String,String> routingContext ); @Override byte signature(); @Override boolean equals( Object o ); @Override int hashCode(); @Override String toString(); final static byte SIGNATURE; }
@Test void shouldNotExposeCredentialsInToString() { Map<String,Value> authToken = new HashMap<>(); authToken.put( PRINCIPAL_KEY, value( "Alice" ) ); authToken.put( CREDENTIALS_KEY, value( "SecretPassword" ) ); HelloMessage message = new HelloMessage( "MyDriver/1.0.2", authToken, Collections.emptyMap() ); assertThat( message.toString(), not( containsString( "SecretPassword" ) ) ); }