def test_disk_persister(setup_params): path = "/tmp/peacemakr" os.mkdir(path) persister = DiskPersister(path) sdk = Factory.get_crypto_sdk(api_key=setup_params["api_key"], client_name="test_encrypt_decrypt_string", peacemakr_hostname=setup_params["test_url"], persister=persister) sdk.register() # sleep to wait for keys to be generated in server time.sleep(2) sdk.sync() num_clients = persister.key_nums() assert(num_clients != 0) N = random.randint(0,1000) plain_text = ''.join(random.choices(string.printable, k=N)) encrypted_text = sdk.encrypt(plain_text.encode()) assert(plain_text != encrypted_text) # ouptut is bytes decrypted_text = sdk.decrypt(encrypted_text) assert(decrypted_text == plain_text.encode())
def test_register(setup_params): persister = InMemoryPersister() sdk = Factory.get_crypto_sdk(api_key=setup_params["api_key"], client_name="test_register", peacemakr_hostname=setup_params["test_url"], persister=persister) sdk.register() num_clients = persister.key_nums() assert(num_clients != 0)
def main(): api_key = "api-key" sdk = Factory.get_crypto_sdk() sdk.register() sdk.sync() sdk.encrypt(b'some text') sdk.encrypt_in_domain(b'some text', "some domain") sdk.decrypt(b'cipher text')
def test_sync(setup_params): persister = InMemoryPersister() sdk = Factory.get_crypto_sdk(api_key=setup_params["api_key"], client_name="test_sync", peacemakr_hostname=setup_params["test_url"], persister=persister) sdk.register() # sleep for 1 sec to wait for sdk to have at least few keys ready # we should check for raise exception time.sleep(1) sdk.sync() num_clients = persister.key_nums() assert(num_clients != 0)
def test_encrypt_decrypt_bytes(setup_params): persister = InMemoryPersister() sdk = Factory.get_crypto_sdk(api_key=setup_params["api_key"], client_name="test_encrypt_decrypt_bytes", peacemakr_hostname=setup_params["test_url"], persister=persister) sdk.register() # sleep to wait for keys to be generated in server time.sleep(2) sdk.sync() num_clients = persister.key_nums() assert(num_clients != 0) # generate random bytes random_bytes = os.urandom(100) # encode random bytes to utf-8 plain_text = random_bytes encrypted_text = sdk.encrypt(plain_text) assert(plain_text != encrypted_text) # ouptut is bytes decrypted_text = sdk.decrypt(encrypted_text) assert(decrypted_text == plain_text)