| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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()
-
|