Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass the correct token for artifacts downloading. #7325

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion infra/cifuzz/filestore/github_actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class GithubActionsFilestore(filestore.BaseFilestore):

def __init__(self, config):
super().__init__(config)
self.github_api_http_headers = github_api.get_http_auth_headers(config)
self.github_api_http_headers = github_api.get_http_auth_headers()

def _get_artifact_name(self, name):
"""Returns |name| prefixed with |self.ARITFACT_PREFIX| if it isn't already
Expand Down
7 changes: 3 additions & 4 deletions infra/cifuzz/filestore/github_actions/github_actions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ class GithubActionsFilestoreTest(fake_filesystem_unittest.TestCase):
@mock.patch('platform_config.github._get_event_data', return_value={})
def setUp(self, _): # pylint: disable=arguments-differ
test_helpers.patch_environ(self)
self.token = 'example githubtoken'
self.owner = 'exampleowner'
self.repo = 'examplerepo'
os.environ['GITHUB_REPOSITORY'] = f'{self.owner}/{self.repo}'
os.environ['GITHUB_EVENT_PATH'] = '/fake'
os.environ['CFL_PLATFORM'] = 'github'
os.environ['GITHUB_WORKSPACE'] = '/workspace'
self.config = test_helpers.create_run_config(token=self.token)
os.environ['ACTIONS_RUNTIME_TOKEN'] = 'githubtoken'
self.config = test_helpers.create_run_config()
self.local_dir = '/local-dir'
self.testcase = os.path.join(self.local_dir, 'testcase')

def _get_expected_http_headers(self):
return {
'Authorization': f'token {self.token}',
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'Bearer githubtoken',
}

@mock.patch('filestore.github_actions.github_api.list_artifacts')
Expand Down
10 changes: 7 additions & 3 deletions infra/cifuzz/filestore/github_actions/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@
_GET_BACKOFF = 1


def get_http_auth_headers(config):
def get_http_auth_headers():
"""Returns HTTP headers for authentication to the API."""
authorization = f'token {config.token}'
# Undocumented token used for artifacts auth.
token = os.environ.get('ACTIONS_RUNTIME_TOKEN')
if not token:
return {}

authorization = f'Bearer {token}'
return {
'Authorization': authorization,
'Accept': 'application/vnd.github.v3+json'
}


Expand Down
10 changes: 4 additions & 6 deletions infra/cifuzz/filestore/github_actions/github_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ class GetHttpAuthHeaders(unittest.TestCase):

def test_get_http_auth_headers(self):
"""Tests that get_http_auth_headers returns the correct result."""
token = 'example githubtoken'
run_config = test_helpers.create_run_config(token=token)
test_helpers.patch_environ(self)
os.environ['ACTIONS_RUNTIME_TOKEN'] = 'githubtoken'
expected_headers = {
'Authorization': f'token {token}',
'Accept': 'application/vnd.github.v3+json',
'Authorization': 'Bearer githubtoken',
}
self.assertEqual(expected_headers,
github_api.get_http_auth_headers(run_config))
self.assertEqual(expected_headers, github_api.get_http_auth_headers())