2626from aws_advanced_python_wrapper .iam_plugin import IamAuthPlugin , TokenInfo
2727from aws_advanced_python_wrapper .utils .properties import (Properties ,
2828 WrapperProperties )
29+ from aws_advanced_python_wrapper .utils .rds_token_utils import RDSTokenUtils
2930
3031_GENERATED_TOKEN = "generated_token"
3132_TEST_TOKEN = "test_token"
@@ -99,6 +100,7 @@ def test_pg_connect_valid_token_in_cache(mocker, mock_plugin_service, mock_sessi
99100 _token_cache [_PG_CACHE_KEY ] = initial_token
100101
101102 target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
103+ RDSTokenUtils (),
102104 mock_session )
103105 target_plugin .connect (
104106 target_driver_func = mocker .MagicMock (),
@@ -127,6 +129,7 @@ def test_pg_connect_with_invalid_port_fall_backs_to_host_port(
127129 assert test_props .get ("password" ) is None
128130
129131 target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
132+ RDSTokenUtils (),
130133 mock_session )
131134 target_plugin .connect (
132135 target_driver_func = mocker .MagicMock (),
@@ -163,6 +166,7 @@ def test_pg_connect_with_invalid_port_and_no_host_port_fall_backs_to_host_port(
163166 assert test_props .get ("password" ) is None
164167
165168 target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
169+ RDSTokenUtils (),
166170 mock_session )
167171 target_plugin .connect (
168172 target_driver_func = mocker .MagicMock (),
@@ -195,7 +199,9 @@ def test_connect_expired_token_in_cache(mocker, mock_plugin_service, mock_sessio
195199 _token_cache [_PG_CACHE_KEY ] = initial_token
196200
197201 mock_func .side_effect = Exception ("generic exception" )
198- target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , mock_session )
202+ target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
203+ RDSTokenUtils (),
204+ mock_session )
199205 with pytest .raises (Exception ):
200206 target_plugin .connect (
201207 target_driver_func = mocker .MagicMock (),
@@ -220,7 +226,9 @@ def test_connect_expired_token_in_cache(mocker, mock_plugin_service, mock_sessio
220226@patch ("aws_advanced_python_wrapper.iam_plugin.IamAuthPlugin._token_cache" , _token_cache )
221227def test_connect_empty_cache (mocker , mock_plugin_service , mock_connection , mock_session , mock_func , mock_client , mock_dialect ):
222228 test_props : Properties = Properties ({"user" : "postgresqlUser" })
223- target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , mock_session )
229+ target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
230+ RDSTokenUtils (),
231+ mock_session )
224232 actual_connection = target_plugin .connect (
225233 target_driver_func = mocker .MagicMock (),
226234 driver_dialect = mock_dialect ,
@@ -251,7 +259,9 @@ def test_connect_with_specified_port(mocker, mock_plugin_service, mock_session,
251259 # Assert no password has been set
252260 assert test_props .get ("password" ) is None
253261
254- target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , mock_session )
262+ target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
263+ RDSTokenUtils (),
264+ mock_session )
255265 target_plugin .connect (
256266 target_driver_func = mocker .MagicMock (),
257267 driver_dialect = mock_dialect ,
@@ -285,7 +295,9 @@ def test_connect_with_specified_iam_default_port(mocker, mock_plugin_service, mo
285295 # Assert no password has been set
286296 assert test_props .get ("password" ) is None
287297
288- target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , mock_session )
298+ target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
299+ RDSTokenUtils (),
300+ mock_session )
289301 target_plugin .connect (
290302 target_driver_func = mocker .MagicMock (),
291303 driver_dialect = mock_dialect ,
@@ -323,7 +335,9 @@ def test_connect_with_specified_region(mocker, mock_plugin_service, mock_session
323335 assert test_props .get ("password" ) is None
324336
325337 mock_client .generate_db_auth_token .return_value = f"{ _TEST_TOKEN } :{ iam_region } "
326- target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , mock_session )
338+ target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
339+ RDSTokenUtils (),
340+ mock_session )
327341 target_plugin .connect (
328342 target_driver_func = mocker .MagicMock (),
329343 driver_dialect = mock_dialect ,
@@ -369,7 +383,9 @@ def test_connect_with_specified_host(iam_host: str, mocker, mock_plugin_service,
369383 assert test_props .get ("password" ) is None
370384
371385 mock_client .generate_db_auth_token .return_value = f"{ _TEST_TOKEN } :{ iam_host } "
372- target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , mock_session )
386+ target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service ,
387+ RDSTokenUtils (),
388+ mock_session )
373389 target_plugin .connect (
374390 target_driver_func = mocker .MagicMock (),
375391 driver_dialect = mock_dialect ,
@@ -411,7 +427,7 @@ def test_aws_supported_regions_url_exists():
411427def test_invalid_iam_host (host , mocker , mock_plugin_service , mock_session , mock_func , mock_client , mock_dialect ):
412428 test_props : Properties = Properties ({"user" : "postgresqlUser" })
413429 with pytest .raises (AwsWrapperError ):
414- target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , mock_session )
430+ target_plugin : IamAuthPlugin = IamAuthPlugin (mock_plugin_service , RDSTokenUtils (), mock_session )
415431 target_plugin .connect (
416432 target_driver_func = mocker .MagicMock (),
417433 driver_dialect = mock_dialect ,
0 commit comments