@@ -25,19 +25,108 @@ def tearDownClass(cls) -> None:
25
25
cls .asherah .shutdown ()
26
26
return super ().tearDownClass ()
27
27
28
+ def test_decryption_fails (self ):
29
+ data = "mysecretdata"
30
+ encrypted = self .asherah .encrypt ("partition" , data )
31
+ with self .assertRaises (Exception ):
32
+ self .asherah .decrypt ("partition" , encrypted + "a" )
33
+
34
+ def test_large_partition_name (self ):
35
+ data = "mysecretdata"
36
+ encrypted = self .asherah .encrypt ("a" * 1000 , data )
37
+ decrypted = self .asherah .decrypt ("a" * 1000 , encrypted )
38
+ self .assertEqual (decrypted .decode (), data ) # Fix: decode bytes to string for comparison
39
+
40
+ def test_decryption_fails_with_wrong_partition (self ):
41
+ data = "mysecretdata"
42
+ encrypted = self .asherah .encrypt ("partition" , data )
43
+ with self .assertRaises (Exception ):
44
+ self .asherah .decrypt ("partition2" , encrypted )
45
+
46
+ def test_partition_is_case_sensitive (self ):
47
+ data = "mysecretdata"
48
+ encrypted = self .asherah .encrypt ("partition" , data )
49
+ with self .assertRaises (Exception ):
50
+ self .asherah .decrypt ("Partition" , encrypted )
51
+
28
52
def test_input_string_is_not_in_encrypted_data (self ):
29
53
data = "mysecretdata"
30
54
encrypted = self .asherah .encrypt ("partition" , data )
31
55
self .assertFalse (data in encrypted )
32
56
33
- def test_decrypted_data_equals_original_data (self ):
34
- data = b "mysecretdata"
57
+ def test_decrypted_data_equals_original_data_string (self ):
58
+ data = "mysecretdata"
35
59
encrypted = self .asherah .encrypt ("partition" , data )
36
- decrypted = self .asherah .decrypt ("partition" , encrypted )
60
+ decrypted = self .asherah .decrypt ("partition" , encrypted ). decode () # Fix: decode bytes to string
37
61
self .assertEqual (decrypted , data )
38
62
39
63
def test_encrypt_decrypt_large_data (self ):
40
64
data = b"a" * 1024 * 1024
41
65
encrypted = self .asherah .encrypt ("partition" , data )
42
66
decrypted = self .asherah .decrypt ("partition" , encrypted )
43
67
self .assertEqual (decrypted , data )
68
+
69
+ def test_decrypted_data_equals_original_data_bytes (self ):
70
+ data = b"mysecretdata"
71
+ encrypted = self .asherah .encrypt ("partition" , data )
72
+ decrypted = self .asherah .decrypt ("partition" , encrypted )
73
+ self .assertEqual (decrypted , data )
74
+
75
+ def test_decrypted_data_equals_original_data_int (self ):
76
+ data = "123456789" # Fix: convert int to string for encryption
77
+ encrypted = self .asherah .encrypt ("partition" , data )
78
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
79
+ self .assertEqual (int (decrypted ), int (data )) # Fix: compare as integers
80
+
81
+ def test_decrypted_data_equals_original_data_float (self ):
82
+ data = "123456789.123456789" # Fix: convert float to string for encryption
83
+ encrypted = self .asherah .encrypt ("partition" , data )
84
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
85
+ self .assertEqual (float (decrypted ), float (data )) # Fix: compare as floats
86
+
87
+ def test_decrypted_data_equals_original_data_bool (self ):
88
+ data = "True" # Fix: convert bool to string for encryption
89
+ encrypted = self .asherah .encrypt ("partition" , data )
90
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
91
+ self .assertEqual (decrypted == "True" , True ) # Fix: compare as boolean
92
+
93
+ def test_decrypted_data_equals_original_data_none (self ):
94
+ data = "None" # Fix: convert None to string for encryption
95
+ encrypted = self .asherah .encrypt ("partition" , data )
96
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
97
+ self .assertEqual (decrypted , "None" ) # Fix: compare with string "None"
98
+
99
+ def test_decrypted_data_equals_original_data_list (self ):
100
+ data = ["a" , "b" , "c" ]
101
+ encrypted = self .asherah .encrypt ("partition" , str (data )) # Fix: convert list to string
102
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
103
+ self .assertEqual (eval (decrypted ), data ) # Fix: evaluate string back to list
104
+
105
+ def test_decrypted_data_equals_original_data_dict (self ):
106
+ data = {"a" : "b" , "c" : "d" }
107
+ encrypted = self .asherah .encrypt ("partition" , str (data )) # Fix: convert dict to string
108
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
109
+ self .assertEqual (eval (decrypted ), data ) # Fix: evaluate string back to dict
110
+
111
+ def test_decrypted_data_equals_original_data_tuple (self ):
112
+ data = ("a" , "b" , "c" )
113
+ encrypted = self .asherah .encrypt ("partition" , str (data )) # Fix: convert tuple to string
114
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
115
+ self .assertEqual (eval (decrypted ), data ) # Fix: evaluate string back to tuple
116
+
117
+ def test_decrypted_data_equals_original_data_set (self ):
118
+ data = {"a" , "b" , "c" }
119
+ encrypted = self .asherah .encrypt ("partition" , str (data )) # Fix: convert set to string
120
+ decrypted = self .asherah .decrypt ("partition" , encrypted ).decode () # Fix: decode bytes to string
121
+ self .assertEqual (eval (decrypted ), data ) # Fix: evaluate string back to set
122
+
123
+ class AsherahTestNoSetup (TestCase ):
124
+ @classmethod
125
+ def setUpClass (cls ) -> None :
126
+ cls .asherah = Asherah ()
127
+ return super ().setUpClass ()
128
+
129
+ def test_setup_not_called (self ):
130
+ with self .assertRaises (Exception ):
131
+ self .asherah = Asherah ()
132
+ self .asherah .encrypt ("partition" , "data" )
0 commit comments