예제 #1
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)
예제 #2
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'")
예제 #3
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)
예제 #4
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'])
예제 #5
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'")
예제 #6
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)
예제 #7
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)
예제 #8
0
파일: pkinterface.py 프로젝트: olcf/pkpass
    def __init__(self):
        ####################################################################
        """Intialization function for class. Register all subcommands"""
        ####################################################################
        # Hash of registered subparser actions, mapping string to actual subparser
        self.actions = {}
        home = path.expanduser("~")
        defaultrc = None
        for file in [".pkpassrc", ".pkpassrc.yml", ".pkpassrc.yaml"]:
            if path.isfile(path.join(home, file)):
                defaultrc = path.join(home, file)
        if not defaultrc:
            defaultrc = path.join(home, ".pkpassrc")
        self.parser = ArgumentParser(description="Public Key Password Manager")
        self.parser.set_default_subparser = set_default_subparser
        self.parser.add_argument(
            "--config",
            type=str,
            help=
            "Path to a PKPass configuration file.  Defaults to '~/.pkpassrc{,.yml,.yaml}'",
            default=defaultrc,
        )
        self.parser.add_argument("--debug",
                                 action="store_true",
                                 help="Errors are more verbose")
        self.subparsers = self.parser.add_subparsers(help="sub-commands",
                                                     dest="subparser_name")

        card.Card(self)
        clip.Clip(self)
        create.Create(self)
        delete.Delete(self)
        distribute.Distribute(self)
        export.Export(self)
        generate.Generate(self)
        pkimport.Import(self)
        info.Info(self)
        pklist.List(self)
        listrecipients.Listrecipients(self)
        modify.Modify(self)
        recover.Recover(self)
        rename.Rename(self)
        show.Show(self)
        populate.Populate(self)
        update.Update(self)
        verifyinstall.VerifyInstall(self)
예제 #9
0
    def __init__(self, args, recipients_database):
        ####################################################################
        Cmd.__init__(self)
        # Hash of registered subparser actions, mapping string to actual subparser
        self.actions = {}
        self.parser = argparse.ArgumentParser(
            description='Public Key Password Manager')

        home = os.path.expanduser("~")
        self.parser.add_argument(
            '--config',
            type=str,
            help=
            "Path to a PKPass configuration file.  Defaults to '~/.pkpassrc'",
            default=os.path.join(home, '.pkpassrc'))
        self.subparsers = self.parser.add_subparsers(help='sub-commands',
                                                     dest='subparser_name')
        self.recipients_database = recipients_database
        self.parser.error = pkparse_error

        card.Card(self)
        clip.Clip(self)
        create.Create(self)
        delete.Delete(self)
        distribute.Distribute(self)
        export.Export(self)
        generate.Generate(self)
        pkimport.Import(self)
        pklist.List(self)
        listrecipients.Listrecipients(self)
        recover.Recover(self)
        rename.Rename(self)
        show.Show(self)
        update.Update(self)

        # Hold onto args passed on the command line
        self.pre_args = args
        # manually remove interpreter from command line so that argparse doesn't try to use it
        sys.argv.remove('interpreter')
        # change our cwd so users can tab complete
        self._change_pwstore()

        # We basically need to grab the first argument and ditch it
        self.parsedargs = {}
예제 #10
0
    def __init__(self):
        """ Intialization function for class. Register all subcommands   """
        ####################################################################
        # Hash of registered subparser actions, mapping string to actual subparser
        self.actions = {}
        home = os.path.expanduser("~")
        self.parser = argparse.ArgumentParser(
            description='Public Key Password Manager')
        self.parser.set_default_subparser = util.set_default_subparser
        self.parser.add_argument(
            '--config',
            type=str,
            help=
            "Path to a PKPass configuration file.  Defaults to '~/.pkpassrc'",
            default=os.path.join(home, '.pkpassrc'))
        self.parser.add_argument('--version',
                                 action='store_true',
                                 help='Show the version of PkPass and exit')
        self.subparsers = self.parser.add_subparsers(help='sub-commands',
                                                     dest='subparser_name')

        card.Card(self)
        clip.Clip(self)
        create.Create(self)
        delete.Delete(self)
        distribute.Distribute(self)
        export.Export(self)
        generate.Generate(self)
        pkimport.Import(self)
        interpreter.Interpreter(self)
        pklist.List(self)
        listrecipients.Listrecipients(self)
        recover.Recover(self)
        rename.Rename(self)
        show.Show(self)
        update.Update(self)

        self.parser.set_default_subparser(self.parser, name='interpreter')
        self.parsedargs = self.parser.parse_args()
        if 'version' in self.parsedargs and self.parsedargs.version:
            print(util.show_version())
        else:
            self.actions[self.parsedargs.subparser_name].run(self.parsedargs)
예제 #11
0
    def __init__(self):
        """ Intialization function for class. Register all subcommands   """
        ####################################################################
        # Hash of registered subparser actions, mapping string to actual subparser
        self.actions = {}
        home = path.expanduser("~")
        self.parser = ArgumentParser(description='Public Key Password Manager')
        self.parser.set_default_subparser = util.set_default_subparser
        self.parser.add_argument(
            '--config',
            type=str,
            help=
            "Path to a PKPass configuration file.  Defaults to '~/.pkpassrc'",
            default=path.join(home, '.pkpassrc'))
        self.parser.add_argument('--debug',
                                 action='store_true',
                                 help="Errors are more verbose")
        self.subparsers = self.parser.add_subparsers(help='sub-commands',
                                                     dest='subparser_name')

        card.Card(self)
        clip.Clip(self)
        create.Create(self)
        delete.Delete(self)
        distribute.Distribute(self)
        export.Export(self)
        generate.Generate(self)
        pkimport.Import(self)
        info.Info(self)
        pklist.List(self)
        listrecipients.Listrecipients(self)
        modify.Modify(self)
        recover.Recover(self)
        rename.Rename(self)
        show.Show(self)
        update.Update(self)
        verifyinstall.VerifyInstall(self)