diff options
author | Victor Shyba <victor1984@riseup.net> | 2017-05-01 20:11:19 -0300 |
---|---|---|
committer | Victor Shyba <victor1984@riseup.net> | 2017-05-01 20:11:19 -0300 |
commit | aba7274ed5682335bd91d94d5b122db440872378 (patch) | |
tree | d9d644e0936a9fde3f8122547d93a8f7c04d6d55 /testing | |
parent | 5854faf9b6de1297d6ebdd95ef700228c7fe5fb6 (diff) |
[refactor] unify path validation
Diffstat (limited to 'testing')
-rw-r--r-- | testing/tests/blobs/test_fs_backend.py | 23 |
1 files changed, 19 insertions, 4 deletions
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([''])) |