Title: [286263] trunk/Tools
Revision
286263
Author
jbed...@apple.com
Date
2021-11-29 14:29:50 -0800 (Mon, 29 Nov 2021)

Log Message

[webkitcorepy] Delete unused environment variables
https://bugs.webkit.org/show_bug.cgi?id=233565
<rdar://problem/85820306>

Reviewed by Dewei Zhu.

* Scripts/libraries/webkitcorepy/setup.py: Bump version.
* Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
* Scripts/libraries/webkitcorepy/webkitcorepy/environment.py:
(Environment.__init__): Keep track of sure environment files.
(Environment.load): Ditto.
(Environment.secure): Delete all unused environment files, since they may contain credentials.
* Scripts/libraries/webkitcorepy/webkitcorepy/tests/environment_unittest.py:
(TestEnvironment.test_secure):

Canonical link: https://commits.webkit.org/244626@main

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (286262 => 286263)


--- trunk/Tools/ChangeLog	2021-11-29 22:04:59 UTC (rev 286262)
+++ trunk/Tools/ChangeLog	2021-11-29 22:29:50 UTC (rev 286263)
@@ -1,3 +1,20 @@
+2021-11-29  Jonathan Bedard  <jbed...@apple.com>
+
+        [webkitcorepy] Delete unused environment variables
+        https://bugs.webkit.org/show_bug.cgi?id=233565
+        <rdar://problem/85820306>
+
+        Reviewed by Dewei Zhu.
+
+        * Scripts/libraries/webkitcorepy/setup.py: Bump version.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py: Ditto.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/environment.py:
+        (Environment.__init__): Keep track of sure environment files.
+        (Environment.load): Ditto.
+        (Environment.secure): Delete all unused environment files, since they may contain credentials.
+        * Scripts/libraries/webkitcorepy/webkitcorepy/tests/environment_unittest.py:
+        (TestEnvironment.test_secure):
+
 2021-11-29  Lauro Moura  <lmo...@igalia.com>
 
         [webkitcorepy] Environment: Sort values before comparing in unittest

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/setup.py (286262 => 286263)


--- trunk/Tools/Scripts/libraries/webkitcorepy/setup.py	2021-11-29 22:04:59 UTC (rev 286262)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/setup.py	2021-11-29 22:29:50 UTC (rev 286263)
@@ -30,7 +30,7 @@
 
 setup(
     name='webkitcorepy',
-    version='0.12.2',
+    version='0.12.3',
     description='Library containing various Python support classes and functions.',
     long_description=readme(),
     classifiers=[

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py (286262 => 286263)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py	2021-11-29 22:04:59 UTC (rev 286262)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py	2021-11-29 22:29:50 UTC (rev 286263)
@@ -44,7 +44,7 @@
 from webkitcorepy.editor import Editor
 from webkitcorepy.file_lock import FileLock
 
-version = Version(0, 12, 2)
+version = Version(0, 12, 3)
 
 from webkitcorepy.autoinstall import Package, AutoInstall
 if sys.version_info > (3, 0):

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/environment.py (286262 => 286263)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/environment.py	2021-11-29 22:04:59 UTC (rev 286262)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/environment.py	2021-11-29 22:29:50 UTC (rev 286263)
@@ -38,6 +38,7 @@
         self._mapping = dict()
         self.path = path
         self._divider = divider
+        self._paths = set()
 
     def load(self, *prefixes):
         if not self.path:
@@ -46,6 +47,7 @@
             prefix, key = file.split(self._divider, 1) if self._divider in file else (None, file)
             if prefix and prefix not in prefixes:
                 continue
+            self._paths.add(os.path.join(self.path, file))
             with open(os.path.join(self.path, file), 'r') as fl:
                 self._mapping[key] = fl.read().rstrip('\n')
         return self
@@ -55,6 +57,19 @@
             return os.environ[key]
         return self._mapping.get(key)
 
+    def secure(self, *extra_paths):
+        '''Delete unused environment files in self.path along with the provided extra paths'''
+
+        for file in os.listdir(self.path):
+            path = os.path.join(self.path, file)
+            if path not in self._paths:
+                os.remove(path)
+        for path in extra_paths:
+            if os.path.isfile(path):
+                os.remove(path)
+            if os.path.exists(path):
+                raise OSError("Failed to delete '{}' when securing credentials".format(path))
+
     def __getitem__(self, key):
         result = self.get(key)
         if not result:

Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/tests/environment_unittest.py (286262 => 286263)


--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/tests/environment_unittest.py	2021-11-29 22:04:59 UTC (rev 286262)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/tests/environment_unittest.py	2021-11-29 22:29:50 UTC (rev 286263)
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 Apple Inc. All rights reserved.
+# Copyright (C) 2021 Apple Inc. All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -72,3 +72,24 @@
             )
         finally:
             Environment._instance = None
+
+    def test_secure(self):
+        try:
+            with open(os.path.join(self.path, 'KEY'), 'w') as file:
+                file.write('value ')
+            with open(os.path.join(self.path, 'scope___KEY_A'), 'w') as file:
+                file.write('value_a')
+            with open(os.path.join(self.path, 'other___KEY_B'), 'w') as file:
+                file.write('value_b')
+            with open(os.path.join(self.path, 'KEY_C'), 'w') as file:
+                file.write('value_c')
+
+            Environment.instance(self.path).load('scope')
+            Environment.instance(self.path).secure(os.path.join(self.path, 'KEY_C'))
+
+            self.assertTrue(os.path.isfile(os.path.join(self.path, 'KEY')))
+            self.assertTrue(os.path.isfile(os.path.join(self.path, 'scope___KEY_A')))
+            self.assertFalse(os.path.isfile(os.path.join(self.path, 'other___KEY_B')))
+            self.assertFalse(os.path.isfile(os.path.join(self.path, 'KEY_C')))
+        finally:
+            Environment._instance = None
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to