From aba7274ed5682335bd91d94d5b122db440872378 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 1 May 2017 20:11:19 -0300 Subject: [refactor] unify path validation --- testing/tests/blobs/test_fs_backend.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'testing/tests/blobs/test_fs_backend.py') diff --git a/testing/tests/blobs/test_fs_backend.py b/testing/tests/blobs/test_fs_backend.py index 0d7e9789..f6f2db2d 100644 --- a/testing/tests/blobs/test_fs_backend.py +++ b/testing/tests/blobs/test_fs_backend.py @@ -99,9 +99,24 @@ class FilesystemBackendTestCase(unittest.TestCase): self.assertEquals(result, ['blob_0', 'blob_1']) @pytest.mark.usefixtures("method_tmpdir") - def test_path_validation_for_subdirectories(self): + def test_path_validation_on_read_blob(self): blobs_path = self.tempdir backend = _blobs.FilesystemBlobsBackend(blobs_path) - self.assertFalse(backend._valid_subdir('/')) - self.assertFalse(backend._valid_subdir(blobs_path + '../../../../../')) - self.assertTrue(backend._valid_subdir(os.path.join(blobs_path, 'x'))) + with pytest.raises(Exception): + backend.read_blob('..', '..', DummyRequest([''])) + with pytest.raises(Exception): + backend.read_blob('valid', '../../../', DummyRequest([''])) + with pytest.raises(Exception): + backend.read_blob('../../../', 'valid', DummyRequest([''])) + + @pytest.mark.usefixtures("method_tmpdir") + @defer.inlineCallbacks + def test_path_validation_on_write_blob(self): + blobs_path = self.tempdir + backend = _blobs.FilesystemBlobsBackend(blobs_path) + with pytest.raises(Exception): + yield backend.write_blob('..', '..', DummyRequest([''])) + with pytest.raises(Exception): + yield backend.write_blob('valid', '../../../', DummyRequest([''])) + with pytest.raises(Exception): + yield backend.write_blob('../../../', 'valid', DummyRequest([''])) -- cgit v1.2.3