|
43 | 43 | $$ LANGUAGE plpgsql; |
44 | 44 |
|
45 | 45 |
|
| 46 | +-- ----------------------------------------------- |
| 47 | +-- Adding search config adds the constraint |
| 48 | +-- |
| 49 | +-- ----------------------------------------------- |
| 50 | +TRUNCATE TABLE eql_v2_configuration; |
| 51 | + |
| 52 | +DO $$ |
| 53 | + BEGIN |
| 54 | + -- reset the table |
| 55 | + PERFORM create_table_with_encrypted(); |
| 56 | + |
| 57 | + PERFORM eql_v2.add_search_config('encrypted', 'e', 'match'); |
| 58 | + |
| 59 | + PERFORM assert_exception( |
| 60 | + 'Constraint catches invalid eql_v2_encrypted', |
| 61 | + 'INSERT INTO encrypted (e) VALUES (''{}''::jsonb::eql_v2_encrypted)'); |
| 62 | + |
| 63 | + -- add constraint without error |
| 64 | + PERFORM eql_v2.add_encrypted_constraint('encrypted', 'e'); |
| 65 | + |
| 66 | + PERFORM eql_v2.remove_encrypted_constraint('encrypted', 'e'); |
| 67 | + |
| 68 | + PERFORM assert_result( |
| 69 | + 'Insert invalid data without constraint', |
| 70 | + 'INSERT INTO encrypted (e) VALUES (''{}''::jsonb::eql_v2_encrypted) RETURNING id'); |
| 71 | + |
| 72 | + END; |
| 73 | +$$ LANGUAGE plpgsql; |
| 74 | + |
| 75 | + |
| 76 | +-- ----------------------------------------------- |
| 77 | +-- Adding column adds the constraint |
| 78 | +-- |
| 79 | +-- ----------------------------------------------- |
| 80 | +TRUNCATE TABLE eql_v2_configuration; |
| 81 | + |
| 82 | +DO $$ |
| 83 | + BEGIN |
| 84 | + -- reset the table |
| 85 | + PERFORM create_table_with_encrypted(); |
| 86 | + |
| 87 | + PERFORM eql_v2.add_column('encrypted', 'e'); |
| 88 | + |
| 89 | + PERFORM assert_exception( |
| 90 | + 'Constraint catches invalid eql_v2_encrypted', |
| 91 | + 'INSERT INTO encrypted (e) VALUES (''{}''::jsonb::eql_v2_encrypted)'); |
| 92 | + |
| 93 | + -- add constraint without error |
| 94 | + PERFORM eql_v2.add_encrypted_constraint('encrypted', 'e'); |
| 95 | + |
| 96 | + PERFORM eql_v2.remove_encrypted_constraint('encrypted', 'e'); |
| 97 | + |
| 98 | + PERFORM assert_result( |
| 99 | + 'Insert invalid data without constraint', |
| 100 | + 'INSERT INTO encrypted (e) VALUES (''{}''::jsonb::eql_v2_encrypted) RETURNING id'); |
| 101 | + |
| 102 | + END; |
| 103 | +$$ LANGUAGE plpgsql; |
| 104 | + |
| 105 | + |
46 | 106 | -- EQL version is enforced |
47 | 107 | DO $$ |
48 | 108 | DECLARE |
|
0 commit comments