def custom_setup(self, tmp_path): super(EmptyLocker, self).custom_setup(tmp_path) for name in self.lockers: try: Locker.delete(name, self.password) except PhibesNotFoundError: pass self.lockers = {} try: Locker.delete(self.locker_name, self.password) except PhibesNotFoundError: pass finally: self.my_locker = Locker.create( password=self.password, crypt_id=crypto.default_id, locker_name=self.locker_name ) # create a locker for each registered crypt instance for crypt_id in crypto.list_crypts(): # dedupe the names with random numbers wart = str(random.randint(1000, 9999)) # but make sure there isn't a freak collision while self.locker_name + str(wart) in self.lockers: wart = str(random.randint(1000, 9999)) locker_name = self.locker_name + wart self.lockers[locker_name] = Locker.create( password=self.password, crypt_id=crypt_id, locker_name=locker_name ) return
def test_good(self, tmp_path, datadir, setup_and_teardown): Locker.create( password=self.password, crypt_id=crypto.default_id, locker_name=self.locker_name ) found = Locker.get(password=self.password, locker_name=self.locker_name) assert found
def custom_setup(self, tmp_path): super(TestDeleteLocker, self).custom_setup(tmp_path) try: Locker.delete(password=self.pw, locker_name=self.locker_name) except PhibesNotFoundError: pass crypt_id = crypto.list_crypts()[0] Locker.create( password=self.pw, crypt_id=crypt_id, locker_name=self.locker_name ) self.setup_command()
def test_duplicate(self, tmp_path, datadir, setup_and_teardown): Locker.create( password=self.password, crypt_id=crypto.default_id, locker_name=self.locker_name ) with pytest.raises(PhibesExistsError): Locker.create( password=self.password, crypt_id=crypto.default_id, locker_name=self.locker_name )
def custom_setup(self, tmp_path): ConfigModel().storage = StoreType.Memory.name super(TestGetLocker, self).custom_setup(tmp_path) try: if Locker.get(password=self.password, locker_name=self.locker_name): Locker.delete(password=self.password, locker_name=self.locker_name) Locker.create(password=self.password, crypt_id=crypto.default_id, locker_name=self.locker_name) except Exception: pass
def _test_create_installs(self, datadir): """ This is a bootstrap for one-time use creating lockers to be tested so we know nothing in our encryption has changed """ for crypt_id in list_crypts(): data_root = datadir['.'] new_loc = Path(data_root / crypt_id) new_loc.mkdir() conf = ConfigModel(store_path=new_loc, editor='vim') write_config_file(new_loc, conf) new_lock = Locker.create(self.test_name, self.test_pw, crypt_id) for name, pt in plain_texts.items(): ni = new_lock.create_item(name) ni.content = ( f"{pt}\nsite:www.zombo.com\npassword: YouCanD0NEthing!") new_lock.add_item(ni) # after lockers are stored, stub out the store_path conf._store_path = Path("/") conf.store = { 'store_type': StoreType.FileSystem.name, 'store_path': "/" } write_config_file(new_loc, conf, update=True, bypass_validation=True)
def test_editor_option(self, crypt_id, tmp_path, setup_and_teardown): self.my_locker = Locker.create(password=self.password, crypt_id=crypt_id) new_item = self.my_locker.create_item(item_name=self.test_item_name) new_item.content = self.start_content self.my_locker.add_item(item=new_item) conf = CliConfig() conf.store = { 'store_type': conf.store['store_type'], 'store_path': tmp_path } conf.editor = f'echo {self.edit_content}> ' write_config_file(tmp_path, update=True) load_config_file(tmp_path) # change the configured working path to the test directory update_config_option_default(self.target_cmd, self.test_path) replacement_content = "emacswhatwhat" cli_editor_option = f"echo {replacement_content}> " result = self.prep_and_run({ 'crypt_id': crypt_id, 'editor': cli_editor_option }) assert result assert result.exit_code == 0, (f"{crypt_id=}\n" f"{result.exception=}\n" f"{result.output=}\n") assert self.start_content not in result.output assert self.edit_content not in result.output inst = self.my_locker.get_item(self.test_item_name) assert replacement_content == inst.content.strip()
def prep_and_run(self, arg_dict): self.my_locker = Locker.create(password=self.password, crypt_id=arg_dict['crypt_id']) new_item = self.my_locker.create_item(item_name=self.test_item_name) new_item.content = self.test_content self.my_locker.add_item(item=new_item) # change the configured working path to the test directory update_config_option_default(self.target_cmd, self.test_path) return self.invoke(arg_dict=arg_dict)
def create_locker( password: str, crypt_id: str, locker_name: str = None, **kwargs ): return Locker.create( password=password, crypt_id=crypt_id, locker_name=locker_name ).to_dict()
def prep_and_run(self, arg_dict): self.my_locker = Locker.create( password=self.password, crypt_id=arg_dict['crypt_id'], locker_name=None ) # change the configured working path to the test directory update_config_option_default(self.target_cmd, self.test_path) arg_list = [ "--path", arg_dict.get('path', self.test_path), "--password", arg_dict.get('password', self.password) ] return CliRunner().invoke(cli=self.target_cmd, args=arg_list)
def test_create_without_arg(self, crypt_id, setup_and_teardown): Locker.create(password=self.password, crypt_id=crypt_id) found = Locker.get(password=self.password, locker_name=None) assert found