def test_import_lastpass(self, pw, call, command): """Testing: parse method for Lastpass CLI.""" # Generate mocked API call response show_uids_response = ['', tests.mocked('lastpass', 'list')] uids = [ '8273029964772952977', '2484914384825433708', '6082506157297743545', '2708675046823528822', '4286509791900574846', '8309982398435317891', '4061988620109635891', '5256086908408307038', '3765864825443255811', '3243291093373152461', '5243770479038533622', '3905446787942154016', '6051084001543180250', '8440852123732500555', ] for ids in uids: show_uids_response.append( tests.mocked('lastpass', f'show-{ids}.json')) show_uids_response.append(tests.mocked('lastpass', f'show-{ids}')) show_uids_response.append('') # sync pw.return_value = 'dummy' call.return_value = (1, None, None) command.side_effect = show_uids_response reference = tests.reference('LastpassCLI') with tests.cls('LastpassCLI', 'login', root='Import') as importer: importer.parse() self.assertImport(importer.data, reference)
def test_importers_generic(self): """Testing: parse method for all importers.""" for manager in tests.conf: with self.subTest(manager): importer = tests.cls(manager) testpath = tests.path(manager) reference = tests.reference(manager) encoding = tests.conf[manager]['encoding'] with open(testpath, 'r', encoding=encoding) as file: importer.parse(file) self.assertImport(importer.data, reference)
def test_imports(self, pw): """Testing: parse method for all importers.""" pw.return_value = self.masterpassword dkeep = ['title', 'password', 'login', 'url', 'comments', 'group'] for manager in tests.conf: if not tests.conf[manager].get('parse', True): continue with self.subTest(manager): reference = tests.reference(manager) keep = tests.conf[manager].get('keep', dkeep) with tests.cls(manager) as importer: importer.parse() self.assertImport(importer.data, reference, keep)
def test_importers_gnomekeyring(self): """Testing: parse method for Gnome Keyring.""" collection = 'pass-import' importer = tests.cls('gnome-keyring') reference = tests.reference() importer.parse(collection) for key in ['group', 'login', 'url', 'comments']: for entry in reference: entry.pop(key, None) for entry in reference: entry['group'] = collection + entry.get('group', '') self.assertImport(importer.data, reference)
def test_importers_keepass(self, pw): """Testing: parse method for Keepass Kdbx.""" importer = tests.cls('keepass') reference = tests.reference() pw.return_value = tests.masterpassword testpath = os.path.join(tests.db, 'keepass.kdbx') importer.parse(testpath) reference.extend(REFERENCE_KDBX) for entry in importer.data: if entry['title'] == 'news.ycombinator.com': entry['title'] = 'https://news.ycombinator.com' self.assertImport(importer.data, reference)
def test_import_gnome_keyring(self): """Testing: parse method for Gnome Keyring.""" collection = 'pass-import' with tests.cls('GnomeKeyring', collection) as importer: importer.parse() data = importer.data # Manual cleaning reference = tests.reference() for key in ['group', 'login', 'url', 'comments']: for entry in reference: entry.pop(key, None) for entry in reference: entry['group'] = collection + entry.get('group', '') self.assertImport(data, reference)
def test_import_csv(self): """Testing: parse method for the generic CSV importer.""" csv = ['OnePassword4CSV', 'Roboform'] cols = { 'OnePassword4CSV': 'title,comments,login,password,url', 'Roboform': 'title,url,login,password,comments,group,,' } for manager in csv: with self.subTest(manager): prefix = os.path.join(tests.db, tests.conf[manager]['path']) reference = tests.reference(manager) with tests.cls('GenericCSV', prefix) as importer: importer.cols = cols[manager] importer.parse() self.assertImport(importer.data, reference)
def test_importers_pass(self): """Testing: parse method for password-store.""" importer = tests.cls('pass') reference = tests.reference() prefix = os.path.join(tests.db, 'pass') importer.parse(prefix) # for entry in importer.data: if entry['title'] == 'news.ycombinator.com': entry['title'] = 'https://news.ycombinator.com' if entry['group'] == 'Servers/ovh.com': entry['group'] = 'Servers' entry['title'] = 'ovh.com' self.assertImport(importer.data, reference)
def test_import_pass(self): """Testing: parse method for password-store.""" prefix = os.path.join(tests.db, 'pass') reference = tests.reference() with tests.cls('PasswordStore', prefix) as importer: importer.parse() data = importer.data # Manual cleaning for entry in data: if entry['title'] == 'news.ycombinator.com': entry['title'] = 'https://news.ycombinator.com' if entry['group'] == 'Servers/ovh.com': entry['group'] = 'Servers' entry['title'] = 'ovh.com' self.assertImport(data, reference)
def test_import_keepass(self, pw): """Testing: parse method for Keepass Kdbx.""" prefix = os.path.join(tests.db, 'keepass.kdbx') reference = tests.reference() pw.return_value = self.masterpassword with tests.cls('Keepass', prefix) as importer: importer.parse() data = importer.data # Manual cleaning reference.extend(REFERENCE_KDBX) for entry in data: if entry['title'] == 'news.ycombinator.com': entry['title'] = 'https://news.ycombinator.com' self.assertImport(data, reference)
def test_importers_csv(self): """Testing: parse method for the generic CSV importer.""" csv = ['1password4', 'roboform'] cols = { '1password4': 'title,comments,login,password,url', 'roboform': 'title,url,login,password,comments,group,,' } for manager in csv: with self.subTest(manager): importer = tests.cls('csv') importer.cols = cols[manager] testpath = tests.path(manager) reference = tests.reference(manager) encoding = tests.conf[manager]['encoding'] with open(testpath, 'r', encoding=encoding) as file: importer.parse(file) self.assertImport(importer.data, reference)