77
88
99class TestSSLConfig (unittest .TestCase ):
10- @patch (' requests.session' )
11- @patch (' tableauserverclient.server.endpoint.Endpoint.set_parameters' )
10+ @patch (" requests.session" )
11+ @patch (" tableauserverclient.server.endpoint.Endpoint.set_parameters" )
1212 def setUp (self , mock_set_parameters , mock_session ):
1313 """Set up test fixtures with mocked session and request validation"""
1414 # Mock the session
1515 self .mock_session = MagicMock ()
1616 mock_session .return_value = self .mock_session
17-
17+
1818 # Mock request preparation
1919 self .mock_request = MagicMock ()
2020 self .mock_session .prepare_request .return_value = self .mock_request
21-
21+
2222 # Create server instance with mocked components
23- self .server = Server (' http://test' )
23+ self .server = Server (" http://test" )
2424
2525 def test_default_ssl_config (self ):
2626 """Test that by default, no custom SSL context is used"""
2727 self .assertIsNone (self .server ._ssl_context )
28- self .assertNotIn (' verify' , self .server .http_options )
28+ self .assertNotIn (" verify" , self .server .http_options )
2929
30- @patch (' ssl.create_default_context' )
30+ @patch (" ssl.create_default_context" )
3131 def test_weak_dh_config (self , mock_create_context ):
3232 """Test that weak DH keys can be allowed when configured"""
3333 # Setup mock SSL context
@@ -36,15 +36,15 @@ def test_weak_dh_config(self, mock_create_context):
3636
3737 # Configure SSL with weak DH
3838 self .server .configure_ssl (allow_weak_dh = True )
39-
39+
4040 # Verify SSL context was created and configured correctly
4141 mock_create_context .assert_called_once ()
4242 mock_context .set_dh_parameters .assert_called_once_with (min_key_bits = 512 )
43-
43+
4444 # Verify context was added to http options
45- self .assertEqual (self .server .http_options [' verify' ], mock_context )
45+ self .assertEqual (self .server .http_options [" verify" ], mock_context )
4646
47- @patch (' ssl.create_default_context' )
47+ @patch (" ssl.create_default_context" )
4848 def test_disable_weak_dh_config (self , mock_create_context ):
4949 """Test that SSL config can be reset to defaults"""
5050 # Setup mock SSL context
@@ -54,23 +54,24 @@ def test_disable_weak_dh_config(self, mock_create_context):
5454 # First enable weak DH
5555 self .server .configure_ssl (allow_weak_dh = True )
5656 self .assertIsNotNone (self .server ._ssl_context )
57- self .assertIn (' verify' , self .server .http_options )
57+ self .assertIn (" verify" , self .server .http_options )
5858
5959 # Then disable it
6060 self .server .configure_ssl (allow_weak_dh = False )
6161 self .assertIsNone (self .server ._ssl_context )
62- self .assertNotIn (' verify' , self .server .http_options )
62+ self .assertNotIn (" verify" , self .server .http_options )
6363
64- @patch (' ssl.create_default_context' )
64+ @patch (" ssl.create_default_context" )
6565 def test_warning_on_weak_dh (self , mock_create_context ):
6666 """Test that a warning is logged when enabling weak DH keys"""
6767 logging .getLogger ().setLevel (logging .WARNING )
68- with self .assertLogs (level = ' WARNING' ) as log :
68+ with self .assertLogs (level = " WARNING" ) as log :
6969 self .server .configure_ssl (allow_weak_dh = True )
7070 self .assertTrue (
71- any (' WARNING: Allowing weak Diffie-Hellman keys' in record for record in log .output ),
72- "Expected warning about weak DH keys was not logged"
71+ any (" WARNING: Allowing weak Diffie-Hellman keys" in record for record in log .output ),
72+ "Expected warning about weak DH keys was not logged" ,
7373 )
7474
75- if __name__ == '__main__' :
76- unittest .main ()
75+
76+ if __name__ == "__main__" :
77+ unittest .main ()
0 commit comments