|
@@ -45,6 +45,7 @@ import static org.junit.Assert.assertArrayEquals;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.hadoop.conf.Configuration.IntegerRanges;
|
|
|
+import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
|
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.apache.hadoop.io.IOUtils;
|
|
|
import org.apache.hadoop.net.NetUtils;
|
|
@@ -73,6 +74,11 @@ public class TestConfiguration extends TestCase {
|
|
|
/** Four apostrophes. */
|
|
|
public static final String ESCAPED = "''''";
|
|
|
|
|
|
+ private static final String SENSITIVE_CONFIG_KEYS =
|
|
|
+ CommonConfigurationKeysPublic.HADOOP_SECURITY_SENSITIVE_CONFIG_KEYS;
|
|
|
+
|
|
|
+ private BufferedWriter out;
|
|
|
+
|
|
|
@Override
|
|
|
protected void setUp() throws Exception {
|
|
|
super.setUp();
|
|
@@ -81,6 +87,9 @@ public class TestConfiguration extends TestCase {
|
|
|
|
|
|
@Override
|
|
|
protected void tearDown() throws Exception {
|
|
|
+ if(out != null) {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
super.tearDown();
|
|
|
new File(CONFIG).delete();
|
|
|
new File(CONFIG2).delete();
|
|
@@ -464,8 +473,6 @@ public class TestConfiguration extends TestCase {
|
|
|
new File(new File(relConfig).getParent()).delete();
|
|
|
}
|
|
|
|
|
|
- BufferedWriter out;
|
|
|
-
|
|
|
public void testIntegerRanges() {
|
|
|
Configuration conf = new Configuration();
|
|
|
conf.set("first", "-100");
|
|
@@ -1327,8 +1334,41 @@ public class TestConfiguration extends TestCase {
|
|
|
assertEquals(fileResource.toString(),prop.getResource());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ public void testDumpSensitiveProperty() throws IOException {
|
|
|
+ final String myPassword = "ThisIsMyPassword";
|
|
|
+ Configuration testConf = new Configuration(false);
|
|
|
+ out = new BufferedWriter(new FileWriter(CONFIG));
|
|
|
+ startConfig();
|
|
|
+ appendProperty("test.password", myPassword);
|
|
|
+ endConfig();
|
|
|
+ Path fileResource = new Path(CONFIG);
|
|
|
+ testConf.addResource(fileResource);
|
|
|
+
|
|
|
+ try (StringWriter outWriter = new StringWriter()) {
|
|
|
+ testConf.set(SENSITIVE_CONFIG_KEYS, "password$");
|
|
|
+ Configuration.dumpConfiguration(testConf, "test.password", outWriter);
|
|
|
+ assertFalse(outWriter.toString().contains(myPassword));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testDumpSensitiveConfiguration() throws IOException {
|
|
|
+ final String myPassword = "ThisIsMyPassword";
|
|
|
+ Configuration testConf = new Configuration(false);
|
|
|
+ out = new BufferedWriter(new FileWriter(CONFIG));
|
|
|
+ startConfig();
|
|
|
+ appendProperty("test.password", myPassword);
|
|
|
+ endConfig();
|
|
|
+ Path fileResource = new Path(CONFIG);
|
|
|
+ testConf.addResource(fileResource);
|
|
|
+
|
|
|
+ try (StringWriter outWriter = new StringWriter()) {
|
|
|
+ testConf.set(SENSITIVE_CONFIG_KEYS, "password$");
|
|
|
+ Configuration.dumpConfiguration(testConf, outWriter);
|
|
|
+ assertFalse(outWriter.toString().contains(myPassword));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void testGetValByRegex() {
|
|
|
Configuration conf = new Configuration();
|
|
|
String key1 = "t.abc.key1";
|