Opened 14 years ago
Last modified 13 years ago
#15768 closed Cleanup/optimization
The setUp() method FileStorageTests in tests/regressiontests/file_storage/tests.py uses tempfile.mktemp() — at Version 2
Reported by: | d1b | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The tempfile.mktemp()
function is deprecated and the documentation warns that the "Use of this function may introduce a security hole in your program" - see http://docs.python.org/library/tempfile.html#tempfile.mktemp for more information.
The setUp()
method FileStorageTests
in tests/regressiontests/file_storage/tests.py uses tempfile.mktemp()
in creating a temporary directory. The temporary directory is then deleted during tearDown()
:
class FileStorageTests(unittest.TestCase): storage_class = FileSystemStorage def setUp(self): self.temp_dir = tempfile.mktemp() os.makedirs(self.temp_dir) self.storage = self.storage_class(location=self.temp_dir, base_url='/test_media_url/') def tearDown(self): shutil.rmtree(self.temp_dir)
This seems like a mistake because other classes such as FileSaveRaceConditionTest
use tempfile.mkdtemp()
. tempfile.mkdtemp
is a safer way of creating a temporary directory.
Something like the following (_NOTE_: I haven't tested this) could be a 'fix'.
- self.temp_dir = tempfile.mktemp() - os.makedirs(self.temp_dir) + self.temp_dir = tempfile.mkdtemp()
Change History (1)
comment:2 by , 14 years ago
Description: | modified (diff) |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
Reformated description so it's easier to read.