incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject git commit: AMBARI-3780. Ambari password file should tolerate newlines. (swagle)
Date Fri, 15 Nov 2013 23:08:41 GMT
Updated Branches:
  refs/heads/trunk 8bd015a72 -> 05cb1b7d6


AMBARI-3780. Ambari password file should tolerate newlines. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/05cb1b7d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/05cb1b7d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/05cb1b7d

Branch: refs/heads/trunk
Commit: 05cb1b7d6f1e796b196994609cbac0710c86b224
Parents: 8bd015a
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Fri Nov 15 15:03:13 2013 -0800
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Fri Nov 15 15:08:10 2013 -0800

----------------------------------------------------------------------
 .../server/configuration/Configuration.java     |  3 ++-
 .../server/configuration/ConfigurationTest.java | 27 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/05cb1b7d/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
index 027f585..b92441b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/configuration/Configuration.java
@@ -27,6 +27,7 @@ import org.apache.ambari.server.security.encryption.CredentialProvider;
 import org.apache.ambari.server.utils.ShellCommandUtil;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.RandomStringUtils;
+import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import java.io.File;
@@ -649,6 +650,7 @@ public class Configuration {
       String password;
       try {
         password = FileUtils.readFileToString(new File(filePath));
+        password = StringUtils.chomp(password);
       } catch (IOException e) {
         throw new RuntimeException("Unable to read database password", e);
       }
@@ -848,5 +850,4 @@ public class Configuration {
     
     return value.split(",");
   }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/05cb1b7d/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
index 73552f3..8da66f4 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/configuration/ConfigurationTest.java
@@ -31,6 +31,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
 import org.junit.runner.RunWith;
 import org.powermock.api.easymock.PowerMock;
 import org.powermock.api.support.membermodification.MemberMatcher;
@@ -43,6 +44,8 @@ import static org.powermock.api.easymock.PowerMock.replayAll;
 import static org.powermock.api.easymock.PowerMock.verifyAll;
 
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.Map;
@@ -52,7 +55,7 @@ import java.util.Properties;
 @RunWith(PowerMockRunner.class)
 @PrepareForTest({ Configuration.class })
 public class ConfigurationTest {
-
+  public TemporaryFolder temp = new TemporaryFolder();
   private Injector injector;
 
   @Inject
@@ -62,10 +65,12 @@ public class ConfigurationTest {
   public void setup() throws Exception {
     injector = Guice.createInjector(new InMemoryDefaultTestModule());
     injector.injectMembers(this);
+    temp.create();
   }
 
   @After
   public void teardown() throws AmbariException {
+    temp.delete();
   }
 
   /**
@@ -206,6 +211,26 @@ public class ConfigurationTest {
     Configuration conf = new Configuration(ambariProperties);
     Assert.assertEquals(conf.getLocalDatabaseUrl(), Configuration.JDBC_LOCAL_URL.concat("ambaritestdatabase"));
   }
+
+  @Test
+  public void testNoNewlineInPassword() throws Exception {
+    Properties ambariProperties = new Properties();
+    File f = temp.newFile("password.dat");
+    FileOutputStream fos = new FileOutputStream(f);
+    fos.write("ambaritest\r\n".getBytes());
+    fos.close();
+    String passwordFile = temp.getRoot().getAbsolutePath()
+      + System.getProperty("file.separator") + "password.dat";
+
+    ambariProperties.setProperty(Configuration.SERVER_JDBC_USER_PASSWD_KEY,
+      passwordFile);
+
+    Configuration conf = new Configuration(ambariProperties);
+    PowerMock.stub(PowerMock.method(Configuration.class,
+      "readPasswordFromStore")).toReturn(null);
+
+    Assert.assertEquals("ambaritest", conf.getDatabasePassword());
+  }
   
   @Test
   public void testGetAmbariProperties() throws Exception {


Mime
View raw message