1bf215546Sopenharmony_cidiff --git a/framework/replay/download_utils.py b/framework/replay/download_utils.py 2bf215546Sopenharmony_ciindex 3119a24a2..4e776ca85 100644 3bf215546Sopenharmony_ci--- a/framework/replay/download_utils.py 4bf215546Sopenharmony_ci+++ b/framework/replay/download_utils.py 5bf215546Sopenharmony_ci@@ -31,6 +31,7 @@ import xml.etree.ElementTree as ET 6bf215546Sopenharmony_ci from email.utils import formatdate 7bf215546Sopenharmony_ci from os import path 8bf215546Sopenharmony_ci from time import time 9bf215546Sopenharmony_ci+from urllib.parse import urlparse 10bf215546Sopenharmony_ci import requests 11bf215546Sopenharmony_ci from requests.adapters import HTTPAdapter, Retry 12bf215546Sopenharmony_ci from requests.utils import requote_uri 13bf215546Sopenharmony_ci@@ -88,7 +89,7 @@ def get_minio_credentials(url): 14bf215546Sopenharmony_ci minio_credentials['SessionToken']) 15bf215546Sopenharmony_ci 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_ci-def get_authorization_headers(url, resource): 18bf215546Sopenharmony_ci+def get_minio_authorization_headers(url, resource): 19bf215546Sopenharmony_ci minio_key, minio_secret, minio_token = get_minio_credentials(url) 20bf215546Sopenharmony_ci 21bf215546Sopenharmony_ci content_type = 'application/octet-stream' 22bf215546Sopenharmony_ci@@ -106,6 +107,17 @@ def get_authorization_headers(url, resource): 23bf215546Sopenharmony_ci return headers 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci 26bf215546Sopenharmony_ci+def get_jwt_authorization_headers(url, resource): 27bf215546Sopenharmony_ci+ date = formatdate(timeval=None, localtime=False, usegmt=True) 28bf215546Sopenharmony_ci+ jwt = OPTIONS.download['jwt'] 29bf215546Sopenharmony_ci+ host = urlparse(url).netloc 30bf215546Sopenharmony_ci+ 31bf215546Sopenharmony_ci+ headers = {'Host': host, 32bf215546Sopenharmony_ci+ 'Date': date, 33bf215546Sopenharmony_ci+ 'Authorization': 'Bearer %s' % (jwt)} 34bf215546Sopenharmony_ci+ return headers 35bf215546Sopenharmony_ci+ 36bf215546Sopenharmony_ci+ 37bf215546Sopenharmony_ci def download(url: str, file_path: str, headers, attempts=2) -> None: 38bf215546Sopenharmony_ci """Downloads a URL content into a file 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci@@ -174,7 +186,9 @@ def ensure_file(file_path): 41bf215546Sopenharmony_ci assert OPTIONS.download['minio_bucket'] 42bf215546Sopenharmony_ci assert OPTIONS.download['role_session_name'] 43bf215546Sopenharmony_ci assert OPTIONS.download['jwt'] 44bf215546Sopenharmony_ci- headers = get_authorization_headers(url, file_path) 45bf215546Sopenharmony_ci+ headers = get_minio_authorization_headers(url, file_path) 46bf215546Sopenharmony_ci+ elif OPTIONS.download['jwt']: 47bf215546Sopenharmony_ci+ headers = get_jwt_authorization_headers(url, file_path) 48bf215546Sopenharmony_ci else: 49bf215546Sopenharmony_ci headers = None 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_cidiff --git a/unittests/framework/replay/test_download_utils.py b/unittests/framework/replay/test_download_utils.py 52bf215546Sopenharmony_ciindex 1e78b26e7..749c5d835 100644 53bf215546Sopenharmony_ci--- a/unittests/framework/replay/test_download_utils.py 54bf215546Sopenharmony_ci+++ b/unittests/framework/replay/test_download_utils.py 55bf215546Sopenharmony_ci@@ -195,3 +195,17 @@ class TestDownloadUtils(object): 56bf215546Sopenharmony_ci get_request = requests_mock.request_history[1] 57bf215546Sopenharmony_ci assert(get_request.method == 'GET') 58bf215546Sopenharmony_ci assert(requests_mock.request_history[1].headers['Authorization'].startswith('AWS Key')) 59bf215546Sopenharmony_ci+ 60bf215546Sopenharmony_ci+ def test_jwt_authorization(self, requests_mock): 61bf215546Sopenharmony_ci+ """download_utils.ensure_file: Check we send the authentication headers to the server""" 62bf215546Sopenharmony_ci+ # reset minio_host from previous tests 63bf215546Sopenharmony_ci+ OPTIONS.download['minio_host'] = '' 64bf215546Sopenharmony_ci+ OPTIONS.download['jwt'] = 'jwt' 65bf215546Sopenharmony_ci+ 66bf215546Sopenharmony_ci+ assert not self.trace_file.check() 67bf215546Sopenharmony_ci+ download_utils.ensure_file(self.trace_path) 68bf215546Sopenharmony_ci+ TestDownloadUtils.check_same_file(self.trace_file, "remote") 69bf215546Sopenharmony_ci+ 70bf215546Sopenharmony_ci+ get_request = requests_mock.request_history[0] 71bf215546Sopenharmony_ci+ assert(get_request.method == 'GET') 72bf215546Sopenharmony_ci+ assert(requests_mock.request_history[0].headers['Authorization'].startswith('Bearer')) 73