public class FileConfigurationParserTest extends UnitTestCase
{
public void testParsingDefaultServerConfig() throws Exception
{
FileConfigurationParser parser = new FileConfigurationParser();
String configStr = firstPart + lastPart;
ByteArrayInputStream input = new ByteArrayInputStream(configStr.getBytes("UTF-8"));
Configuration config = parser.parseMainConfig(input);
String clusterPassword = config.getClusterPassword();
assertEquals(ConfigurationImpl.DEFAULT_CLUSTER_PASSWORD, clusterPassword);
//if we add cluster-password, it should be default plain text
String clusterPasswordPart = "<cluster-password>helloworld</cluster-password>";
configStr = firstPart + clusterPasswordPart + lastPart;
config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes("UTF-8")));
assertEquals("helloworld", config.getClusterPassword());
//if we add mask, it should be able to decode correctly
DefaultSensitiveStringCodec codec = new DefaultSensitiveStringCodec();
String mask = (String)codec.encode("helloworld");
String maskPasswordPart = "<mask-password>true</mask-password>";
clusterPasswordPart = "<cluster-password>" + mask + "</cluster-password>";
configStr = firstPart + clusterPasswordPart + maskPasswordPart + lastPart;
config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes("UTF-8")));
assertEquals("helloworld", config.getClusterPassword());
//if we change key, it should be able to decode correctly
codec = new DefaultSensitiveStringCodec();
Map<String, String> prop = new HashMap<String, String>();
prop.put("key", "newkey");
codec.init(prop);
mask = (String)codec.encode("newpassword");
clusterPasswordPart = "<cluster-password>" + mask + "</cluster-password>";
String codecPart = "<password-codec>" + "org.hornetq.utils.DefaultSensitiveStringCodec" +
";key=newkey</password-codec>";
configStr = firstPart + clusterPasswordPart + maskPasswordPart + codecPart + lastPart;
config = parser.parseMainConfig(new ByteArrayInputStream(configStr.getBytes("UTF-8")));
assertEquals("newpassword", config.getClusterPassword());
}