| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | 
							- import pathlib
 
- current = pathlib.Path(__file__).parent
 
- root = current.parent
 
- import sys
 
- sys.path.append(str(root))
 
- import assets
 
- def drop_db() -> None:
 
-     db = pathlib.Path("./009-application_crypter.db")
 
-     if db.is_file():
 
-         db.unlink()
 
- drop_db()
 
- import sqlmodel
 
- connection = sqlmodel.create_engine("sqlite:///009-application_crypted.db")
 
- user_app = assets.application_user(connection)
 
- crypter_app = assets.application_crypter(connection)
 
- sqlmodel.SQLModel.metadata.create_all(connection)
 
- user_app.register("test", "password")
 
- apikey = user_app.login("test", "password")["apikey"]
 
- print("Create test user, apikey: " + apikey)
 
- code_key = user_app.get(apikey)["code_key"]
 
- coder = assets.code_key_manager("password", code_key).coder
 
- outside_sample_plain = "SECRET"
 
- outside_sample_crypted = coder.encrypt(outside_sample_plain)
 
- print()
 
- print("Testing encryption works...")
 
- result_a = crypter_app.encrypt(apikey, "password", outside_sample_plain)
 
- print("Crypted:")
 
- print(result_a)
 
- print("Encrypted with other coder:")
 
- print(coder.decrypt(result_a["crypted"]))
 
- print()
 
- print("Testing decryption works...")
 
- print("Decrypted:")
 
- print(crypter_app.decrypt(apikey, "password", outside_sample_crypted))
 
- print()
 
- print("Testing bad password:")
 
- print(crypter_app.decrypt(apikey, "bad_psk", outside_sample_crypted))
 
- print()
 
- print("Testing with bad apikey:")
 
- print(crypter_app.decrypt("NOT_EXISTS", "bad_psk", outside_sample_crypted))
 
- drop_db()
 
 
  |