Esempio n. 1
0
def test_qget_wrong_input(set_up):
    domain1 = 'pera'
    access1 = "cotta"
    domain2 = 'bella'
    access2 = 'pera'
    
    #when the list of secrete is returned they are ordered alphabetically
    #by domain, access. Hence the first secret is bella,pera, or the second record here
    
    sleep(1)
    #delete first
    du.delete_secret(domain1, access1)
    du.delete_secret(domain2, access2)
    #then set   
    sys.argv=['secret_wallet','set','-d',domain1, '-a', access1, '-ik', 'idx', '-iv','second record']
    Parser()
    sys.argv=['secret_wallet','set','-d',domain2, '-a', access2, '-ik', 'idx', '-iv','first record']
    Parser()
    assert du.has_secret(domain1, access1)
    assert du.has_secret(domain2, access2)
    
    #now running a qget command with some mockable input
    iou.my_input = iou.MockableInput(["string"])    
    sys.argv=['secret_wallet','qget','pera']
    with io.StringIO() as buf, redirect_stdout(buf):
        Parser()
        sleep(1)
        assert "first record" not in buf.getvalue() #get the inner value in the secret 
        assert "second record" not in buf.getvalue()
        assert "I need a number"  in buf.getvalue()                     
Esempio n. 2
0
def test_update_secret_login(set_up):
    m_pwd = u"memorabile"
    secret_uid = u"me@home"
    secret_uid2 = u"me@office"
    secret_pwd = u"ciao mamma"
    domain = u"my_domain"
    access = u"my_access"
    try:
        ns = du.count_secrets()
        du.insert_secret(domain, access, secret_uid, secret_pwd, None, m_pwd,
                         parameters.get_salt_key())
        assert ns + 1 == du.count_secrets()
        assert du.has_secret(domain, access)
        old_ts = du.get_secret(domain, access, m_pwd,
                               parameters.get_salt_key())['timestamp']

        du.update_secret(domain, access, secret_uid2, None, None, None, m_pwd,
                         parameters.get_salt_key())

        assert ns + 1 == du.count_secrets(
        )  #no change to the number of secrets
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert secret_uid2 == res['uid']
        assert secret_pwd == res['pwd']
        assert old_ts < res['timestamp']
    finally:
        du.delete_secret(domain, access)
Esempio n. 3
0
    def set(self):
        """
            Add or change a secret in the wallet. This could be an entire new secret, with all the information passed inline
            or an update of an existing secret. What is set with this command determines the content of a secret, identified
            by the domain, access pair. Key values pairs, as defined by the -ik and -iv options, can be added incrementally
            by multiple calls to the set command.
        """
        parser = argparse.ArgumentParser(description=self.set.__doc__,
                                         prog='secret_wallet set')
        #required arguments
        parser.add_argument('-d',
                            dest='domain',
                            required=True,
                            help='The domain (category) of the secret')
        parser.add_argument(
            '-a',
            dest='access',
            required=True,
            help='The sub=domain (sub-category or access) of the secret')
        #optional arguments
        parser.add_argument('-u',
                            '--uid',
                            help='The login id for a given access')
        parser.add_argument('-p',
                            '--pwd',
                            help='The password for a given access')
        parser.add_argument('-ik',
                            '--info_key',
                            help='The key in an information map')
        parser.add_argument('-iv',
                            '--info_value',
                            help='The value in an information map')

        args = iou.my_parse(parser, sys.argv[2:])
        if args is None:
            return

        iou.my_output('Running set for domain %s and access %s' %
                      (args.domain, args.access))
        if args.info_key is None or args.info_value is None:
            info = None
        else:
            info = {args.info_key: args.info_value}
        try:
            memorable, need_session = pm.get_memorable_password(True)
            if not has_secret(args.domain, args.access):
                insert_secret(args.domain, args.access, args.uid, args.pwd,
                              info, memorable)
            else:
                update_secret(args.domain, args.access, args.uid, args.pwd,
                              args.info_key, args.info_value, memorable)
            if need_session:
                start_my_session(memorable, parameters.get_session_lifetime(),
                                 parameters.get_session_timeout())
        except Exception as e:
            iou.my_output(repr(e))
Esempio n. 4
0
def test_rename_secret(set_up):
    new_domain = "new domain_01"
    new_access = "new_access_01"
    
    sleep(1)
    #delete first
    du.delete_secret(DOMAIN, ACCESS)
    #then set   
    sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','first_key','-iv','first_value']
    Parser()
    assert du.has_secret(DOMAIN, ACCESS)
    assert not du.has_secret(new_domain, new_access)
    
    #now rename
    sys.argv=['secret_wallet','rename','-d',DOMAIN, '-a', ACCESS, '-nd', new_domain,'-na', new_access]
    Parser()
    assert not du.has_secret(DOMAIN, ACCESS)
    assert du.has_secret(new_domain, new_access)
    du.delete_secret(new_domain, new_access)
Esempio n. 5
0
def test_shell_set_rename_get_delete(set_up):
    password = '******'
    #mocking password retrieval
    iou.my_getpass = lambda question: password
    #mocking input to pass a 'set ...' command in a shell
    iou.my_input = iou.MockableInput(["set -d shell_test -a test -ik test -iv 'this is a test'",
                                      'rename -d shell_test -a test -na test2',
                                      'yes',
                                      'get -d shell_test -a test2',
                                      'delete -d shell_test -a test2',
                                      'yes',
                                      'quit'])
    sys.argv=['secret_wallet','shell']
    with io.StringIO() as buf, redirect_stdout(buf):
        Parser()
        assert 'this is a test' in buf.getvalue()

    #now check it is not there any longer
    assert not du.has_secret('shell_test','test')
    assert not du.has_secret('shell_test','test2')
