@@ -173,6 +173,37 @@ def test_no_cached_token(mocker, mock_plugin_service, mock_session, mock_func, m
173173 assert WrapperProperties .PASSWORD .get (test_props ) == _TEST_TOKEN
174174
175175
176+ @patch ("aws_advanced_python_wrapper.federated_plugin.FederatedAuthPlugin._token_cache" , _token_cache )
177+ def test_no_cached_token_raises_exception (mocker , mock_plugin_service , mock_session , mock_func , mock_client , mock_dialect ,
178+ mock_credentials_provider_factory ):
179+ test_props : Properties = Properties (
180+ {"plugins" : "federated_auth" , "user" : "postgresqlUser" , "idp_username" : "user" , "idp_password" : "password" })
181+ WrapperProperties .DB_USER .set (test_props , _DB_USER )
182+
183+ exception_message = "generic exception"
184+ mock_func .side_effect = Exception (exception_message )
185+
186+ target_plugin : FederatedAuthPlugin = FederatedAuthPlugin (mock_plugin_service , mock_credentials_provider_factory ,
187+ mock_session )
188+ with pytest .raises (Exception ) as e_info :
189+ target_plugin .connect (
190+ target_driver_func = mocker .MagicMock (),
191+ driver_dialect = mock_dialect ,
192+ host_info = _PG_HOST_INFO ,
193+ props = test_props ,
194+ is_initial_connection = False ,
195+ connect_func = mock_func )
196+
197+ mock_client .generate_db_auth_token .assert_called_with (
198+ DBHostname = "pg.testdb.us-east-2.rds.amazonaws.com" ,
199+ Port = 5432 ,
200+ DBUsername = "postgresqlUser"
201+ )
202+
203+ assert e_info .type == Exception
204+ assert str (e_info .value ) == exception_message
205+
206+
176207@patch ("aws_advanced_python_wrapper.federated_plugin.FederatedAuthPlugin._token_cache" , _token_cache )
177208def test_connect_with_specified_iam_host_port_region (mocker ,
178209 mock_plugin_service ,
0 commit comments