@@ -95,7 +95,11 @@ def test_end_to_end_simple(self):
95
95
self .assertEquals (expected , encrypted )
96
96
self .assertEquals (expected , unencrypted )
97
97
98
- def test_end_to_end_different_cle_contexts (self ):
98
+ def test_end_to_end_different_cle_contexts_different_ivs (self ):
99
+ """
100
+ Test to validate PYTHON-1350. We should be able to decode the data from two different contexts (with two different IVs)
101
+ since the IV used to decrypt the data is actually now stored with the data.
102
+ """
99
103
100
104
expected = 2
101
105
@@ -133,3 +137,34 @@ def test_end_to_end_different_cle_contexts(self):
133
137
(encrypted ,unencrypted ) = session2 .execute ("select encrypted, unencrypted from foo.bar where unencrypted = %s allow filtering" , (expected ,)).one ()
134
138
self .assertEquals (expected , encrypted )
135
139
self .assertEquals (expected , unencrypted )
140
+
141
+ def test_end_to_end_different_cle_contexts_different_policies (self ):
142
+ """
143
+ Test to validate PYTHON-1356. Class variables used to pass CLE policy down to protocol handler shouldn't persist.
144
+ """
145
+
146
+ expected = 3
147
+
148
+ key = os .urandom (AES256_KEY_SIZE_BYTES )
149
+ (col_desc , cl_policy ) = self ._create_policy (key )
150
+ cluster = TestCluster (column_encryption_policy = cl_policy )
151
+ session = cluster .connect ()
152
+ self ._recreate_keyspace (session )
153
+
154
+ # Use encode_and_encrypt helper function to populate date
155
+ session .execute ("insert into foo.bar (encrypted, unencrypted) values (%s,%s)" ,(cl_policy .encode_and_encrypt (col_desc , expected ), expected ))
156
+
157
+ # We now open a new session _without_ the CLE policy specified. We should _not_ be able to read decrypted bits from this session.
158
+ cluster2 = TestCluster ()
159
+ session2 = cluster2 .connect ()
160
+
161
+ # A straight select from the database will now return the decrypted bits. We select both encrypted and unencrypted
162
+ # values here to confirm that we don't interfere with regular processing of unencrypted vals.
163
+ (encrypted ,unencrypted ) = session2 .execute ("select encrypted, unencrypted from foo.bar where unencrypted = %s allow filtering" , (expected ,)).one ()
164
+ self .assertEquals (cl_policy .encode_and_encrypt (col_desc , expected ), encrypted )
165
+ self .assertEquals (expected , unencrypted )
166
+
167
+ # Confirm the same behaviour from a subsequent prepared statement as well
168
+ prepared = session2 .prepare ("select encrypted, unencrypted from foo.bar where unencrypted = ? allow filtering" )
169
+ (encrypted ,unencrypted ) = session2 .execute (prepared , [expected ]).one ()
170
+ self .assertEquals (cl_policy .encode_and_encrypt (col_desc , expected ), encrypted )
0 commit comments