2022-01-24 12:47:18 +08:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from gradio import encryptor, processing_utils
|
2022-04-20 02:27:32 +08:00
|
|
|
from gradio.media_data import BASE64_IMAGE
|
2022-01-24 12:47:18 +08:00
|
|
|
|
|
|
|
os.environ["GRADIO_ANALYTICS_ENABLED"] = "False"
|
|
|
|
|
|
|
|
|
|
|
|
class TestKeyGenerator(unittest.TestCase):
|
|
|
|
def test_same_pass(self):
|
|
|
|
key1 = encryptor.get_key("test")
|
|
|
|
key2 = encryptor.get_key("test")
|
2022-03-24 00:22:44 +08:00
|
|
|
self.assertEqual(key1, key2)
|
2022-01-24 12:47:18 +08:00
|
|
|
|
|
|
|
def test_diff_pass(self):
|
|
|
|
key1 = encryptor.get_key("test")
|
|
|
|
key2 = encryptor.get_key("diff_test")
|
2022-03-24 00:22:44 +08:00
|
|
|
self.assertNotEqual(key1, key2)
|
2022-01-24 12:47:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
class TestEncryptorDecryptor(unittest.TestCase):
|
|
|
|
def test_same_pass(self):
|
|
|
|
key = encryptor.get_key("test")
|
|
|
|
data, _ = processing_utils.decode_base64_to_binary(BASE64_IMAGE)
|
|
|
|
encrypted_data = encryptor.encrypt(key, data)
|
|
|
|
decrypted_data = encryptor.decrypt(key, encrypted_data)
|
2022-03-24 00:22:44 +08:00
|
|
|
self.assertEqual(data, decrypted_data)
|
2022-02-09 02:56:13 +08:00
|
|
|
|
2022-01-24 12:47:18 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|