@@ -75,13 +75,11 @@ def test_get_certificate_content_invalid_file_content(self, api_client):
7575 invalid_file_path = invalid_file .name
7676
7777 try :
78- result = api_client ._get_certificate_content (invalid_file_path )
79-
80- assert result is None
81- api_client .app_logger .warning .assert_called_with (
82- "File at HTTPS_CA_CERTIFICATES path does not contain valid certificate" ,
83- {"file_path" : invalid_file_path },
84- )
78+ with pytest .raises (
79+ ValueError ,
80+ match = "File at HTTPS_CA_CERTIFICATES path does not contain valid certificate" ,
81+ ):
82+ api_client ._get_certificate_content (invalid_file_path )
8583 finally :
8684 # Clean up
8785 os .unlink (invalid_file_path )
@@ -90,15 +88,19 @@ def test_get_certificate_content_nonexistent_file(self, api_client):
9088 """Test _get_certificate_content with a nonexistent file path."""
9189 nonexistent_path = "/tmp/nonexistent_certificate.crt"
9290
93- result = api_client ._get_certificate_content (nonexistent_path )
94-
95- assert result is None
91+ with pytest .raises (
92+ ValueError ,
93+ match = "HTTPS_CA_CERTIFICATES is not a valid certificate or file path" ,
94+ ):
95+ api_client ._get_certificate_content (nonexistent_path )
9696
9797 def test_get_certificate_content_invalid_content (self , api_client ):
9898 """Test _get_certificate_content with invalid content (not PEM, not file)."""
99- result = api_client ._get_certificate_content (self .INVALID_CONTENT )
100-
101- assert result is None
99+ with pytest .raises (
100+ ValueError ,
101+ match = "HTTPS_CA_CERTIFICATES is not a valid certificate or file path" ,
102+ ):
103+ api_client ._get_certificate_content (self .INVALID_CONTENT )
102104
103105 def test_get_certificate_content_whitespace_handling (self , api_client ):
104106 """Test _get_certificate_content handles whitespace correctly."""
@@ -174,13 +176,19 @@ def test_setup_proxy_certificates_with_invalid_path(self, mock_mkdtemp, api_clie
174176
175177 mock_mkdtemp .return_value = "/tmp/test_certs"
176178
177- # Mock _get_certificate_content to return None (invalid)
178- with patch .object (api_client , "_get_certificate_content" , return_value = None ):
179- api_client ._setup_proxy_certificates ()
179+ # Mock _get_certificate_content to raise ValueError (invalid)
180+ with patch .object (
181+ api_client ,
182+ "_get_certificate_content" ,
183+ side_effect = ValueError ("Invalid certificate" ),
184+ ):
185+ with pytest .raises (ValueError , match = "Invalid certificate" ):
186+ api_client ._setup_proxy_certificates ()
180187
181- # Should log warning and return early
182- api_client .app_logger .warning .assert_called ()
183- assert not hasattr (api_client , "ssl_verify" ) or api_client .ssl_verify is False
188+ # Should log error before raising
189+ api_client .app_logger .error .assert_called_with (
190+ "Failed to setup proxy certificates" , {"error" : "Invalid certificate" }
191+ )
184192
185193 # Cleanup
186194 opencti_api_client ._PROXY_CERT_BUNDLE = None
0 commit comments