cast X-Realms header to

jsonified string
This commit is contained in:
Joey Orlando 2024-01-25 14:41:35 -05:00
parent add6df570f
commit 4220199a86
No known key found for this signature in database
GPG key ID: 469E88366B17F644
2 changed files with 19 additions and 12 deletions

View file

@ -1,4 +1,5 @@
import enum
import json
import typing
from urllib.parse import urljoin
@ -43,17 +44,20 @@ class CloudAuthApiClient:
org_id = org.org_id
stack_id = org.stack_id
# NOTE: header values must always be strings
headers = {
"Authorization": f"Bearer {self.api_token}",
# need to cast to str otherwise - requests.exceptions.InvalidHeader: Header part ... from ('X-Org-ID', 5000)
# must be of type str or bytes, not <class 'int'>
"X-Org-ID": str(org_id),
"X-Realms": [
{
"type": "stack",
"identifier": str(stack_id),
},
],
"X-Realms": json.dumps(
[
{
"type": "stack",
"identifier": str(stack_id),
},
]
),
}
url = urljoin(self.api_base_url, "v1/sign")

View file

@ -1,3 +1,4 @@
import json
from unittest.mock import patch
import pytest
@ -66,12 +67,14 @@ def test_request_signed_token(mock_requests, make_organization, response_status_
headers={
"Authorization": f"Bearer {GRAFANA_CLOUD_AUTH_API_SYSTEM_TOKEN}",
"X-Org-ID": str(org_id),
"X-Realms": [
{
"type": "stack",
"identifier": str(stack_id),
},
],
"X-Realms": json.dumps(
[
{
"type": "stack",
"identifier": str(stack_id),
},
]
),
},
json={
"claims": claims,