def test_write_new_read(self): phibes_file.write(self.pth, salt=self.test_salt, crypt_id=self.test_crypt_id, timestamp=self.test_timestamp, body=self.test_body) result = phibes_file.read(self.pth) assert result['body'] == self.test_body assert result['salt'] == self.test_salt assert result['crypt_id'] == self.test_crypt_id assert result['timestamp'] == self.test_timestamp
def get(self) -> dict: """ Get a stored Locker from file @return: LockerFileStorage instance """ if not self.locker_file.exists(): raise PhibesNotFoundError(f'file: {self.locker_file}') else: rec = phibes_file.read(self.locker_file) rec['lock_file'] = self.locker_file rec['path'] = self.locker_path return rec
def get_item(self, item_id: str) -> dict: """ Attempts to find and return a named item in the locker. Raises an exception of item isn't found @param item_id: ID of item - encryption of the item_name @return: the item dict """ item_path = self.locker_path / f"{item_id}.{ITEM_FILE_EXT}" if item_path.exists(): return phibes_file.read(item_path) else: raise PhibesNotFoundError(f"{item_id} not found")
def test_allow_empty(self): phibes_file.write(self.pth, salt=self.test_salt, crypt_id=self.test_crypt_id, timestamp=self.test_timestamp, body="", allow_empty=True, overwrite=True) result = phibes_file.read(self.pth) assert result['salt'] == self.test_salt assert result['crypt_id'] == self.test_crypt_id assert result['timestamp'] == self.test_timestamp assert result['body'] == ''
def read(self, pth: Path) -> None: """ Read an Item from the file at pth Caller (a locker) is responsible for any validation. e.g. does the salt in the file and the locker key produce the encoded/encrypted file name? If not, the contents won't be decrypted correctly. :param pth: :return: """ rec = phibes_file.read(pth) Item.make_item_from_dict( crypt_obj=self.crypt_impl, name=self.name, item_dict=rec, item_inst=self )
def test_allow_overwrite(self): phibes_file.write(self.pth, salt=self.test_salt, crypt_id=self.test_crypt_id, timestamp=self.test_timestamp, body=f"{self.test_body}", overwrite=True) phibes_file.write(self.pth, salt=self.test_salt, crypt_id=self.test_crypt_id, timestamp=self.test_timestamp, body="replacement", overwrite=True) result = phibes_file.read(self.pth) assert result['salt'] == self.test_salt assert result['crypt_id'] == self.test_crypt_id assert result['timestamp'] == self.test_timestamp assert result['body'] == 'replacement'