@@ -1211,28 +1211,22 @@ def test_build_factor_name_webauthn_registered(self, mock_input):
12111211 # result = self.client.choose_app()
12121212 # self.assertEqual(result['name'], 'Sample AWS Account')
12131213
1214- @patch ('keyring.get_password' )
1215- @patch ('keyring.get_keyring' )
1214+ @patch ('gimme_aws_creds.okta_classic. keyring.get_password' )
1215+ @patch ('gimme_aws_creds.okta_classic.OktaClassicClient.KEYRING_ENABLED' , True )
12161216 @patch ('builtins.input' , return_value = 'testuser@example.com' )
12171217 @patch ('getpass.getpass' , return_value = 'testpass123' )
1218- def test_get_username_password_creds_with_keyring (self , mock_pass , mock_input , mock_get_keyring , mock_get_password ):
1218+ def test_get_username_password_creds_with_keyring (self , mock_pass , mock_input , mock_get_password ):
12191219 """Test password retrieval from keyring when available"""
1220- from keyring .backends .fail import Keyring as FailKeyring
1221-
1222- # Mock keyring as available (not FailKeyring)
1223- mock_keyring_instance = unittest .mock .MagicMock ()
1224- mock_get_keyring .return_value = mock_keyring_instance
1220+ # Mock keyring.get_password to return stored password
12251221 mock_get_password .return_value = 'stored_password'
12261222
1227- # Recreate client to pick up mocked keyring
1228- with patch ('gimme_aws_creds.okta_classic.keyring.get_keyring' , return_value = mock_keyring_instance ):
1229- client = self .setUp_client (self .okta_org_url , False )
1230- client ._use_keyring = True
1231-
1232- result = client ._get_username_password_creds ()
1233- self .assertEqual (result ['username' ], 'testuser@example.com' )
1234- self .assertEqual (result ['password' ], 'stored_password' )
1235- mock_get_password .assert_called_once_with (client .KEYRING_SERVICE , 'testuser@example.com' )
1223+ client = self .setUp_client (self .okta_org_url , False )
1224+ client ._use_keyring = True
1225+
1226+ result = client ._get_username_password_creds ()
1227+ self .assertEqual (result ['username' ], 'testuser@example.com' )
1228+ self .assertEqual (result ['password' ], 'stored_password' )
1229+ mock_get_password .assert_called_once_with (client .KEYRING_SERVICE , 'testuser@example.com' )
12361230
12371231 @patch ('keyring.get_keyring' )
12381232 @patch ('builtins.input' , return_value = 'testuser@example.com' )
@@ -1253,28 +1247,20 @@ def test_get_username_password_creds_with_fail_keyring(self, mock_pass, mock_inp
12531247 self .assertEqual (result ['username' ], 'testuser@example.com' )
12541248 self .assertEqual (result ['password' ], 'testpass123' )
12551249
1256- @patch ('keyring.set_password' )
1257- @patch ('keyring.get_password' , return_value = None )
1258- @patch ('keyring.get_keyring' )
1250+ @patch ('gimme_aws_creds.okta_classic. keyring.set_password' )
1251+ @patch ('gimme_aws_creds.okta_classic. keyring.get_password' , return_value = None )
1252+ @patch ('gimme_aws_creds.okta_classic.OktaClassicClient.KEYRING_ENABLED' , True )
12591253 @patch ('builtins.input' , side_effect = ['testuser@example.com' , 'y' ])
12601254 @patch ('getpass.getpass' , return_value = 'testpass123' )
1261- def test_password_storage_to_keyring (self , mock_pass , mock_input , mock_get_keyring , mock_get_password , mock_set_password ):
1255+ def test_password_storage_to_keyring (self , mock_pass , mock_input , mock_get_password , mock_set_password ):
12621256 """Test password storage to keyring when user confirms"""
1263- from keyring .backends .fail import Keyring as FailKeyring
1257+ client = self .setUp_client (self .okta_org_url , False )
1258+ client ._use_keyring = True
12641259
1265- # Mock keyring as available
1266- mock_keyring_instance = unittest .mock .MagicMock ()
1267- mock_get_keyring .return_value = mock_keyring_instance
1268-
1269- # Recreate client to pick up mocked keyring
1270- with patch ('gimme_aws_creds.okta_classic.keyring.get_keyring' , return_value = mock_keyring_instance ):
1271- client = self .setUp_client (self .okta_org_url , False )
1272- client ._use_keyring = True
1273-
1274- result = client ._get_username_password_creds ()
1275- self .assertEqual (result ['username' ], 'testuser@example.com' )
1276- self .assertEqual (result ['password' ], 'testpass123' )
1277- mock_set_password .assert_called_once_with (client .KEYRING_SERVICE , 'testuser@example.com' , 'testpass123' )
1260+ result = client ._get_username_password_creds ()
1261+ self .assertEqual (result ['username' ], 'testuser@example.com' )
1262+ self .assertEqual (result ['password' ], 'testpass123' )
1263+ mock_set_password .assert_called_once_with (client .KEYRING_SERVICE , 'testuser@example.com' , 'testpass123' )
12781264
12791265 @patch ('keyring.delete_password' )
12801266 @patch ('keyring.get_keyring' )
0 commit comments