Browse Source

AMBARI-9512. Kerberos: Keytab content is available through requests endpoint.(vbrodetskyi)

Vitaly Brodetskyi 10 năm trước cách đây
mục cha
commit
3b88165640

+ 7 - 1
ambari-server/src/main/resources/common-services/KERBEROS/1.10.3-10/package/scripts/kerberos_common.py

@@ -382,8 +382,14 @@ class KerberosScript(Script):
             elif group_access == 'r':
               mode |= stat.S_IRGRP
 
+            keytab_content = base64.b64decode(keytab_content_base64)
+
+            # to hide content in command output
+            def make_lambda(data):
+              return lambda: data
+
             File(keytab_file_path,
-                 content=base64.b64decode(keytab_content_base64),
+                 content=make_lambda(keytab_content),
                  mode=mode,
                  owner=owner,
                  group=group)

+ 5 - 5
ambari-server/src/test/python/stacks/2.2/KERBEROS/test_kerberos_client.py

@@ -24,6 +24,7 @@ import sys
 import use_cases
 from stacks.utils.RMFTestCase import *
 
+
 class TestKerberosClient(RMFTestCase):
   COMMON_SERVICES_PACKAGE_DIR = "KERBEROS/1.10.3-10/package"
   STACK_VERSION = "2.2"
@@ -65,7 +66,6 @@ class TestKerberosClient(RMFTestCase):
                        target = RMFTestCase.TARGET_COMMON_SERVICES
     )
 
-
     self.assertResourceCalled('Directory', use_cases.get_krb5_conf_dir(json_data),
                               owner='root',
                               group='root',
@@ -262,7 +262,7 @@ class TestKerberosClient(RMFTestCase):
                               owner='root',
                               group='hadoop',
                               mode=0440,
-                              content=base64.b64decode("BQIAAABbAAIAC0VYQU1QTEUuQ09NAARIVFRQABdjNjU"
+                              content=CallFunctionMock(call_result=base64.b64decode("BQIAAABbAAIAC0VYQU1QTEUuQ09NAARIVFRQABdjNjU"
                                                        "wMS5hbWJhcmkuYXBhY2hlLm9yZwAAAAFUodgKAQASAC"
                                                        "A5N4gKUJsizCzwRD11Q/6sdZhJjlJmuuMeMKw/WefIb"
                                                        "gAAAFMAAgALRVhBTVBMRS5DT00ABEhUVFAAF2M2NTAx"
@@ -274,7 +274,7 @@ class TestKerberosClient(RMFTestCase):
                                                        "jNjUwMS5hbWJhcmkuYXBhY2hlLm9yZwAAAAFUodgKAQ"
                                                        "ADAAiov1LleuaMgwAAAEsAAgALRVhBTVBMRS5DT00AB"
                                                        "EhUVFAAF2M2NTAxLmFtYmFyaS5hcGFjaGUub3JnAAAA"
-                                                       "AVSh2AoBABEAECBTe9uCaSiPxnoGRldhAks=")
+                                                       "AVSh2AoBABEAECBTe9uCaSiPxnoGRldhAks="))
     )
 
     self.assertResourceCalled('Directory', "/etc/security/keytabs",
@@ -287,7 +287,7 @@ class TestKerberosClient(RMFTestCase):
                           owner='ambari-qa',
                           group='hadoop',
                           mode=0400,
-                          content=base64.b64decode("BQIAAABHAAEAC0VYQU1QTEUuQ09NAAlhbWJhcmktcWEAAAA"
+                          content=CallFunctionMock(call_result=base64.b64decode("BQIAAABHAAEAC0VYQU1QTEUuQ09NAAlhbWJhcmktcWEAAAA"
                                                    "BVKHYCgEAEgAg3OBDOecGoznTHZiPwmlmK4TI6bdRdrl/6q"
                                                    "TV8Kml2TAAAAA/AAEAC0VYQU1QTEUuQ09NAAlhbWJhcmktc"
                                                    "WEAAAABVKHYCgEAEAAYzqEjkX/xDoO8ij0cJmc3ZG7Qfzgl"
@@ -295,5 +295,5 @@ class TestKerberosClient(RMFTestCase):
                                                    "AAVSh2AoBABcAEHzLG1kfqxhEoTe4erUldvQAAAAvAAEAC0"
                                                    "VYQU1QTEUuQ09NAAlhbWJhcmktcWEAAAABVKHYCgEAAwAIO"
                                                    "PK6UkwyUSMAAAA3AAEAC0VYQU1QTEUuQ09NAAlhbWJhcmkt"
-                                                   "cWEAAAABVKHYCgEAEQAQVqISRJwXIQnG28lI34mfeA==")
+                                                   "cWEAAAABVKHYCgEAEQAQVqISRJwXIQnG28lI34mfeA=="))
     )

+ 22 - 2
ambari-server/src/test/python/stacks/utils/RMFTestCase.py

@@ -17,7 +17,8 @@ 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.
 '''
-__all__ = ["RMFTestCase", "Template", "StaticFile", "InlineTemplate", "UnknownConfigurationMock", "FunctionMock"]
+__all__ = ["RMFTestCase", "Template", "StaticFile", "InlineTemplate", "UnknownConfigurationMock", "FunctionMock",
+           "CallFunctionMock"]
 
 from unittest import TestCase
 import json
@@ -213,7 +214,7 @@ class RMFTestCase(TestCase):
     with patch.object(UnknownConfiguration, '__getattr__', return_value=lambda: "UnknownConfiguration()"):
       self.assertNotEqual(len(RMFTestCase.env.resource_list), 0, "There was no more resources executed!")
       resource = RMFTestCase.env.resource_list.pop(0)
-      
+
       self.assertEquals(resource_type, resource.__class__.__name__)
       self.assertEquals(name, resource.name)
       self.assertEquals(kwargs, resource.arguments)
@@ -264,5 +265,24 @@ class FunctionMock():
     
   def __eq__(self, other):
     return hasattr(other, '__call__') and hasattr(other, '__name__') and self.name == other.__name__
+
+class CallFunctionMock():
+  """
+  Used to mock callable with specified arguments and expected results.
+  Callable will be called with arguments and result will be compared.
+  """
+  def __init__(self, call_result=None, *args, **kwargs):
+    self.call_result = call_result
+    self.args = args
+    self.kwargs = kwargs
+
+  def __ne__(self, other):
+    return not self.__eq__(other)
+
+  def __eq__(self, other):
+    if hasattr(other, '__call__'):
+      result = other(*self.args, **self.kwargs)
+      return self.call_result == result
+    return False