Change in vdsm[master]: securable: Do not try to secure inner classes

nsoffer at redhat.com nsoffer at redhat.com
Fri Feb 14 16:04:53 UTC 2014


Nir Soffer has uploaded a new change for review.

Change subject: securable: Do not try to secure inner classes
......................................................................

securable: Do not try to secure inner classes

Previously the class decorator was not careful enough, "securing" any
callable, which matches inner classes.

This patch corrects the type check so only unbound methods are matched
and add more tests, ensuring this will not break in future version.

Change-Id: Ic5ea86b94ca5f07753e2376de8e9e7228a2a147e
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/securableTests.py
M vdsm/storage/securable.py
2 files changed, 32 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/87/24487/1

diff --git a/tests/securableTests.py b/tests/securableTests.py
index ffc402a..037ae49 100644
--- a/tests/securableTests.py
+++ b/tests/securableTests.py
@@ -27,11 +27,24 @@
     @secured
     class MySecureClass(object):
 
+        class InnerClass(object):
+            pass
+
+        classVariable = 42
+
         def __init__(self):
             self.secured = False
 
         def __is_secure__(self):
             return self.secured
+
+        @staticmethod
+        def staticMethod():
+            pass
+
+        @classmethod
+        def classMethod(cls):
+            pass
 
         def securedMethod(self):
             "securedMethod docstring"
@@ -86,3 +99,18 @@
                          "securedMethod docstring")
         self.assertEqual(secureObject.unsecuredMethod.__doc__,
                          "unsecuredMethod docstring")
+
+    def testInnerClass(self):
+        obj = TestSecurable.MySecureClass.InnerClass()
+        self.assertEqual(type(obj), TestSecurable.MySecureClass.InnerClass)
+
+    def testClassVariable(self):
+        self.assertEqual(TestSecurable.MySecureClass.classVariable, 42)
+
+    def testStaticMethod(self):
+        TestSecurable.MySecureClass.staticMethod()
+
+    def testClassMethod(self):
+        TestSecurable.MySecureClass.classMethod()
+        secureObject = TestSecurable.MySecureClass()
+        secureObject.classMethod()
diff --git a/vdsm/storage/securable.py b/vdsm/storage/securable.py
index f4c0140..b7a6c09 100644
--- a/vdsm/storage/securable.py
+++ b/vdsm/storage/securable.py
@@ -18,6 +18,7 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+import inspect
 from functools import wraps
 
 OVERRIDE_ARG = "__securityOverride"
@@ -45,8 +46,9 @@
     for name, value in cls.__dict__.iteritems():
         # Skipping non callable attributes, special methods (including
         # SECURE_METHOD_NAME) and unsecured methods.
-        if (not callable(value) or not getattr(value, SECURE_FIELD, True)
-                or name.startswith("__")):
+        if (not inspect.isfunction(value) or
+            not getattr(value, SECURE_FIELD, True) or
+            name.startswith("__")):
             continue
         setattr(cls, name, _secure_method(value))
 


-- 
To view, visit http://gerrit.ovirt.org/24487
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic5ea86b94ca5f07753e2376de8e9e7228a2a147e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list