@@ -917,3 +917,84 @@ async def test_attribute_truncation(aio_client: Client, method, mock_method, cal
917917 assert "attributes" in kwargs ["json" ]
918918 assert kwargs ["json" ]["attributes" ]
919919 assert len (kwargs ["json" ]["attributes" ][0 ]["value" ]) == 128
920+
921+
922+ @pytest .mark .asyncio
923+ async def test_api_key_authorization_header ():
924+ """Test that API key authentication sets Authorization header correctly."""
925+ api_key = "test_api_key_12345"
926+ client = Client (endpoint = ENDPOINT , project = PROJECT , api_key = api_key )
927+
928+ # Get the session (which is ClientSession wrapper)
929+ session = await client .session ()
930+
931+ # Mock the underlying aiohttp.ClientSession within ClientSession
932+ # noinspection PyProtectedMember
933+ underlying_session_mock = mock .AsyncMock ()
934+
935+ # Mock response with status attribute
936+ response_mock = mock .Mock ()
937+ response_mock .status = 200
938+ response_mock .json = mock .AsyncMock (return_value = RETURN_GET_JSON )
939+ underlying_session_mock .get .return_value = response_mock
940+
941+ # noinspection PyProtectedMember
942+ session ._client = underlying_session_mock
943+ client ._skip_analytics = "1"
944+
945+ # Make a request
946+ await client .get_project_settings ()
947+
948+ # Verify the underlying session.get was called
949+ underlying_session_mock .get .assert_called_once ()
950+ call_kwargs = underlying_session_mock .get .call_args_list [0 ][1 ]
951+
952+ # Verify Authorization header is set correctly
953+ assert "headers" in call_kwargs
954+ assert "Authorization" in call_kwargs ["headers" ]
955+ assert call_kwargs ["headers" ]["Authorization" ] == f"Bearer { api_key } "
956+
957+
958+ @pytest .mark .asyncio
959+ async def test_oauth_authorization_header ():
960+ """Test that OAuth authentication sets Authorization header correctly."""
961+ client = Client (
962+ endpoint = ENDPOINT ,
963+ project = PROJECT ,
964+ oauth_oauth_uri = "https://example.com/oauth/token" ,
965+ oauth_username = "test_user" ,
966+ oauth_password = "test_password" ,
967+ oauth_client_id = "test_client_id" ,
968+ )
969+
970+ # Get the session (which is ClientSession wrapper)
971+ session = await client .session ()
972+
973+ # Mock the underlying aiohttp.ClientSession within ClientSession
974+ # noinspection PyProtectedMember
975+ underlying_session_mock = mock .AsyncMock ()
976+
977+ # Mock response with status attribute
978+ response_mock = mock .Mock ()
979+ response_mock .status = 200
980+ response_mock .json = mock .AsyncMock (return_value = RETURN_GET_JSON )
981+ underlying_session_mock .get .return_value = response_mock
982+
983+ # noinspection PyProtectedMember
984+ session ._client = underlying_session_mock
985+ client ._skip_analytics = "1"
986+
987+ # Mock the Auth.get() method to return a test token
988+ test_token = "Bearer test_oauth_token_xyz"
989+ with mock .patch .object (client .auth , "get" , return_value = test_token ):
990+ # Make a request
991+ await client .get_project_settings ()
992+
993+ # Verify the underlying session.get was called
994+ underlying_session_mock .get .assert_called_once ()
995+ call_kwargs = underlying_session_mock .get .call_args_list [0 ][1 ]
996+
997+ # Verify Authorization header is set correctly
998+ assert "headers" in call_kwargs
999+ assert "Authorization" in call_kwargs ["headers" ]
1000+ assert call_kwargs ["headers" ]["Authorization" ] == test_token
0 commit comments