def test_importers_applekeychain_note(self): """Testing: parse method for AppleKeychain with notes.""" importer = tests.cls('apple-keychain') testpath = os.path.join(tests.db, 'apple-keychain-note.txt') with open(testpath, 'r') as file: importer.parse(file) self.assertImport(importer.data, REFERENCE_NOTE)
def test_importers_keepassxother(self): """Testing: parse method for KeepassX with special cases.""" importer = tests.cls('keepassx') testpath = os.path.join(tests.db, 'keepassx-other.xml') with open(testpath, 'r') as file: importer.parse(file) self.assertImport(importer.data, REFERENCE_OTHER)
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_formats_csv(self): """Testing: file format for generic CSV importer.""" prefix = os.path.join(tests.db, 'lastpass.csv') with self.assertRaises(self.formaterror): with tests.cls('GenericCSV', prefix) as importer: importer.cols = '' importer.parse()
def test_importers_andotpgpg(self): """Testing: parse method for andOTP encrypted with GPG.""" keep = ['title', 'otpauth', 'type'] importer = tests.cls('andotp') testpath = os.path.join(tests.db, 'andotp.gpg') with open(testpath, 'r') as file: importer.parse(file) self.assertImport(importer.data, REFERENCE_OTP, keep)
def test_importers_andotpaes(self, pw): """Testing: parse method for andOTP encrypted with AES.""" keep = ['title', 'otpauth', 'type'] importer = tests.cls('andotp') pw.return_value = tests.masterpassword testpath = os.path.join(tests.db, 'andotp.json.aes') with open(testpath, 'r') as file: importer.parse(file) self.assertImport(importer.data, REFERENCE_OTP, keep)
def test_importers_revelation(self): """Testing: parse method for Revelation with special cases.""" keep = [ 'title', 'password', 'login', 'database', 'host', 'port', 'url', 'email', 'phone', 'location', 'description', 'comments', 'group' ] prefix = os.path.join(tests.db, 'revelation-other.xml') with tests.cls('Revelation', prefix) as importer: importer.parse() self.assertImport(importer.data, REFERENCE_REVELATION, keep)
def test_import_encryptr(self): """Testing: parse method for Encryptr with credit card.""" keep = [ 'title', 'Type', 'Name on card', 'Card Number', 'CVV', 'Expiry', 'group' ] prefix = os.path.join(tests.db, 'encryptr-card.csv') with tests.cls('Encryptr', prefix) as importer: importer.parse() self.assertImport(importer.data, REFERENCE_CARD, keep)
def test_importers_encryptr(self): """Testing: parse method for Encryptr with credit card.""" keep = [ 'title', 'Type', 'Name on card', 'Card Number', 'CVV', 'Expiry', 'group' ] importer = tests.cls('encryptr') testpath = os.path.join(tests.db, 'encryptr-card.csv') with open(testpath, 'r') as file: importer.parse(file) self.assertImport(importer.data, REFERENCE_CARD, keep)
def test_importers_otp(self): """Testing: parse method for all OTP importers.""" keep = ['title', 'otpauth', 'type'] otp = ['andotp', 'gnome-authenticator', 'aegis'] for manager in otp: with self.subTest(manager): importer = tests.cls(manager) testpath = os.path.join(tests.db, manager + '.json') with open(testpath, 'r') as file: importer.parse(file) self.assertImport(importer.data, REFERENCE_OTP, keep)
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_imports_otp(self, pw): """Testing: parse method for all OTP importers.""" keep = ['title', 'otpauth', 'type'] pw.return_value = self.masterpassword otp = [ 'Aegis', 'AegisCipher', 'AndOTP', 'FreeOTPPlus', 'GnomeAuthenticator' ] for manager in otp: with self.subTest(manager): with tests.cls(manager) as importer: importer.parse() self.assertImport(importer.data, REFERENCE_OTP, keep)
def test_formats(self): """Testing: file format for all importers.""" ignore = ['DashlaneCSV', 'KeeperCSV', 'UPM'] for manager in tests.conf: if manager in ignore or not tests.conf[manager].get('parse', True): continue with self.subTest(manager): _, ext = os.path.splitext(tests.conf[manager]['path']) prefix = os.path.join(tests.formats, 'dummy' + ext) with self.assertRaises(self.formaterror): with tests.cls(manager, prefix) as importer: importer.parse()
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_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_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_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_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_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)
def test_importers_bitwarden(self): """Testing: parse method for Bitwarden with special cases.""" keep = [ 'title', 'password', 'login', 'database', 'host', 'port', 'url', 'email', 'phone', 'location', 'description', 'comments', 'group', 'otpauth', 'title', 'brand', 'cardholderName', 'code', 'expMonth', 'expYear', 'number', 'title', 'address1', 'address2', 'address3', 'city', 'company', 'country', 'email', 'firstName', 'lastName', 'licenseNumber', 'middleName', 'passportNumber', 'phone', 'postalCode', 'ssn', 'username', 'passportNumber', 'licenseNumber', 'title', 'comments', 'my text field', 'my hidden field', 'a boolean field which is off', 'a boolean field which is on', 'secureNote', 'title_', 'url2' ] prefix = os.path.join(tests.db, 'bitwarden-other.json') with tests.cls('BitwardenJSON', prefix) as importer: importer.parse() self.assertImport(importer.data, REFERENCE_BITWARDEN, keep)
def test_importers_networkmanager(self): """Testing: parse method for Network Manager.""" importer = tests.cls('networkmanager') testpath = os.path.join(tests.db, 'networkmanager') importer.parse(testpath) self.assertImport(importer.data, REFERENCE_WIFI)
def test_import_applekeychain_notes(self): """Testing: parse method for AppleKeychain with notes.""" prefix = os.path.join(tests.db, 'apple-keychain-note.txt') with tests.cls('AppleKeychain', prefix) as importer: importer.parse() self.assertImport(importer.data, REFERENCE_NOTE)
def test_formats_otp(self): """Testing: file format for OTP based importers.""" prefix = os.path.join(tests.db, 'andotp.json') with self.assertRaises(self.formaterror): with tests.cls('Aegis', prefix) as importer: importer.parse()
def test_import_keepass_other(self): """Testing: parse method for Keepass with special cases.""" prefix = os.path.join(tests.db, 'keepass-other.xml') with tests.cls('KeepassXML', prefix) as importer: importer.parse() self.assertImport(importer.data, REFERENCE_OTHER)
def test_import_networkmanager(self): """Testing: parse method for NetworkManager.""" prefix = os.path.join(tests.db, 'networkmanager') with tests.cls('NetworkManager', prefix) as importer: importer.parse() self.assertImport(importer.data, REFERENCE_WIFI)