Project

Profile

Help

Issue #3412

Updated by Ichimonji10 about 6 years ago

Let's say I create a distribution by making an HTTP POST request to <code>/api/v3/distributions/</code>, with the following JSON body: 

 <pre><code class="json">{ 
   "base_path": "my-base-path", 
   "http": true, 
   "https": true, 
   "name": "distribution-name", 
   "publication": "http://pulp-3.example.com:8000/api/v3/publications/publication-id/", 
 }</code></pre> 

 This will return a distribution: 

 <pre><code class="json">{ 
   "_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 
 }</code></pre> 

 Furthermore, let's say that the publication at <code>…/api/v3/publications/publication-id/</code> contains a file named <code>1.iso.</code> At which URLs are this file available? The following: 

 * <code>http://pulp-3.example.com:8000/content/my-base-path/1.iso</code> <code>http://pulp-3.example.com:8000/content/my_base_path/1.iso</code> 
 * <code>https://pulp-3.example.com:8000/content/my-base-path/1.iso</code> <code>https://pulp-3.example.com:8000/content/my_base_path/1.iso</code> 

 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 <code>1.iso</code>. A naive attempt will totally fail: 

 <pre><code class="python">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] 
 ] 
 </code></pre> 

 This user experience sucks. But that's not what this bug is about. This bug is *really* about the fact Pulp accepts <code>base_path</code>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 <code>base_path</code>: 

 <pre><code class="json">{ 
   "base_path": "my-base-path/", 
   "http": true, 
   "https": true, 
   "name": "distribution-name", 
   "publication": "http://pulp-3.example.com:8000/api/v3/publications/publication-id/", 
 }</code></pre> 

 Pulp will accept the trailing slash: 

 <pre><code class="json">{ 
   "_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 
 }</code></pre> 

 The file named <code>1.iso</code> *should* be available at the following URLs: 

 * <code>http://pulp-3.example.com:8000/content/my-base-path/1.iso</code> <code>http://pulp-3.example.com:8000/content/my_base_path/1.iso</code> 
 * <code>https://pulp-3.example.com:8000/content/my-base-path/1.iso</code> <code>https://pulp-3.example.com:8000/content/my_base_path/1.iso</code> 

 Unfortunately, HTTP requests to these URLs will produce HTTP 404s. 

 Please do one of the following: 

 * Reject <code>base_url</code>s that have a trailing slash. 
 * Accept <code>base_url</code>s that have a trailing slash, and handle them properly. 

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

Back