示例#1
0
def test_update_missing_secret_no_effect(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    access2 = u"my_second access"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    secret_pwd2 = u"my second password"
    secret_info = {'message': 'secret'}
    try:
        ns = du.count_secrets()
        du.insert_secret(domain, access, secret_uid, secret_pwd, secret_info,
                         m_pwd, parameters.get_salt_key())
        assert ns + 1 == du.count_secrets()
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        old_ts = res['timestamp']
        assert 'secret' == res['info']['message']
        assert secret_pwd == res['pwd']
        assert secret_uid == res['uid']

        du.update_secret(domain, access2, None, secret_pwd2, None, None, m_pwd,
                         parameters.get_salt_key())

        assert ns + 1 == du.count_secrets()
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert old_ts == res['timestamp']
    finally:
        du.delete_secret(domain, access)
示例#2
0
def test_update_secret_info_change_password_and_a_value(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    secret_pwd2 = u"another password"
    secret_info = {'message': 'secret'}
    info_key = 'message'
    info_val = 'a new secret'
    try:
        du.insert_secret(domain, access, secret_uid, secret_pwd, secret_info,
                         m_pwd, parameters.get_salt_key())
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        old_ts = res['timestamp']
        assert 'secret' == res['info'][info_key]
        assert secret_pwd == res['pwd']

        du.update_secret(domain, access, None, secret_pwd2, info_key, info_val,
                         m_pwd, parameters.get_salt_key())

        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert info_val == res['info'][info_key]
        assert secret_pwd2 == res['pwd']
        assert old_ts < res['timestamp']
    finally:
        du.delete_secret(domain, access)
示例#3
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)
示例#4
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))
示例#5
0
def test_update_secret_info_change_value(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_info = {'message': 'secret'}
    info_key = 'message'
    info_val = 'a new secret'
    try:
        du.insert_secret(domain, access, None, None, secret_info, m_pwd,
                         parameters.get_salt_key())
        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        old_ts = res['timestamp']
        assert 'secret' == res['info'][info_key]

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

        res = du.get_secret(domain, access, m_pwd, parameters.get_salt_key())
        assert info_val == res['info'][info_key]
        assert old_ts < res['timestamp']
    finally:
        du.delete_secret(domain, access)