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()
def test_rename_secret_wrong_values(set_up): sleep(1) sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','first_key','-iv','first_value'] Parser() sys.argv=['secret_wallet','rename','-d',DOMAIN, '-a', 'wrong', '-nd', DOMAIN, '-na', ACCESS] with io.StringIO() as buf, redirect_stdout(buf): Parser() assert "Could not find the secret to rename" in buf.getvalue()
def test_rename_secret_same_values(set_up): sleep(1) sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','first_key','-iv','first_value'] Parser() sys.argv=['secret_wallet','rename','-d',DOMAIN, '-a', ACCESS, '-nd', DOMAIN, '-na', ACCESS] with io.StringIO() as buf, redirect_stdout(buf): Parser() assert "Both new values are the same as the originals: nothing to do" in buf.getvalue()
def test_rename_secret_no_new_values(set_up): sleep(1) sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','first_key','-iv','first_value'] Parser() sys.argv=['secret_wallet','rename','-d',DOMAIN, '-a', ACCESS] with io.StringIO() as buf, redirect_stdout(buf): Parser() assert "No new keys have been passed" in buf.getvalue()
def test_update_info(set_up): sleep(1) sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','first_key','-iv','first_value'] Parser() sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', ACCESS, '-ik','second_key','-iv','second_value'] Parser() res = du.get_secret(DOMAIN, ACCESS, 'memorable', parameters.get_salt_key()) assert 3 == len(res['info']) assert 'value' == res['info']['key'] assert 'first_value' == res['info']['first_key'] assert 'second_value' == res['info']['second_key']
def test_shell_set_help(set_up): #mocking input to pass a 'set -h' command in a shell iou.my_input = iou.MockableInput(['set -h','quit']) sys.argv=['secret_wallet','shell'] with io.StringIO() as buf, redirect_stdout(buf): Parser() assert 'usage: secret_wallet set' in buf.getvalue()
def test_get_secret(set_up): sys.argv=['secret_wallet','get','-d',DOMAIN, '-a', ACCESS] #output redirection to string sleep(1) with io.StringIO() as buf, redirect_stdout(buf): Parser() assert ACCESS in buf.getvalue()
def test_wrong_memorable_password(set_up): my_access = 'another' sleep(1) try: #insert sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', my_access, '-u','login','-p','password'] Parser() #now change the memorable in the session sys.argv=['secret_wallet','client','-a','set','-v','azzo'] Parser() #the following shoud produce and InvalidToken error sys.argv=['secret_wallet','get','-d',DOMAIN, '-a', my_access] with io.StringIO() as buf, redirect_stdout(buf): Parser() assert 'InvalidToken' in buf.getvalue() finally: du.delete_secret(DOMAIN,my_access)
def test_empty_list(set_up): sys.argv=['secret_wallet','list','-d','xxx'] #output redirection to string with io.StringIO() as buf, redirect_stdout(buf): try: Parser() except: assert False, "An empty list should not raise and exception when formatted" assert "****" in buf.getvalue()
def test_wrong_salt(set_up): my_access = 'another' other_key = cu.encrypt_key('pirillo') sleep(1) du.insert_secret(DOMAIN, my_access, 'login', 'password', None, 'memorable', other_key) #the following shoud produce and InvalidToken error sys.argv=['secret_wallet','get','-d',DOMAIN, '-a', my_access] with io.StringIO() as buf, redirect_stdout(buf): Parser() assert 'InvalidToken' in buf.getvalue()
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)
def test_set_secret(set_up): sys.argv=['secret_wallet','set','-d',DOMAIN, '-a', 'test_access_2', '-u','x@y','-p','mamma'] #output redirection to string try: sleep(1) with io.StringIO() as buf, redirect_stdout(buf): Parser() du.list_secrets(DOMAIN) assert 'test_access_2' in buf.getvalue() finally: du.delete_secret(DOMAIN,'test_access_2')
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()
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()
def test_shell_set_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'", 'get -d shell_test -a test', 'delete -d shell_test -a test', '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')
def test_conf_list(set_up): sys.argv=['secret_wallet','conf','-l'] with io.StringIO() as buf, redirect_stdout(buf): Parser() assert "secret wallet configuration is located" in buf.getvalue()
def test_list_domain(set_up): sys.argv=['secret_wallet','list','-d',DOMAIN] #output redirection to string with io.StringIO() as buf, redirect_stdout(buf): Parser() assert ACCESS in buf.getvalue()
def test_list(set_up): sys.argv=['secret_wallet','list'] #output redirection to string with io.StringIO() as buf, redirect_stdout(buf): Parser() assert "<domain>" in buf.getvalue()
def test_help(set_up): sys.argv=['secret_wallet','help'] #output redirection to string with io.StringIO() as buf, redirect_stdout(buf): Parser() assert 'list of secretwallet commands' in buf.getvalue()