def test_get_keys(): gpg = get_GPG('{"One": 1, "Two": 2}', 'secrets_tmp4', '12345') cmdc = CommandControler(gpg) keys = cmdc.get_keys() assert keys == ['One', 'Two'] remove_files(['secrets_tmp4'])
def test_get_json(): gpg = get_GPG('{"One": 1, "Two": 2}', 'secrets_tmp1', '12345') cmdc = CommandControler(gpg) json = cmdc.get_json() assert json == '{"One": 1, "Two": 2}' remove_files(['secrets_tmp1'])
def test_modify_id_no_id(): gpg = get_GPG('{"One": {"user":"******","password":"******","url":"url1","other":"other1"}}', 'secrets_tmp43', '12345') cmdc = CommandControler(gpg) with pytest.raises(KeyError): cmdc.modify_id('Two','Three') remove_files(['secrets_tmp43'])
def test_show_keys_empty(capsys): gpg = get_GPG('{}', 'secrets_tmp8', '12345') cmdc = CommandControler(gpg) cmdc.show_keys() out, err = capsys.readouterr() assert out == '' remove_files(['secrets_tmp8'])
def test_show_keys(capsys): gpg = get_GPG('{"One": 1, "Two": 2}', 'secrets_tmp7', '12345') cmdc = CommandControler(gpg) cmdc.show_keys() out, err = capsys.readouterr() assert out == 'One\nTwo\n' remove_files(['secrets_tmp7'])
def test_add_content_id_json_firt_element(): gpg = GPGTools(key = '12345') cmdc = CommandControler(gpg) cmdc.add_content_id_json("example", '{"user":"******","password":"******","url":"example","other":"example"}') json_gpg = json.loads(str(gpg.decrypt_content())) assert json_gpg == {"example": {"user":"******","password":"******","url":"example","other":"example"}} remove_files(['secrets'])
def test_show_keys_no_json(capsys): gpg = get_GPG('d', 'secrets_tmp9', '12345') with pytest.raises(ValueError): cmdc = CommandControler(gpg) cmdc.show_keys() out, err = capsys.readouterr() assert out == '' remove_files(['secrets_tmp9'])
def test_del_id(): gpg = get_GPG('{"One": {"user":"******","password":"******","url":"url1","other":"other1"}}', 'secrets_tmp44', '12345') cmdc = CommandControler(gpg) cmdc.del_id('One') json_gpg = json.loads(str(gpg.decrypt_content())) assert json_gpg == {} remove_files(['secrets_tmp44'])
def test_set_json(): gpg = get_GPG('{"One": 1, "Two": 2}', 'secrets_tmp2', '12345') gpg2 = GPGTools(file = 'secrets_tmp3', key = '12345') cmdc = CommandControler(gpg2) cmdc.set_json('{"One": 1, "Two": 2}') file1 = open('secrets_tmp2', 'r') file2 = open('secrets_tmp3', 'r') assert file1.read() != file2.read() remove_files(['secrets_tmp2', 'secrets_tmp3'])
def test_update_keys(): get_files('secrets_tmp10', 'secrets_tmp11') gpg = GPGTools(file = 'secrets_tmp10', key = '12345') cmdc = CommandControler(gpg) cmdc.update_keys() file1 = open('secrets_tmp10','r') file2 = open('secrets_tmp11','r') assert file1.read() != file2.read() remove_files(['secrets_tmp10','secrets_tmp11'])
def test_add_content_id_json(): json_gpg = {"One": {"user":"******","password":"******","url":"url1","other":"other1"},"example": {"user":"******","password":"******","url":"example","other":"example"}} gpg2 = get_GPG('{"One": {"user":"******","password":"******","url":"url1","other":"other1"}}', 'secrets_tmp39', '12345') cmdc = CommandControler(gpg2) cmdc.add_content_id_json("example", '{"user":"******","password":"******","url":"example","other":"example"}') json_gpg2 = json.loads(str(gpg2.decrypt_content())) assert json_gpg2 == json_gpg remove_files(['secrets_tmp39'])
def test_no_update_keys(): ''' This test ensure that the codification works properly in the future this could be moved to the test_gpg_tools ''' get_files('secrets_tmp12', 'secrets_tmp13') gpg = GPGTools(file = 'secrets_tmp12', key = '12345') cmdc = CommandControler(gpg) file1 = open('secrets_tmp12','r') file2 = open('secrets_tmp13','r') assert file1.read() == file2.read() remove_files(['secrets_tmp12','secrets_tmp13'])
def test_add_content(monkeypatch): gpg = get_GPG('{"One": {"user":"******","password":"******","url":"url1","other":"other1"},"example": {"user":"******","password":"******","url":"example","other":"example"}}', 'secrets_tmp5', '12345') gpg2 = get_GPG('{"One": {"user":"******","password":"******","url":"url1","other":"other1"}}', 'secrets_tmp6', '12345') json_msg = '{"example": {"user":"******","password":"******","url":"example","other":"example"}}' cmdc = CommandControler(gpg2) cmdc.add_content(json_msg) json_gpg = json.loads(str(gpg.decrypt_content())) json_gpg2 = json.loads(str(gpg2.decrypt_content())) assert json_gpg == json_gpg2 remove_files(['secrets_tmp5', 'secrets_tmp6'])
def __init__(self, gpg): self.cmdc = CommandControler(gpg) self.FILE = gpg.get_file()
def main(argv): gpg = GPGTools(file=FILE) icmd = InteractiveCMD(gpg) cmdc = CommandControler(gpg) if os.path.isfile(FILE): parser = argparse.ArgumentParser( description='Manager for sensible information under PGP') parser.add_argument( '-i', '--interactive', help='display the interactive menu for pwd-manager', action='store_true') parser.add_argument('-l', '--list', help='list all the stored identifiers', action='store_true') parser.add_argument( '-u', '--user', metavar='identifier', help='return the username for the given identifier') parser.add_argument( '-p', '--password', metavar='identifier', help='return the password for the given identifier') parser.add_argument('-ur', '--url', metavar='identifier', help='return the URL for the given identifier') parser.add_argument( '-o', '--other', metavar='identifier', help='return the other for the given identifier') parser.add_argument( '-a', '--all', metavar='identifier', help='display all values for the given identifier') parser.add_argument( '-ak', '--addkey', nargs=2, metavar=('identifier', '{"user":"******", ...}'), help= 'add element to secrets, second argument must be a valid json string. Allowed keys user, password, url and other' ) parser.add_argument( '-mk', '--modkey', nargs=2, metavar=('identifier', '{"user":"******", ...}'), help= 'modify element to secrets, second argument must be a valid json string. Allowed keys user, password, url and other' ) parser.add_argument('-mi', '--modid', nargs=2, metavar=('old_identifier', 'new_identifier'), help='modify id from an element') parser.add_argument( '-d', '--delete', nargs=1, metavar='identifier', help= 'modify element to secrets, second argument must be a valid json string' ) args = parser.parse_args() if args.interactive: icmd.interactive_menu() elif args.list: cmdc.show_keys() elif args.user: cmdc.get_key_value(args.user, 'user') elif args.password: cmdc.get_key_value(args.password, 'pass') elif args.url: cmdc.get_key_value(args.url, 'url') elif args.other: cmdc.get_key_value(args.other, 'other') elif args.all: cmdc.get_key_value(args.all, 'all') elif args.addkey: cmdc.add_content_id_json(args.addkey[0], str(args.addkey[1:][0])) elif args.modkey: cmdc.modify_content(args.modkey[0], str(args.modkey[1:][0])) elif args.modid: cmdc.modify_id(args.modid[0], args.modid[1]) elif args.delete: cmdc.del_id(args.delete[0]) else: parser.print_help() else: parser = argparse.ArgumentParser( description= '''Manager for sensible information under PGP. Use -i/--interactive or -ak/--addkey to introduce your first key and for more option will be displayed.''' ) parser.add_argument( '-i', '--interactive', help='display the interactive menu for pwd-manager', action='store_true') parser.add_argument( '-ak', '--addkey', nargs=2, metavar=('identifier', '{"user":"******", ...}'), help= 'add element to secrets, second argument must be a valid json string. Allowed keys user, password, url and other' ) args = parser.parse_args() if args.interactive: icmd.interactive_menu() elif args.addkey: cmdc.add_content_id_json(args.addkey[0], str(args.addkey[1:][0])) else: parser.print_help()