ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rle...@apache.org
Subject ambari git commit: AMBARI-9244. JAAS configuration file parser leaves trailing quote in quoted values (rlevas)
Date Thu, 22 Jan 2015 02:09:49 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk e606c9d81 -> 2686976e8


AMBARI-9244. JAAS configuration file parser leaves trailing quote in quoted values (rlevas)


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

Branch: refs/heads/trunk
Commit: 2686976e85fbc9c701e6478f1f48b0b057d66579
Parents: e606c9d
Author: Robert Levas <rlevas@hortonworks.com>
Authored: Wed Jan 21 21:09:28 2015 -0500
Committer: Robert Levas <rlevas@hortonworks.com>
Committed: Wed Jan 21 21:09:28 2015 -0500

----------------------------------------------------------------------
 .../resource_management/TestSecurityCommons.py  | 49 ++++++++++++++++++++
 .../libraries/functions/security_commons.py     |  3 +-
 2 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/2686976e/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py b/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
index 196ae34..602b88b 100644
--- a/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
+++ b/ambari-agent/src/test/python/resource_management/TestSecurityCommons.py
@@ -21,6 +21,7 @@ from unittest import TestCase
 from resource_management.libraries.functions.security_commons import *
 from datetime import datetime, timedelta
 from tempfile import gettempdir
+import os
 
 class TestSecurityCommons(TestCase):
   @patch('os.path.isfile')
@@ -119,6 +120,54 @@ class TestSecurityCommons(TestCase):
 
     self.assertEquals(not result[config_file].items(), True)
 
+  def test_get_params_from_filesystem_JAAS(self):
+    conf_dir = gettempdir()
+    jaas_file = "test_jaas.conf"
+    jaas_file_path = conf_dir + os.sep + jaas_file
+
+    # Create temporary test file (mocking a files for reading isn't available for the current
version
+    # of the library
+    with open(jaas_file_path, "w+") as f:
+      f.write('Client {\n'
+              '  com.sun.security.auth.module.Krb5LoginModule required\n'
+              '  useKeyTab=true\n'
+              '  storeKey=true\n'
+              '  useTicketCache=false\n'
+              '  keyTab="/etc/security/keytabs/hbase.service.keytab"\n'
+              '  principal="hbase/vp-ambari-ranger-med-0120-2.cs1cloud.internal@EXAMPLE.COM";\n'
+              '};\n')
+
+    config_file = {
+      jaas_file : FILE_TYPE_JAAS_CONF
+    }
+
+    result = get_params_from_filesystem(conf_dir, config_file)
+
+    self.assertIn('test_jaas', result)
+    self.assertIn('Client', result['test_jaas'])
+
+    self.assertIn('com.sun.security.auth.module.Krb5LoginModule', result['test_jaas']['Client'])
+    self.assertEquals('required', result['test_jaas']['Client']['com.sun.security.auth.module.Krb5LoginModule'])
+
+    self.assertIn('useKeyTab', result['test_jaas']['Client'])
+    self.assertEquals('true', result['test_jaas']['Client']['useKeyTab'])
+
+    self.assertIn('storeKey', result['test_jaas']['Client'])
+    self.assertEquals('true', result['test_jaas']['Client']['storeKey'])
+
+    self.assertIn('useTicketCache', result['test_jaas']['Client'])
+    self.assertEquals('false', result['test_jaas']['Client']['useTicketCache'])
+
+    self.assertIn('keyTab', result['test_jaas']['Client'])
+    self.assertEquals('/etc/security/keytabs/hbase.service.keytab', result['test_jaas']['Client']['keyTab'])
+
+    self.assertIn('principal', result['test_jaas']['Client'])
+    self.assertEquals('hbase/vp-ambari-ranger-med-0120-2.cs1cloud.internal@EXAMPLE.COM',
result['test_jaas']['Client']['principal'])
+
+    os.unlink(jaas_file_path)
+
+    print result
+
   @patch('xml.etree.ElementTree.parse')
   def test_get_params_from_filesystem(self, et_parser_mock):
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/2686976e/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
b/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
index 7f6ed00..1e92f9d 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/security_commons.py
@@ -146,13 +146,14 @@ def get_params_from_filesystem(conf_dir, config_files):
 
     elif file_type == FILE_TYPE_JAAS_CONF:
       section_header = re.compile('^(\w+)\s+\{\s*$')
-      section_data = re.compile('^\s*([^ \s\=\}\{]+)\s*=?\s*"?([^ ";].+)"?;?\s*$')
+      section_data = re.compile('^\s*([^ \s\=\}\{]+)\s*=?\s*"?([^ ";]+)"?;?\s*$')
       section_footer = re.compile('^\}\s*;?\s*$')
       section_name = "root"
       result[file_name] = {}
       with open(conf_dir + os.sep + config_file, 'r') as f:
         for line in f:
           if line:
+            line = line.strip()
             m = section_header.search(line)
             if m:
               section_name = m.group(1)


Mime
View raw message