Make service optional for auth

The service is not required for WWW-Authenticate and is not provided
from the rdoproject docker registry. It is provided from docker.io so we
should only add it when it's available.

Change-Id: Iecc421c07f005eead38dc6b5ad1c1cd821d86e8e
CLoses-Bug: #1798126
This commit is contained in:
Alex Schultz
2018-10-16 12:17:47 -06:00
parent b1afa59e03
commit 79a5455ffe
2 changed files with 20 additions and 2 deletions

View File

@@ -338,6 +338,7 @@ class BaseImageUploader(ImageUploader):
token_param = {}
realm = re.search('realm="(.*?)"', www_auth).group(1)
if 'service=' in www_auth:
token_param['service'] = re.search(
'service="(.*?)"', www_auth).group(1)
token_param['scope'] = 'repository:%s:pull' % image[1:]

View File

@@ -431,6 +431,23 @@ class TestBaseImageUploader(base.TestCase):
auth(url1).headers['Authorization']
)
def test_authenticate_with_no_service(self):
req = self.requests
auth = image_uploader.BaseImageUploader.authenticate
url1 = urlparse('docker://docker.io/t/nova-api:latest')
headers = {
'www-authenticate': 'Bearer '
'realm="https://auth.docker.io/token",'
}
req.get('https://registry-1.docker.io/v2/', status_code=401,
headers=headers)
req.get('https://auth.docker.io/token', json={"token": "asdf1234"})
self.assertEqual(
'Bearer asdf1234',
auth(url1).headers['Authorization']
)
def test_fix_dockerio_url(self):
url1 = urlparse('docker://docker.io/t/nova-api:latest')
url2 = urlparse('docker://registry-1.docker.io/t/nova-api:latest')