Project

Profile

Help

Issue #3412

closed

Trailing slash in distribution base_path causes breakage (Pulp 3)

Added by Ichimonji10 almost 7 years ago. Updated about 5 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Sprint:
Sprint 34
Quarter:

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.

Actions #1

Updated by Ichimonji10 almost 7 years ago

  • Description updated (diff)
Actions #2

Updated by Ichimonji10 almost 7 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)
Actions #3

Updated by daviddavis almost 7 years ago

  • Project changed from File Support to Pulp
Actions #4

Updated by dalley almost 7 years ago

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

Updated by bmbouter almost 7 years ago

  • Sprint set to Sprint 33
Actions #6

Updated by bmbouter almost 7 years ago

  • Sprint/Milestone deleted (56)
Actions #7

Updated by jortel@redhat.com almost 7 years ago

  • Sprint changed from Sprint 33 to Sprint 34
Actions #8

Updated by daviddavis almost 7 years ago

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

Added by daviddavis almost 7 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

fixes #3412 https://pulp.plan.io/issues/3412

Added by daviddavis almost 7 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

fixes #3412 https://pulp.plan.io/issues/3412

Actions #10

Updated by daviddavis almost 7 years ago

  • Status changed from POST to MODIFIED
Actions #11

Updated by daviddavis over 5 years ago

  • Sprint/Milestone set to 3.0.0
Actions #12

Updated by bmbouter over 5 years ago

  • Tags deleted (Pulp 3)
Actions #13

Updated by bmbouter about 5 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF