Esempio n. 1
0
def test_update_info_dict_remove_key(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    access = u"my_access"
    secret_info = {'key1': 'value1', 'key2': 'value2'}
    salt = parameters.get_salt_key()
    try:
        ns = du.count_secrets()
        du.insert_secret(domain, access, None, None, secret_info, m_pwd,
                         parameters.get_salt_key())
        assert ns + 1 == du.count_secrets()
        res = du.get_secret(domain, access, m_pwd, salt,
                            False)  #no decryption of secret
        old_ts = res['timestamp']
        info = res['info']
        assert 2 == len(info)

        del info['key2']  #remove one entry
        du.update_secret_info_dictionary(domain, access, info)
        res = du.get_secret(domain, access, m_pwd, salt)
        ts = res['timestamp']
        info = res['info']
        assert 1 == len(info)
        assert 'value1' == info['key1']
        assert ts != old_ts

    finally:
        du.delete_secret(domain, access)
Esempio n. 2
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)
Esempio n. 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)
Esempio n. 4
0
def test_insert_delete_login(set_up):
    m_pwd = u"memorabile"
    secret_uid = u"me@home"
    secret_pwd = u"ciao mamma"
    domain = u"my_domain"
    access = u"my_access"
    ns = du.count_secrets()
    try:
        du.insert_secret(domain, access, secret_uid, secret_pwd, None, m_pwd,
                         parameters.get_salt_key())
        assert ns + 1 == du.count_secrets()
    finally:
        du.delete_secret(domain, access)
        assert ns == du.count_secrets()
Esempio n. 5
0
def test_query_records(set_up, insert_records):
    #test with no filter
    ns = du.count_secrets()
    secrets = du.query_secrets_by_field(None, None)
    assert ns == len(secrets)

    #test filter on domain with a d
    secrets = du.query_secrets_by_field("d", None)
    assert 3 == len(secrets)

    #tets filter on domain with a 1
    secrets = du.query_secrets_by_field("1", None)
    assert 2 == len(secrets)

    #test filter domain with an x
    secrets = du.query_secrets_by_field("x", None)
    assert 0 == len(secrets)

    #test filter on access with a 1 in it
    secrets = du.query_secrets_by_field(None, "1")
    assert 1 == len(secrets)

    #test on both
    secrets = du.query_secrets_by_field("1", "2")
    assert 1 == len(secrets)
Esempio n. 6
0
def test_delete_secrets(set_up):
    m_pwd = u"memorabile"
    domain = u"my_domain"
    info = {'message': 'secret'}
    #cleanup
    du.delete_secrets(du.list_secrets(None))
    cnt = du.count_secrets()
    for i in range(5):
        access = f"access_{i}"
        du.insert_secret(domain, access, None, None, info, m_pwd,
                         parameters.get_salt_key())
    assert cnt + 5 == du.count_secrets()
    # now get the secret back by domain
    secrets = du.list_secrets(domain)
    #delete them in block
    du.delete_secrets(secrets)
    #check that they are gone
    assert cnt == du.count_secrets()