@@ -114,7 +114,7 @@ $$ LANGUAGE plpgsql;
114
114
115
115
116
116
-- -----------------------------------------------
117
- -- Start encryptindexing wwith no target table
117
+ -- Start encryptindexing with no target table
118
118
--
119
119
-- The schema should be validated first.
120
120
-- Users table does not exist, so should fail.
@@ -129,7 +129,7 @@ DO $$
129
129
130
130
BEGIN
131
131
PERFORM cs_encrypt_v1();
132
- RAISE NOTICE ' Missinbg users table. Encrypt should have failed.' ;
132
+ RAISE NOTICE ' Missing users table. Encrypt should have failed.' ;
133
133
ASSERT false; -- skipped by exception
134
134
EXCEPTION
135
135
WHEN OTHERS THEN
@@ -143,6 +143,29 @@ DO $$
143
143
$$ LANGUAGE plpgsql;
144
144
145
145
146
+ -- -----------------------------------------------
147
+ -- FORCE start encryptindexing with no target table
148
+ --
149
+ -- Schema validation is skipped
150
+ -- -----------------------------------------------
151
+ DROP TABLE IF EXISTS users;
152
+ TRUNCATE TABLE cs_configuration_v1;
153
+
154
+
155
+ DO $$
156
+ BEGIN
157
+ PERFORM cs_add_index_v1(' users' , ' name' , ' match' );
158
+
159
+ PERFORM cs_encrypt_v1(true);
160
+ RAISE NOTICE ' Missing users table. Encrypt should have failed.' ;
161
+
162
+ -- configuration state should be changed
163
+ ASSERT (SELECT NOT EXISTS (SELECT FROM cs_configuration_v1 c WHERE c .state = ' pending' ));
164
+ ASSERT (SELECT EXISTS (SELECT FROM cs_configuration_v1 c WHERE c .state = ' encrypting' ));
165
+
166
+ END;
167
+ $$ LANGUAGE plpgsql;
168
+
146
169
147
170
-- -----------------------------------------------
148
171
-- With existing active config
@@ -171,7 +194,7 @@ INSERT INTO cs_configuration_v1 (state, data) VALUES (
171
194
}' ::jsonb
172
195
);
173
196
174
- -- Create a table with multiple plaintext columns
197
+ -- Create a table with plaintext and encrypted columns
175
198
DROP TABLE IF EXISTS users;
176
199
CREATE TABLE users
177
200
(
@@ -195,6 +218,56 @@ DO $$
195
218
$$ LANGUAGE plpgsql;
196
219
197
220
221
+ -- -----------------------------------------------
222
+ -- With existing active config and an updated schema using a raw JSONB column
223
+ -- Start encryptindexing
224
+ -- The active config is unchanged
225
+ -- The pending config should now be encrypting
226
+ -- -----------------------------------------------
227
+ TRUNCATE TABLE cs_configuration_v1;
228
+
229
+ -- create an active configuration
230
+ INSERT INTO cs_configuration_v1 (state, data) VALUES (
231
+ ' active' ,
232
+ ' {
233
+ "v": 1,
234
+ "tables": {
235
+ "users": {
236
+ "name": {
237
+ "cast_as": "text",
238
+ "indexes": {
239
+ "unique": {}
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }' ::jsonb
245
+ );
246
+
247
+ -- Create a table with plaintext and jsonb column
248
+ DROP TABLE IF EXISTS users;
249
+ CREATE TABLE users
250
+ (
251
+ id bigint GENERATED ALWAYS AS IDENTITY,
252
+ name TEXT ,
253
+ name_encrypted jsonb,
254
+ PRIMARY KEY (id)
255
+ );
256
+
257
+
258
+ -- An encrypting config should exist
259
+ DO $$
260
+ BEGIN
261
+ PERFORM cs_add_index_v1(' users' , ' name' , ' match' );
262
+ PERFORM cs_encrypt_v1();
263
+
264
+ ASSERT (SELECT EXISTS (SELECT FROM cs_configuration_v1 c WHERE c .state = ' active' ));
265
+ ASSERT (SELECT EXISTS (SELECT FROM cs_configuration_v1 c WHERE c .state = ' encrypting' ));
266
+ ASSERT (SELECT NOT EXISTS (SELECT FROM cs_configuration_v1 c WHERE c .state = ' pending' ));
267
+ END;
268
+ $$ LANGUAGE plpgsql;
269
+
270
+
198
271
-- -----------------------------------------------
199
272
-- With existing active config
200
273
-- Activate encrypting config
0 commit comments