Implement AI code review suggestions

- Enhanced SSL function documentation with detailed examples and environment variable precedence
- Added CA bundle file format validation (.pem, .crt, .cer) with warnings for unsupported formats
- Improved error handling with structured solutions and current CA bundle path display
- Added comprehensive tests for file format validation and warning scenarios
- Enhanced user guidance for SSL certificate configuration issues

Addresses feedback from joaomdmoura's AI code review for better documentation,
error handling, and path validation as requested.

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-06-09 14:46:50 +00:00
parent 2a48e24d98
commit 06a5689e8a
2 changed files with 48 additions and 4 deletions

View File

@@ -71,6 +71,35 @@ class TestSSLConfiguration:
result = get_ssl_verify_config()
assert result == '/path/to/certifi/cacert.pem'
def test_get_ssl_verify_config_file_format_validation(self):
"""Test that CA bundle file format validation works correctly."""
with tempfile.NamedTemporaryFile(suffix=".pem", delete=False) as temp_file:
temp_path = temp_file.name
try:
with patch.dict(os.environ, {"REQUESTS_CA_BUNDLE": temp_path}):
result = get_ssl_verify_config()
assert result == temp_path
finally:
os.unlink(temp_path)
def test_get_ssl_verify_config_unsupported_format_warning(self):
"""Test that unsupported file formats still work but show warning."""
with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as temp_file:
temp_path = temp_file.name
try:
with patch.dict(os.environ, {"REQUESTS_CA_BUNDLE": temp_path}):
with patch('click.secho') as mock_secho:
result = get_ssl_verify_config()
assert result == temp_path
mock_secho.assert_called_with(
f"Warning: CA bundle file {temp_path} may not be in expected format (.pem, .crt, .cer)",
fg="yellow"
)
finally:
os.unlink(temp_path)
class TestFetchProviderDataSSL:
def test_fetch_provider_data_uses_ssl_config(self):
@@ -99,7 +128,8 @@ class TestFetchProviderDataSSL:
assert result is None
mock_secho.assert_any_call("SSL certificate verification failed: SSL verification failed", fg="red")
mock_secho.assert_any_call("Try setting REQUESTS_CA_BUNDLE environment variable to your CA bundle path", fg="yellow")
mock_secho.assert_any_call("Solutions:", fg="cyan")
mock_secho.assert_any_call(" 1. Set REQUESTS_CA_BUNDLE environment variable to your CA bundle path", fg="yellow")
def test_fetch_provider_data_general_request_error(self):
cache_file = Path("/tmp/test_cache.json")