test: assert Azure endpoint hostname instead of substring match

CodeQL flagged the `"test.openai.azure.com" in llm.endpoint` substring
check as incomplete URL sanitization — the substring could match in
an arbitrary position. Parse the URL and assert against
`urlparse(...).hostname` instead, which is the precise check we want.
This commit is contained in:
Greyson LaLonde
2026-04-12 05:13:57 +08:00
parent 1dc310844c
commit 760a3f2b05

View File

@@ -2,6 +2,7 @@ import os
import sys
import types
from unittest.mock import patch, MagicMock, Mock
from urllib.parse import urlparse
import pytest
from crewai.llm import LLM
@@ -442,7 +443,7 @@ def test_azure_lazy_build_reads_env_vars_set_after_construction():
assert client is not None
assert llm.api_key == "late-key"
assert llm.endpoint is not None
assert "test.openai.azure.com" in llm.endpoint
assert urlparse(llm.endpoint).hostname == "test.openai.azure.com"
assert llm.is_azure_openai_endpoint is True