-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: DEV-3212: Add validation to avoid users import local files using…
… URL (#2840) * Add validation to avoid local files using URL import * Add unit tests * Apply formatting
- Loading branch information
1 parent
ad29804
commit 501142c
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import pytest | ||
|
|
||
| from rest_framework.exceptions import ValidationError | ||
|
|
||
| from data_import.uploader import load_tasks | ||
|
|
||
| pytestmark = pytest.mark.django_db | ||
|
|
||
|
|
||
| class MockedRequest: | ||
| FILES = () | ||
|
|
||
| def __init__(self, url): | ||
| self.url = url | ||
|
|
||
| @property | ||
| def content_type(self): | ||
| return "application/x-www-form-urlencoded" | ||
|
|
||
| @property | ||
| def data(self): | ||
| return {"url": self.url} | ||
|
|
||
|
|
||
| class TestUploader: | ||
| @pytest.fixture | ||
| def project(self, configured_project): | ||
| return configured_project | ||
|
|
||
| class TestLoadTasks: | ||
| @pytest.mark.parametrize("url", ("file:///etc/passwd", " file://etc/kernel ")) | ||
| def test_raises_for_local_files(self, url, project): | ||
| request = MockedRequest(url=url) | ||
|
|
||
| with pytest.raises(ValidationError) as e: | ||
| load_tasks(request, project) | ||
|
|
||
| assert '"url" is not valid' in str(e.value) |