-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add validation to check for file path overlaps
- Loading branch information
David Davis
committed
Dec 2, 2019
1 parent
b617ad4
commit eda7d3d
Showing
7 changed files
with
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Added artifact path overlap checks for repo versions and publications. Plugin writers should call | ||
``validate_version_paths()`` or ``validate_publication_paths()`` during the finalize step when | ||
creating RepositoryVersions or Publications (respectively). |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ drf-yasg | |
dynaconf | ||
plantuml | ||
pyyaml | ||
pygtrie | ||
rq | ||
sphinx | ||
sphinx-rtd-theme | ||
|
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
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,22 @@ | ||
from pulpcore.app.models import ContentArtifact | ||
from pulpcore.app.files import validate_file_paths | ||
|
||
|
||
def validate_publication_paths(publication): | ||
""" | ||
Validate artifact relative paths for dupes or overlap (e.g. a/b and a/b/c). | ||
Raises: | ||
ValueError: If two artifact relative paths are dupes or overlap | ||
""" | ||
paths = list(publication.published_artifact.values_list("relative_path", flat=True)) | ||
|
||
if publication.pass_through: | ||
paths += ContentArtifact.objects. \ | ||
filter(content__pk__in=publication.repository_version.content). \ | ||
values_list("relative_path", flat=True) | ||
|
||
try: | ||
validate_file_paths(paths) | ||
except ValueError as e: | ||
raise ValueError(_("Cannot create publication. {err}.").format(err=e)) |
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
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,36 @@ | ||
from unittest import TestCase | ||
|
||
from pulpcore.app.files import validate_file_paths | ||
|
||
|
||
class TestValidateFilePaths(TestCase): | ||
def test_valid_paths(self): | ||
""" | ||
Test for valid paths. | ||
""" | ||
paths = ['a/b', 'a/c/b', 'PULP_MANIFEST', 'b'] | ||
validate_file_paths(paths) | ||
|
||
def test_dupes(self): | ||
""" | ||
Test for two duplicate paths. | ||
""" | ||
paths = ['a/b', 'PULP_MANIFEST', 'PULP_MANIFEST'] | ||
with self.assertRaisesRegex(ValueError, "Path is duplicated: PULP_MANIFEST"): | ||
validate_file_paths(paths) | ||
|
||
def test_overlaps(self): | ||
""" | ||
Test for overlapping paths. | ||
""" | ||
paths = ['a/b', 'a/b/c'] | ||
with self.assertRaises(ValueError): | ||
validate_file_paths(paths) | ||
|
||
paths = ['a/b/c', 'a/b'] | ||
with self.assertRaises(ValueError): | ||
validate_file_paths(paths) | ||
|
||
paths = ['b/c', 'a/b', 'b'] | ||
with self.assertRaises(ValueError): | ||
validate_file_paths(paths) |
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 |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
'setuptools>=39.2.0,<42.1.0', | ||
'dynaconf>=2.2,<2.3', | ||
'whitenoise~=4.1.3', | ||
'pygtrie~=2.3.2', | ||
] | ||
|
||
setup( | ||
|