Skip to content

Commit b7d74f3

Browse files
authored
Merge branch 'trunk' into dependabot/github_actions/actions-06a2827400
2 parents fffe86c + 4aa42f4 commit b7d74f3

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

spicepy/_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def __init__(self, grpc: str, api_key: str, tls_root_certs, user_agent=None):
219219
self._authenticate()
220220

221221
def _authenticate(self):
222-
if self._api_key is not None:
222+
if self._api_key:
223223
self.headers = [
224224
self._flight_client.authenticate_basic_token("", self._api_key),
225225
_SpiceFlight._user_agent(),

tests/test_client.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,35 @@ def test_spice_flight_authenticate_without_api_key(
908908
assert len(flight_instance.headers) == 1
909909
assert flight_instance.headers[0][0] == b"user-agent"
910910

911+
@patch("spicepy._client.flight")
912+
def test_spice_flight_authenticate_with_empty_string_api_key(
913+
self,
914+
mock_flight: MagicMock,
915+
) -> None:
916+
"""Test _SpiceFlight authentication with empty string API key.
917+
918+
Empty string API key should be treated the same as None - no authentication
919+
should be attempted. This prevents gRPC errors like 'Metadata keys cannot
920+
be zero length' that occur when authenticate_basic_token is called with
921+
empty credentials.
922+
"""
923+
from spicepy._client import _SpiceFlight
924+
925+
mock_client = MagicMock()
926+
mock_flight.connect.return_value = mock_client
927+
928+
flight_instance = _SpiceFlight(
929+
grpc="grpc://localhost:50051",
930+
api_key="",
931+
tls_root_certs=b"cert",
932+
)
933+
934+
# authenticate_basic_token should not be called when api_key is empty string
935+
mock_client.authenticate_basic_token.assert_not_called()
936+
# Headers should only contain user-agent
937+
assert len(flight_instance.headers) == 1
938+
assert flight_instance.headers[0][0] == b"user-agent"
939+
911940

912941
class TestArrowFlightCallThread:
913942
"""Test _ArrowFlightCallThread class."""

0 commit comments

Comments
 (0)