Issue #3412
closedTrailing slash in distribution base_path causes breakage (Pulp 3)
Description
Let's say I create a distribution by making an HTTP POST request to /api/v3/distributions/
, with the following JSON body:
{
"base_path": "my-base-path",
"http": true,
"https": true,
"name": "distribution-name",
"publication": "http://pulp-3.example.com:8000/api/v3/publications/publication-id/",
}
This will return a distribution:
{
"_href": "http://pulp-3.example.com:8000/api/v3/distributions/distribution-name/",
"base_path": "my-base-path",
"base_url": "pulp-3.example.com:8000/content/my-base-path",
"http": true,
"https": true,
"name": "distribution-name",
"publication": "http://pulp-3.example.com:8000/api/v3/publications/publication-id/",
"publisher": null,
"repository": null
}
Furthermore, let's say that the publication at …/api/v3/publications/publication-id/
contains a file named 1.iso.
At which URLs are this file available? The following:
http://pulp-3.example.com:8000/content/my-base-path/1.iso
https://pulp-3.example.com:8000/content/my-base-path/1.iso
Before going any further, note that the process of generating these paths is awkward, because the data in the distributor is awkward. Let's say that I write some Python code to come up with the path to 1.iso
. A naive attempt will totally fail:
from urllib.parse import urljoin
distribution = {
'_href': 'http://pulp-3.example.com:8000/api/v3/distributions/distribution-name/',
'base_path': 'my-base-path',
'base_url': 'pulp-3.example.com:8000/content/my-base-path',
'http': True,
'https': True,
'name': 'distribution-name',
'publication': 'http://pulp-3.example.com:8000/api/v3/publications/publication-id/',
'publisher': None,
'repository': None
}
basename = '1.iso'
# ['1.iso', '1.iso']
urls = [
urljoin(distribution['base_url'], basename)
for scheme in ('http', 'https')
if distribution[scheme]
]
# ['http://pulp-3.example.com:8000/content/1.iso', 'https://pulp-3.example.com:8000/content/1.iso']
urls = [
urljoin(scheme + '://' + distribution['base_url'], basename)
for scheme in ('http', 'https')
if distribution[scheme]
]
# ['http://pulp-3.example.com:8000/content/my-base-path/1.iso', 'https://pulp-3.example.com:8000/content/my-base-path/1.iso']
urls = [
urljoin(scheme + '://' + distribution['base_url'] + '/', basename)
for scheme in ('http', 'https')
if distribution[scheme]
]
This user experience sucks. But that's not what this bug is about. This bug is really about the fact Pulp accepts base_path
s that it subsequently barfs on. Let's say that I create the exact same distribution as before, but with a trailing slash on the base_path
:
{
"base_path": "my-base-path/",
"http": true,
"https": true,
"name": "distribution-name",
"publication": "http://pulp-3.example.com:8000/api/v3/publications/publication-id/",
}
Pulp will accept the trailing slash:
{
"_href": "http://pulp-3.example.com:8000/api/v3/distributions/distribution-name/",
"base_path": "my-base-path/",
"base_url": "pulp-3.example.com:8000/content/my-base-path/",
"http": true,
"https": true,
"name": "distribution-name",
"publication": "http://pulp-3.example.com:8000/api/v3/publications/publication-id/",
"publisher": null,
"repository": null
}
The file named 1.iso
should be available at the following URLs:
http://pulp-3.example.com:8000/content/my-base-path/1.iso
https://pulp-3.example.com:8000/content/my-base-path/1.iso
Unfortunately, HTTP requests to these URLs will produce HTTP 404s.
Please do one of the following:
- Reject
base_url
s that have a trailing slash. - Accept
base_url
s that have a trailing slash, and handle them properly.
When deciding upon a solution, please consider the user story outlined above.
Updated by Ichimonji10 over 6 years ago
- Subject changed from Trailing slash in distribution base_url causes breakage (Pulp 3) to Trailing slash in distribution base_path causes breakage (Pulp 3)
Updated by daviddavis over 6 years ago
- Project changed from File Support to Pulp
Updated by dalley over 6 years ago
- Sprint/Milestone set to 56
- Triaged changed from No to Yes
Updated by jortel@redhat.com over 6 years ago
- Sprint changed from Sprint 33 to Sprint 34
Updated by daviddavis over 6 years ago
- Status changed from NEW to POST
- Assignee set to daviddavis
Added by daviddavis over 6 years ago
Added by daviddavis over 6 years ago
Revision 4c92978e | View on GitHub
Validate distribution base paths
Validate that distribution base paths contain valid urls and don't end or begin with slashes
Updated by daviddavis over 6 years ago
- Status changed from POST to MODIFIED
Applied in changeset pulp|4c92978e13566e3a3fbd84582f0b29198cbf392e.
Updated by bmbouter almost 5 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
Validate distribution base paths
Validate that distribution base paths contain valid urls and don't end or begin with slashes
fixes #3412 https://pulp.plan.io/issues/3412