Exemple #1
0
 def test_rename_success(self):
     """Test a successful rename (then rename it back)"""
     ret = True
     try:
         with patch_args(subparser_name='rename',
                         identity='r1',
                         nopassphrase='true',
                         all=True,
                         pwname='test',
                         rename='retest',
                         overwrite='true'):
             with mock.patch.object(builtins, 'input', lambda _: 'y'):
                 rename.Rename(cli.Cli())
         with patch_args(subparser_name='rename',
                         identity='r1',
                         nopassphrase='true',
                         all=True,
                         pwname='retest',
                         rename='test',
                         overwrite="true"):
             with mock.patch.object(builtins, 'input', lambda _: 'y'):
                 rename.Rename(cli.Cli())
     except DecryptionError:
         ret = False
     self.assertTrue(ret)
Exemple #2
0
 def test_list_one(self):
     """test list functionality for one password"""
     with patch_args(subparser_name='list', identity='r1', nopassphrase="true"):
         with captured_output() as (out, _):
             pklist.List(cli.Cli())
     output = yaml.safe_load(out.getvalue().replace('\t', ' '))
     self.assertDictEqual(output, self.password_list_1)
Exemple #3
0
 def test_info_no_pass(self):
     """Test what happens when pwname is not supplied"""
     with patch_args(subparser_name='info',
                     identity='r1',
                     nopassphrase="true",
                     pwname=None):
         with self.assertRaises(CliArgumentError) as context:
             info.Info(cli.Cli())
     self.assertEqual(context.exception.msg, ERROR_MSGS['pwname'])
Exemple #4
0
 def test_list_one(self, subparser_name):
     """test list functionality"""
     ret = False
     with captured_output() as (out, _):
         pklist.List(cli.Cli())
     output = "".join(out.getvalue().strip().split())
     if output == PASSWORD_LIST_1:
         ret = True
     self.assertTrue(ret)
Exemple #5
0
 def test_show_nopass_error(self, subparser_name):
     """test decryption functionality"""
     ret = False
     try:
         show.Show(cli.Cli())
     except KeyError as error:
         if str(error) == "'pwname'":
             ret = str(error)
     self.assertEqual(ret, "'pwname'")
Exemple #6
0
 def test_distribute_cli_error(self):
     """Test what happens with pwname is not supplied"""
     with self.assertRaises(CliArgumentError) as context:
         with patch_args(subparser_name='distribute',
                         identity='r1',
                         nopassphrase='true',
                         pwname=None):
             distribute.Distribute(cli.Cli())
     self.assertEqual(context.exception.msg, ERROR_MSGS['pwname'])
Exemple #7
0
 def test_recipient_not_in_database(self):
     """test bad recipient functionality"""
     with self.assertRaises(CliArgumentError) as context:
         with patch_args(subparser_name='list', identity='bleh', nopassphrase="true"):
             pklist.List(cli.Cli())
     self.assertEqual(
         context.exception.msg,
         ERROR_MSGS['rep']
     )
Exemple #8
0
 def test_showall_decryption_error(self, subparser_name):
     """test decryption functionality"""
     ret = False
     try:
         show.Show(cli.Cli())
     except DecryptionError as error:
         if error.msg == BADPIN:
             ret = True
     self.assertTrue(ret)
Exemple #9
0
 def test_recipient_not_in_database(self, subparser_name):
     """test decryption functionality"""
     ret = False
     try:
         show.Show(cli.Cli())
     except CliArgumentError as error:
         if error.msg == "Error: Your user 'bleh' is not in the recipient database":
             ret = True
     self.assertTrue(ret)
Exemple #10
0
 def test_distribute_cli_error(self, subparser_name):
     """test decryption functionality"""
     ret = False
     try:
         distribute.Distribute(cli.Cli())
     except CliArgumentError as error:
         if error.msg == "'pwname' is a required argument":
             ret = True
     self.assertTrue(ret)
Exemple #11
0
 def test_recipient_not_in_database(self):
     """Test what happens with a recipient is not within the appropriate directory"""
     with self.assertRaises(CliArgumentError) as context:
         with patch_args(subparser_name='distribute',
                         identity='bleh',
                         nopassphrase='true',
                         pwname='test'):
             distribute.Distribute(cli.Cli())
     self.assertEqual(context.exception.msg, ERROR_MSGS['rep'])
Exemple #12
0
 def test_recipient_not_in_database(self):
     """test what happens when the recipient is not in the appropriate directory"""
     with self.assertRaises(CliArgumentError) as context:
         with patch_args(subparser_name='show',
                         identity='bleh',
                         nopassphrase='true',
                         all=None,
                         pwname='test'):
             show.Show(cli.Cli())
     self.assertEqual(context.exception.msg, ERROR_MSGS['rep'])
