sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / fts5 / test / fts5securefault.test
| 1 | # 2023 April 14 |
| 2 | # |
| 3 | # The author disclaims copyright to this source code. In place of |
| 4 | # a legal notice, here is a blessing: |
| 5 | # |
| 6 | # May you do good and not evil. |
| 7 | # May you find forgiveness for yourself and forgive others. |
| 8 | # May you share freely, never taking more than you give. |
| 9 | # |
| 10 | #************************************************************************* |
| 11 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this script is testing the FTS5 module. |
| 13 | # |
| 14 | |
| 15 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 16 | source $testdir/malloc_common.tcl |
| 17 | set testprefix fts5securefault |
| 18 | |
| 19 | # If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 20 | return_if_no_fts5 |
| 21 | |
| 22 | do_execsql_test 1.0 { |
| 23 | CREATE VIRTUAL TABLE t1 USING fts5(ab); |
| 24 | INSERT INTO t1(rowid, ab) VALUES |
| 25 | (0, 'abc'), (1, 'abc'), (2, 'abc'), (3, 'abc'), (4, 'def'); |
| 26 | } |
| 27 | faultsim_save_and_close |
| 28 | |
| 29 | do_faultsim_test 1.1 -faults oom* -prep { |
| 30 | faultsim_restore_and_reopen |
| 31 | execsql { |
| 32 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 33 | } |
| 34 | } -body { |
| 35 | execsql { DELETE FROM t1 WHERE rowid=2 } |
| 36 | } -test { |
| 37 | faultsim_test_result {0 {}} |
| 38 | } |
| 39 | do_faultsim_test 1.2 -faults oom* -prep { |
| 40 | faultsim_restore_and_reopen |
| 41 | execsql { |
| 42 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 43 | } |
| 44 | } -body { |
| 45 | execsql { DELETE FROM t1 WHERE rowid IN(0, 1, 2, 3, 4) } |
| 46 | } -test { |
| 47 | faultsim_test_result {0 {}} |
| 48 | } |
| 49 | |
| 50 | #------------------------------------------------------------------------- |
| 51 | # |
| 52 | reset_db |
| 53 | set big [string repeat abcdefghij 5] |
| 54 | set big2 [string repeat klmnopqrst 5] |
| 55 | set doc "$big $big2" |
| 56 | |
| 57 | do_execsql_test 2.0 { |
| 58 | CREATE VIRTUAL TABLE t1 USING fts5(ab); |
| 59 | INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 60 | WITH s(i) AS ( |
| 61 | SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<4 |
| 62 | ) |
| 63 | INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s; |
| 64 | } |
| 65 | faultsim_save_and_close |
| 66 | |
| 67 | do_faultsim_test 2.1 -faults oom* -prep { |
| 68 | faultsim_restore_and_reopen |
| 69 | execsql { |
| 70 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 71 | } |
| 72 | } -body { |
| 73 | execsql { DELETE FROM t1 WHERE rowid = 3 } |
| 74 | execsql { DELETE FROM t1 WHERE rowid = 4 } |
| 75 | } -test { |
| 76 | faultsim_test_result {0 {}} |
| 77 | } |
| 78 | |
| 79 | #------------------------------------------------------------------------- |
| 80 | # |
| 81 | reset_db |
| 82 | set big [string repeat abcdefghij 5] |
| 83 | set big2 [string repeat klmnopqrst 5] |
| 84 | set doc "$big $big2" |
| 85 | |
| 86 | do_execsql_test 3.0 { |
| 87 | CREATE VIRTUAL TABLE t1 USING fts5(ab); |
| 88 | INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 89 | WITH s(i) AS ( |
| 90 | SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<25 |
| 91 | ) |
| 92 | INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s; |
| 93 | |
| 94 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 95 | DELETE FROM t1 WHERE rowid BETWEEN 3 AND 23; |
| 96 | } |
| 97 | faultsim_save_and_close |
| 98 | |
| 99 | do_faultsim_test 3.1 -faults oom* -prep { |
| 100 | faultsim_restore_and_reopen |
| 101 | execsql { |
| 102 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 103 | } |
| 104 | } -body { |
| 105 | execsql { DELETE FROM t1 WHERE rowid = 24 } |
| 106 | execsql { DELETE FROM t1 WHERE rowid = 25 } |
| 107 | } -test { |
| 108 | faultsim_test_result {0 {}} |
| 109 | } |
| 110 | |
| 111 | #------------------------------------------------------------------------- |
| 112 | # |
| 113 | reset_db |
| 114 | set doc [string repeat "tok " 400] |
| 115 | |
| 116 | do_execsql_test 4.0 { |
| 117 | CREATE VIRTUAL TABLE t1 USING fts5(ab); |
| 118 | INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 119 | INSERT INTO t1(rowid, ab) VALUES(1, $doc), (2, $doc), (3, $doc); |
| 120 | } |
| 121 | faultsim_save_and_close |
| 122 | |
| 123 | do_faultsim_test 4.1 -faults oom* -prep { |
| 124 | faultsim_restore_and_reopen |
| 125 | execsql { |
| 126 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 127 | } |
| 128 | } -body { |
| 129 | execsql { DELETE FROM t1 WHERE rowid = 2 } |
| 130 | } -test { |
| 131 | faultsim_test_result {0 {}} |
| 132 | } |
| 133 | |
| 134 | #------------------------------------------------------------------------- |
| 135 | # |
| 136 | reset_db |
| 137 | |
| 138 | set doc1 [string repeat "abc " 10] |
| 139 | set doc2 [string repeat "def " 10] |
| 140 | |
| 141 | do_test 5.0 { |
| 142 | execsql { |
| 143 | CREATE VIRTUAL TABLE t1 USING fts5(ab); |
| 144 | INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 145 | BEGIN; |
| 146 | } |
| 147 | for {set i 0} {$i < 50} {incr i} { |
| 148 | execsql { |
| 149 | INSERT INTO t1(rowid, ab) VALUES($i, 'abcdefg'); |
| 150 | } |
| 151 | } |
| 152 | execsql { |
| 153 | INSERT INTO t1(rowid, ab) VALUES(105, 'def'); |
| 154 | COMMIT; |
| 155 | } |
| 156 | } {} |
| 157 | faultsim_save_and_close |
| 158 | |
| 159 | do_faultsim_test 5.1 -faults oom* -prep { |
| 160 | faultsim_restore_and_reopen |
| 161 | execsql { |
| 162 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 163 | } |
| 164 | } -body { |
| 165 | execsql { DELETE FROM t1 WHERE rowid = 105 } |
| 166 | } -test { |
| 167 | faultsim_test_result {0 {}} |
| 168 | } |
| 169 | |
| 170 | #------------------------------------------------------------------------- |
| 171 | # |
| 172 | reset_db |
| 173 | do_test 6.0 { |
| 174 | execsql { |
| 175 | CREATE VIRTUAL TABLE t1 USING fts5(ab); |
| 176 | INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 177 | BEGIN; |
| 178 | INSERT INTO t1(rowid, ab) VALUES(1, 'abcdefg'); |
| 179 | INSERT INTO t1(rowid, ab) VALUES(2, 'abcdefg'); |
| 180 | INSERT INTO t1(rowid, ab) VALUES(3, 'abcdefg'); |
| 181 | COMMIT; |
| 182 | } |
| 183 | } {} |
| 184 | faultsim_save_and_close |
| 185 | |
| 186 | do_faultsim_test 6.1 -faults oom* -prep { |
| 187 | faultsim_restore_and_reopen |
| 188 | execsql { |
| 189 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 190 | } |
| 191 | } -body { |
| 192 | execsql { |
| 193 | UPDATE t1 SET ab='abcdefg' WHERE rowid=2; |
| 194 | } |
| 195 | } -test { |
| 196 | faultsim_test_result {0 {}} |
| 197 | } |
| 198 | |
| 199 | #------------------------------------------------------------------------- |
| 200 | # |
| 201 | reset_db |
| 202 | do_test 7.0 { |
| 203 | execsql { |
| 204 | CREATE VIRTUAL TABLE t1 USING fts5(ab); |
| 205 | INSERT INTO t1(t1, rank) VALUES('pgsz', 32); |
| 206 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 207 | } |
| 208 | } {} |
| 209 | faultsim_save_and_close |
| 210 | |
| 211 | do_faultsim_test 7.1 -faults oom* -prep { |
| 212 | faultsim_restore_and_reopen |
| 213 | set big1 "[string repeat x 50] [string repeat y 50] [string repeat z 50]" |
| 214 | execsql { |
| 215 | BEGIN; |
| 216 | INSERT INTO t1 VALUES($big1); |
| 217 | } |
| 218 | } -body { |
| 219 | execsql { COMMIT } |
| 220 | } -test { |
| 221 | faultsim_test_result {0 {}} |
| 222 | } |
| 223 | |
| 224 | |
| 225 | finish_test |