[Windows] Security model for files permissions - STEP 3b (#6965)

* Modifications for misc

* Add some types

* Use os_rename

* Move rename into filesystem

* Use our os package

* Rename filesystem.rename to filesystem.replace

* Disable globally function redefined lint in os module
This commit is contained in:
Adrien Ferrand
2019-06-11 17:08:48 -07:00
committed by Brad Warren
parent 72e5d89e95
commit d75908c645
9 changed files with 82 additions and 77 deletions
-21
View File
@@ -1,21 +0,0 @@
"""Tests for certbot.compat."""
import certbot.tests.util as test_util
from certbot.compat import misc
from certbot.compat import os
class OsReplaceTest(test_util.TempDirTestCase):
"""Test to ensure consistent behavior of os_rename method"""
def test_os_rename_to_existing_file(self):
"""Ensure that os_rename will effectively rename src into dst for all platforms."""
src = os.path.join(self.tempdir, 'src')
dst = os.path.join(self.tempdir, 'dst')
open(src, 'w').close()
open(dst, 'w').close()
# On Windows, a direct call to os.rename will fail because dst already exists.
misc.os_rename(src, dst)
self.assertFalse(os.path.exists(src))
self.assertTrue(os.path.exists(dst))
+21
View File
@@ -0,0 +1,21 @@
"""Tests for certbot.compat.filesystem"""
import certbot.tests.util as test_util
from certbot.compat import os
from certbot.compat import filesystem
class OsReplaceTest(test_util.TempDirTestCase):
"""Test to ensure consistent behavior of rename method"""
def test_os_replace_to_existing_file(self):
"""Ensure that replace will effectively rename src into dst for all platforms."""
src = os.path.join(self.tempdir, 'src')
dst = os.path.join(self.tempdir, 'dst')
open(src, 'w').close()
open(dst, 'w').close()
# On Windows, a direct call to os.rename would fail because dst already exists.
filesystem.replace(src, dst)
self.assertFalse(os.path.exists(src))
self.assertTrue(os.path.exists(dst))