fix: Tool secret keys must use a case-insensitive comparison (#275)

Missed one test case here.
This commit is contained in:
Nate Barbettini 2025-03-04 14:33:55 -08:00 committed by GitHub
parent e9ee3bba40
commit 4a0e2b8667
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 9 deletions

View file

@ -2,7 +2,7 @@ import os
from dataclasses import dataclass
from typing import Any, Literal, Optional, Union
from pydantic import BaseModel, Field, field_validator
from pydantic import BaseModel, Field
# allow for custom tool name separator
TOOL_NAME_SEPARATOR = os.getenv("ARCADE_TOOL_NAME_SEPARATOR", ".")
@ -262,12 +262,6 @@ class ToolContext(BaseModel):
user_id: str | None = None
"""The user ID for the tool invocation (if any)."""
@field_validator("secrets", mode="before")
def lower_keys(cls, v: dict[str, ToolSecretItem] | None) -> dict[str, ToolSecretItem] | None:
if isinstance(v, dict):
return {k.lower(): value for k, value in v.items()}
return v
def get_auth_token_or_empty(self) -> str:
"""Retrieve the authorization token, or return an empty string if not available."""
return self.authorization.token if self.authorization and self.authorization.token else ""
@ -282,7 +276,7 @@ class ToolContext(BaseModel):
normalized_key = key.lower()
for secret in self.secrets:
if secret.key == normalized_key:
if secret.key.lower() == normalized_key:
return secret.value
raise ValueError(f"Secret {key} not found in context.")

View file

@ -38,7 +38,7 @@ def test_get_secret_valid():
def test_get_secret_with_case_insensitive_key():
key = "my_key"
key = "My_key"
val = "secret_value"
secrets = [ToolSecretItem(key=key, value=val)]
tool_context = ToolContext(secrets=secrets)