def test_take_action_good_pasphrase(self): """ Ensure the take_action method processes the arguments and good user input correctly: an rsa keypair is created, output files specified and the utils.save_keys method is called. """ with mock.patch('getpass.getpass', return_value='passphrase'): keygen = KeyGen(None, None) with mock.patch('drogulus.commands.keygen.save_keys') as sk: parsed_args = mock.MagicMock() parsed_args.size = 512 mock_pub = mock.MagicMock() mock_pub.save_pkcs1 = mock.MagicMock(return_value=b'pub') mock_priv = mock.MagicMock() mock_priv.save_pkcs1 = mock.MagicMock(return_value=b'priv') return_val = (mock_pub, mock_priv) with mock.patch('rsa.newkeys', return_value=return_val) as mock_newkeys: keygen.take_action(parsed_args) self.assertEqual(1, mock_newkeys.call_count) self.assertEqual(1, sk.call_count) output_pub = os.path.join(data_dir(), '{}.pub'.format(APPNAME)) output_priv = os.path.join(data_dir(), '{}.scrypt'.format(APPNAME)) self.assertEqual(sk.call_args[0][0], 'priv') self.assertEqual(sk.call_args[0][1], 'pub') self.assertEqual(sk.call_args[0][2], 'passphrase') self.assertEqual(sk.call_args[0][3], output_priv) self.assertEqual(sk.call_args[0][4], output_pub)
def test_take_action_passphrase_mismatch(self): """ If the requested passphrase doesn't match its confirmation then complain. """ with mock.patch('getpass.getpass', side_effect=['good', 'bad']): keygen = KeyGen(None, None) parsed_args = mock.MagicMock() parsed_args.size = 512 with self.assertRaises(ValueError) as ex: keygen.take_action(parsed_args) self.assertEqual('Passphrase and confirmation did not match.', ex.exception.args[0])