|
13 | 13 | # See the License for the specific language governing permissions and |
14 | 14 | # limitations under the License. |
15 | 15 |
|
| 16 | +import os |
16 | 17 | import sys |
17 | 18 | import errno |
18 | 19 | import hashlib |
| 20 | +import tempfile |
19 | 21 | from io import BytesIO |
20 | 22 | from unittest import mock |
21 | 23 | from unittest.mock import Mock |
@@ -53,6 +55,22 @@ def setUp(self): |
53 | 55 | self.driver1.strict_mode = False |
54 | 56 | self.driver1.strict_mode = False |
55 | 57 |
|
| 58 | + def test_save_object_confines_provider_name_to_destination_directory(self): |
| 59 | + with tempfile.TemporaryDirectory() as temp_dir: |
| 60 | + destination_path = os.path.join(temp_dir, "downloads") + os.sep |
| 61 | + os.mkdir(destination_path) |
| 62 | + outside_path = os.path.join(temp_dir, "evil") |
| 63 | + response = Mock() |
| 64 | + response._response.iter_content.return_value = [b"PWNED"] |
| 65 | + obj = Mock(size=5) |
| 66 | + obj.name = "../../evil" |
| 67 | + |
| 68 | + self.driver1._save_object(response, obj, destination_path) |
| 69 | + |
| 70 | + self.assertFalse(os.path.exists(outside_path)) |
| 71 | + with open(os.path.join(destination_path, "evil"), "rb") as file_handle: |
| 72 | + self.assertEqual(file_handle.read(), b"PWNED") |
| 73 | + |
56 | 74 | def test__upload_object_iterator_must_have_next_method(self): |
57 | 75 | valid_iterators = [BytesIO(b("134")), StringIO("bar")] |
58 | 76 | invalid_iterators = ["foobar", "", False, True, 1, object()] |
|
0 commit comments