You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2013/06/14 02:37:22 UTC
svn commit: r1492916 [2/2] - in /incubator/ambari/trunk: ./ ambari-project/
ambari-server/ ambari-server/sbin/
ambari-server/src/main/java/org/apache/ambari/server/configuration/
ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-s...
Added: incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/security/encryption/MasterKeyServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/security/encryption/MasterKeyServiceTest.java?rev=1492916&view=auto
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/security/encryption/MasterKeyServiceTest.java (added)
+++ incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/security/encryption/MasterKeyServiceTest.java Fri Jun 14 00:37:22 2013
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ambari.server.security.encryption;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.ambari.server.configuration.Configuration;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import static org.easymock.EasyMock.expect;
+import static org.powermock.api.easymock.PowerMock.mockStatic;
+import static org.powermock.api.easymock.PowerMock.replayAll;
+import static org.powermock.api.easymock.PowerMock.verifyAll;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("javax.crypto.*")
+@PrepareForTest({ MasterKeyServiceImpl.class })
+public class MasterKeyServiceTest extends TestCase {
+ @Rule
+ public TemporaryFolder tmpFolder = new TemporaryFolder();
+ private String fileDir;
+ private static final Log LOG = LogFactory.getLog
+ (CredentialStoreServiceTest.class);
+
+ @Override
+ protected void setUp() throws Exception {
+ tmpFolder.create();
+ fileDir = tmpFolder.newFolder("keys").getAbsolutePath();
+ LOG.info("Setting temp folder to: " + fileDir);
+ }
+
+ @Test
+ public void testInitiliazeMasterKey() throws Exception {
+ MasterKeyService ms = new MasterKeyServiceImpl("ThisisSomePassPhrase",
+ fileDir + File.separator + "master", true);
+ Assert.assertTrue(ms.isMasterKeyInitialized());
+ File f = new File(fileDir + File.separator + "master");
+ Assert.assertTrue(f.exists());
+ // Re-initialize master from file
+ MasterKeyService ms1 = new MasterKeyServiceImpl(fileDir + File.separator
+ + "master", true);
+ Assert.assertTrue(ms1.isMasterKeyInitialized());
+ Assert.assertEquals("ThisisSomePassPhrase", new String(ms1.getMasterSecret
+ ()));
+ }
+
+ @Test
+ public void testReadFromEnv() throws Exception {
+ Map<String, String> mapRet = new HashMap<String, String>();
+ mapRet.put(Configuration.MASTER_KEY_ENV_PROP, "ThisisSomePassPhrase");
+ mockStatic(System.class);
+ expect(System.getenv()).andReturn(mapRet);
+ replayAll();
+ MasterKeyService ms = new MasterKeyServiceImpl();
+ verifyAll();
+ Assert.assertTrue(ms.isMasterKeyInitialized());
+ Assert.assertNotNull(ms.getMasterSecret());
+ Assert.assertEquals("ThisisSomePassPhrase",
+ new String(ms.getMasterSecret()));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ tmpFolder.delete();
+ }
+
+}
Modified: incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py?rev=1492916&r1=1492915&r2=1492916&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py (original)
+++ incubator/ambari/trunk/ambari-server/src/test/python/TestAmbaryServer.py Fri Jun 14 00:37:22 2013
@@ -91,7 +91,7 @@ class TestAmbariServer(TestCase):
@patch('__builtin__.raw_input')
- def test_get_choice_string_input(self, raw_input_method):
+ def get_choice_string_input(self, raw_input_method):
prompt = "blablabla"
default = "default blablabla"
firstChoice = set(['yes','ye', 'y'])
@@ -141,7 +141,7 @@ class TestAmbariServer(TestCase):
@patch('re.search')
@patch('__builtin__.raw_input')
@patch('getpass.getpass')
- def test_get_validated_string_input(self, get_pass_method,
+ def get_validated_string_input(self, get_pass_method,
raw_input_method, re_search_method):
prompt = "blabla"
default = "default_pass"
@@ -1093,15 +1093,15 @@ class TestAmbariServer(TestCase):
self.assertEqual(None, rcode)
self.assertTrue(setup_db_mock.called)
-
+ @patch.object(ambari_server, "get_ambari_properties")
@patch("os.kill")
@patch("os.path.exists")
@patch("__builtin__.open")
@patch("subprocess.Popen")
@patch.object(ambari_server, "print_info_msg")
- @patch.object(ambari_server, "get_conf_dir")
+ @patch.object(ambari_server, "search_file")
@patch.object(ambari_server, "find_jdk")
@patch.object(ambari_server, "print_error_msg")
@patch.object(ambari_server, "check_postgre_up")
@@ -1113,14 +1113,16 @@ class TestAmbariServer(TestCase):
@patch("os.chdir")
def test_start(self, chdir_mock, getuser_mock, is_root_mock, read_ambari_user_mock,
parse_properties_file_mock, check_iptables_mock, check_postgre_up_mock,
- print_error_msg_mock, find_jdk_mock, get_conf_dir_mock,
+ print_error_msg_mock, find_jdk_mock, search_file_mock,
print_info_msg_mock, popenMock, openMock, pexistsMock,
- killMock):
+ killMock, get_ambari_properties_mock):
args = MagicMock()
f = MagicMock()
f.readline.return_value = 42
openMock.return_value = f
+ get_ambari_properties_mock.return_value = \
+ {ambari_server.SECURITY_KEY_IS_PERSISTED : "True"}
# Checking "server is running"
pexistsMock.return_value = True
@@ -1578,7 +1580,7 @@ class TestAmbariServer(TestCase):
@patch.object(ambari_server, "print_warning_msg")
@patch('__builtin__.raw_input')
@patch("sys.exit")
- def test_check_jdbc_drivers(self, exit_mock, raw_input_mock, print_warning_msg, print_error_msg_mock, copy_files_mock,
+ def check_jdbc_drivers(self, exit_mock, raw_input_mock, print_warning_msg, print_error_msg_mock, copy_files_mock,
find_jdbc_driver_mock, get_ambari_properties_mock):
out = StringIO.StringIO()