Exemple #13
0
 def test_generate_no_pass(self):
     """test what happens with pwname is not supplied"""
     with self.assertRaises(CliArgumentError) as context:
         with patch_args(subparser_name='generate',
                         identity='r3',
                         nopassphrase='true',
                         pwname=None):
             with mock.patch.object(builtins, 'input', lambda _: 'y'):
                 with mock.patch.object(getpass, 'getpass', lambda _: 'y'):
                     generate.Generate(cli.Cli())
     self.assertEqual(context.exception.msg, ERROR_MSGS['pwname'])
Exemple #14
0
 def test_rename_cli_error(self):
     """Test what happens when pwname is not supplied"""
     with self.assertRaises(CliArgumentError) as context:
         with patch_args(subparser_name='rename',
                         identity='r1',
                         nopassphrase='true',
                         all=True,
                         rename='test',
                         overwrite='true'):
             rename.Rename(cli.Cli())
     self.assertEqual(context.exception.msg, ERROR_MSGS['pwname'])
Exemple #15
0
 def test_info(self):
     """Test what info shows on a password"""
     with patch_args(subparser_name='info',
                     identity='r1',
                     nopassphrase="true",
                     pwname='test'):
         with captured_output() as (out, _):
             info.Info(cli.Cli())
     output = yaml.safe_load(out.getvalue())
     del output['Earliest distribute timestamp']
     self.assertDictEqual(output, self.check_dict)
Exemple #16
0
 def test_decryption(self):
     """Test successful decryption"""
     ret = True
     try:
         with patch_args(subparser_name='show',
                         identity='r1',
                         nopassphrase='true',
                         all=None,
                         pwname='test'):
             show.Show(cli.Cli())
     except DecryptionError:
         ret = False
     self.assertTrue(ret)
Exemple #17
0
 def test_show_nopass_error(self):
     """Test what happens when neither pwname or the all flag are supplied"""
     ret = False
     try:
         with patch_args(subparser_name='show',
                         identity='r1',
                         nopassphrase='true',
                         all=None):
             show.Show(cli.Cli())
     except KeyError as error:
         if str(error) == "'pwname'":
             ret = str(error)
     self.assertEqual(ret, "'pwname'")
Exemple #18
0
 def test_modify_success(self):
     """Test modifying the metadata of a password"""
     ret = True
     try:
         with patch_args(subparser_name='modify',
                         identity='r3',
                         nopassphrase='true',
                         pwname='gentest'):
             with mock.patch.object(builtins, 'input', lambda _: 'y'):
                 modify.Modify(cli.Cli())
     except DecryptionError:
         ret = False
     self.assertTrue(ret)
Exemple #19
0
 def test_distribute_success(self):
     """Test a successful distribute"""
     ret = True
     try:
         with patch_args(subparser_name='distribute',
                         identity='r1',
                         nopassphrase='true',
                         pwname='test'):
             with mock.patch.object(builtins, 'input', lambda _: 'y'):
                 distribute.Distribute(cli.Cli())
     except DecryptionError:
         ret = False
     self.assertTrue(ret)
Exemple #20
0
 def test_showall_decryption(self):
     """Test showing all passwords"""
     ret = True
     try:
         with patch_args(subparser_name='show',
                         identity='r1',
                         nopassphrase='true',
                         all=True,
                         pwname='*test*'):
             show.Show(cli.Cli())
     except DecryptionError:
         ret = False
     self.assertTrue(ret)
Exemple #21
0
 def test_generate_success(self):
     """Test a successful generation of a password"""
     ret = True
     try:
         with patch_args(subparser_name='generate',
                         identity='r3',
                         nopassphrase='true',
                         pwname='gentest'):
             with mock.patch.object(builtins, 'input', lambda _: 'y'):
                 with mock.patch.object(getpass, 'getpass', lambda _: 'y'):
                     generate.Generate(cli.Cli())
     except DecryptionError:
         ret = False
     self.assertTrue(ret)
Exemple #22
0
 def test_listrecipients(self):
     """Test a listing of our recipients"""
     self.maxDiff = None
     with patch_args(subparser_name='listrecipients',
                     identity='r1',
                     nopassphrase="true",
                     filter="r3"):
         with captured_output() as (out, _):
             listrecipients.Listrecipients(cli.Cli())
     output = yaml.safe_load(out.getvalue().replace('\t', '  '))
     # we remove these things because the actual values depend on creation
     # moreover, some of the outputs on different operating systems appear
     # to utilize different delimiters.
     del output['r3']['certs']['enddate']
     del output['r3']['certs']['subjecthash']
     del output['r3']['certs']['issuerhash']
     del output['r3']['certs']['fingerprint']
     del output['r3']['certs']['subject']
     del output['r3']['certs']['issuer']
     self.assertDictEqual(output, self.out_dict)