Project

Profile

Help

Issue #3412

Trailing slash in distribution base_path causes breakage (Pulp 3)

Added by Ichimonji10 over 1 year ago. Updated 6 months ago.

Status:
MODIFIED
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Severity:
2. Medium
Version:
Platform Release:
Blocks Release:
OS:
Backwards Incompatible:
No
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
QA Contact:
Complexity:
Smash Test:
Verified:
No
Verification Required:
No
Sprint:
Sprint 34

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_paths 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_urls that have a trailing slash.
  • Accept base_urls that have a trailing slash, and handle them properly.

When deciding upon a solution, please consider the user story outlined above.

Associated revisions

Revision 4c92978e View on GitHub
Added by daviddavis over 1 year ago

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

Revision 4c92978e View on GitHub
Added by daviddavis over 1 year ago

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

Revision 4c92978e View on GitHub
Added by daviddavis over 1 year ago

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

History

#1 Updated by Ichimonji10 over 1 year ago

  • Description updated (diff)

#2 Updated by Ichimonji10 over 1 year 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)

#3 Updated by daviddavis over 1 year ago

  • Project changed from File Support to Pulp

#4 Updated by dalley over 1 year ago

  • Sprint/Milestone set to 56
  • Triaged changed from No to Yes

#5 Updated by bmbouter over 1 year ago

  • Sprint set to Sprint 33

#6 Updated by bmbouter over 1 year ago

  • Sprint/Milestone deleted (56)

#7 Updated by jortel@redhat.com over 1 year ago

  • Sprint changed from Sprint 33 to Sprint 34

#8 Updated by daviddavis over 1 year ago

  • Status changed from NEW to POST
  • Assignee set to daviddavis

#9 Updated by daviddavis over 1 year ago

  • Smash Test set to 906

#10 Updated by daviddavis over 1 year ago

  • Status changed from POST to MODIFIED

#11 Updated by daviddavis 6 months ago

  • Sprint/Milestone set to 3.0

#12 Updated by bmbouter 6 months ago

  • Tags deleted (Pulp 3)

Please register to edit this issue

Also available in: Atom PDF