Esempio n. 6
0
def test_has_not_secret(set_up):
    m_pwd = u"memorabile"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    domain = u"my_domain"
    access = u"my_access"
    try:
        du.insert_secret(domain, access, secret_uid, secret_pwd, None, m_pwd,
                         parameters.get_salt_key())
        assert not du.has_secret('new_domain', access)
    finally:
        du.delete_secret(domain, access)
Esempio n. 7
0
def test_rename_secret(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    new_domain = u"new_domain"
    new_access = u"new_access"
    info = {'message': 'secret'}
    try:
        #before
        assert not du.has_secret(domain, access)
        assert not du.has_secret(new_domain, new_access)
        #after insertion
        du.insert_secret(domain, access, None, None, info, m_pwd,
                         parameters.get_salt_key())
        assert du.has_secret(domain, access)
        assert not du.has_secret(new_domain, new_access)
        #after rename
        du.rename_secret(domain, access, new_domain, new_access)
        assert not du.has_secret(domain, access)
        assert du.has_secret(new_domain, new_access)
        res = du.get_secret(new_domain, new_access, m_pwd,
                            parameters.get_salt_key())
        assert info['message'] == res['info']['message']
    finally:
        du.delete_secret(domain, access)
        du.delete_secret(new_domain, new_access)
Esempio n. 8
0
    def rename(self):
        """
           Renames a secret, as identified by the domain, access pair. A new domain name can be passed with the -nd option and a new access
           name can be passed with the -na option. Both domain and access can be changed at the same time or on their own.
        """
        parser = argparse.ArgumentParser(description=self.rename.__doc__,
                                         prog='secret_wallet rename')
        #required arguments
        parser.add_argument('-d',
                            dest='domain',
                            required=True,
                            help='The domain (category) of the secret')
        parser.add_argument(
            '-a',
            dest='access',
            required=True,
            help='The sub=domain (sub-category or access) of the secret')
        parser.add_argument('-nd',
                            dest='new_domain',
                            default=None,
                            help='The new domain')
        parser.add_argument('-na',
                            dest='new_access',
                            default=None,
                            help='The new asset')
        args = iou.my_parse(parser, sys.argv[2:])
        if args is None:
            return

        iou.my_output('Running rename with arguments %s' % args)
        try:
            if args.new_domain is None and args.new_access is None:
                iou.my_output("No new keys have been passed", True)
            elif args.new_domain == args.domain and args.new_access == args.access:
                iou.my_output(
                    "Both new values are the same as the originals: nothing to do",
                    True)
            elif not has_secret(args.domain, args.access):
                iou.my_output("Could not find the secret to rename", True)
            else:
                if args.new_domain is None:
                    args.new_domain = args.domain
                if args.new_access is None:
                    args.new_access = args.access
                iou.confirm_rename([(args.domain, args.access)])
                rename_secret(args.domain, args.access, args.new_domain,
                              args.new_access)
        except Exception as e:
            iou.my_output(repr(e))
Esempio n. 9
0
def test_query_by_pattern(set_up):
    domain1 = 'pera'
    access1 = "cotta"
    domain2 = 'bella'
    access2 = 'pera'
    
    sleep(1)
    #delete first
    du.delete_secret(domain1, access1)
    du.delete_secret(domain2, access2)
    #then set   
    sys.argv=['secret_wallet','set','-d',domain1, '-a', access1]
    Parser()
    sys.argv=['secret_wallet','set','-d',domain2, '-a', access2]
    Parser()
    assert du.has_secret(domain1, access1)
    assert du.has_secret(domain2, access2)
    
    #now querying by domain
    sys.argv=['secret_wallet','query','pera']
    with io.StringIO() as buf, redirect_stdout(buf):
        Parser()
        assert "cotta" in buf.getvalue()
        assert "bella" in buf.getvalue()
Esempio n. 10
0
def test_delete_info_item(set_up):
    domain = 'pera'
    access = "cotta"
    key1 = 'bella'
    value1 = 'pupa'
    key2 = 'toste'
    value2 = 'mele'    
        
    sleep(1)
    #delete first
    du.delete_secret(domain, access)
    #then set   
    sys.argv=['secret_wallet','set','-d',domain, '-a', access, '-ik', key1, '-iv', value1]
    Parser()
    sys.argv=['secret_wallet','set','-d',domain, '-a', access, '-ik', key2, '-iv',value2]
    Parser()
    assert du.has_secret(domain, access)
        
    sys.argv=['secret_wallet','get', '-d', domain, '-a', access]
    with io.StringIO() as buf, redirect_stdout(buf):
        Parser()
        sleep(1)
        assert "pupa" in buf.getvalue() 
        assert "mele" in buf.getvalue()
    
    #now remove one item from the dictionary    
    sys.argv=['secret_wallet','delete', '-d', domain, '-a', access, '-ik', key2]
    Parser()
    
    #check that the item is gone
    sys.argv=['secret_wallet','get', '-d', domain, '-a', access]
    with io.StringIO() as buf, redirect_stdout(buf):
        Parser()
        sleep(1)
        assert "pupa" in buf.getvalue() 
        assert "mele" not in buf.getvalue()