fts5securefault.test 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. source [file join [file dirname [info script]] fts5_common.tcl]
  15. source $testdir/malloc_common.tcl
  16. set testprefix fts5securefault
  17. # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
  18. return_if_no_fts5
  19. do_execsql_test 1.0 {
  20. CREATE VIRTUAL TABLE t1 USING fts5(ab);
  21. INSERT INTO t1(rowid, ab) VALUES
  22. (0, 'abc'), (1, 'abc'), (2, 'abc'), (3, 'abc'), (4, 'def');
  23. }
  24. faultsim_save_and_close
  25. do_faultsim_test 1.1 -faults oom* -prep {
  26. faultsim_restore_and_reopen
  27. execsql {
  28. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  29. }
  30. } -body {
  31. execsql { DELETE FROM t1 WHERE rowid=2 }
  32. } -test {
  33. faultsim_test_result {0 {}}
  34. }
  35. do_faultsim_test 1.2 -faults oom* -prep {
  36. faultsim_restore_and_reopen
  37. execsql {
  38. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  39. }
  40. } -body {
  41. execsql { DELETE FROM t1 WHERE rowid IN(0, 1, 2, 3, 4) }
  42. } -test {
  43. faultsim_test_result {0 {}}
  44. }
  45. #-------------------------------------------------------------------------
  46. #
  47. reset_db
  48. set big [string repeat abcdefghij 5]
  49. set big2 [string repeat klmnopqrst 5]
  50. set doc "$big $big2"
  51. do_execsql_test 2.0 {
  52. CREATE VIRTUAL TABLE t1 USING fts5(ab);
  53. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  54. WITH s(i) AS (
  55. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<4
  56. )
  57. INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
  58. }
  59. faultsim_save_and_close
  60. do_faultsim_test 2.1 -faults oom* -prep {
  61. faultsim_restore_and_reopen
  62. execsql {
  63. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  64. }
  65. } -body {
  66. execsql { DELETE FROM t1 WHERE rowid = 3 }
  67. execsql { DELETE FROM t1 WHERE rowid = 4 }
  68. } -test {
  69. faultsim_test_result {0 {}}
  70. }
  71. #-------------------------------------------------------------------------
  72. #
  73. reset_db
  74. set big [string repeat abcdefghij 5]
  75. set big2 [string repeat klmnopqrst 5]
  76. set doc "$big $big2"
  77. do_execsql_test 3.0 {
  78. CREATE VIRTUAL TABLE t1 USING fts5(ab);
  79. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  80. WITH s(i) AS (
  81. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<25
  82. )
  83. INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
  84. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  85. DELETE FROM t1 WHERE rowid BETWEEN 3 AND 23;
  86. }
  87. faultsim_save_and_close
  88. do_faultsim_test 3.1 -faults oom* -prep {
  89. faultsim_restore_and_reopen
  90. execsql {
  91. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  92. }
  93. } -body {
  94. execsql { DELETE FROM t1 WHERE rowid = 24 }
  95. execsql { DELETE FROM t1 WHERE rowid = 25 }
  96. } -test {
  97. faultsim_test_result {0 {}}
  98. }
  99. #-------------------------------------------------------------------------
  100. #
  101. reset_db
  102. set doc [string repeat "tok " 400]
  103. do_execsql_test 4.0 {
  104. CREATE VIRTUAL TABLE t1 USING fts5(ab);
  105. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  106. INSERT INTO t1(rowid, ab) VALUES(1, $doc), (2, $doc), (3, $doc);
  107. }
  108. faultsim_save_and_close
  109. do_faultsim_test 4.1 -faults oom* -prep {
  110. faultsim_restore_and_reopen
  111. execsql {
  112. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  113. }
  114. } -body {
  115. execsql { DELETE FROM t1 WHERE rowid = 2 }
  116. } -test {
  117. faultsim_test_result {0 {}}
  118. }
  119. #-------------------------------------------------------------------------
  120. #
  121. reset_db
  122. set doc1 [string repeat "abc " 10]
  123. set doc2 [string repeat "def " 10]
  124. do_test 5.0 {
  125. execsql {
  126. CREATE VIRTUAL TABLE t1 USING fts5(ab);
  127. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  128. BEGIN;
  129. }
  130. for {set i 0} {$i < 50} {incr i} {
  131. execsql {
  132. INSERT INTO t1(rowid, ab) VALUES($i, 'abcdefg');
  133. }
  134. }
  135. execsql {
  136. INSERT INTO t1(rowid, ab) VALUES(105, 'def');
  137. COMMIT;
  138. }
  139. } {}
  140. faultsim_save_and_close
  141. do_faultsim_test 5.1 -faults oom* -prep {
  142. faultsim_restore_and_reopen
  143. execsql {
  144. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  145. }
  146. } -body {
  147. execsql { DELETE FROM t1 WHERE rowid = 105 }
  148. } -test {
  149. faultsim_test_result {0 {}}
  150. }
  151. #-------------------------------------------------------------------------
  152. #
  153. reset_db
  154. do_test 6.0 {
  155. execsql {
  156. CREATE VIRTUAL TABLE t1 USING fts5(ab);
  157. INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
  158. BEGIN;
  159. INSERT INTO t1(rowid, ab) VALUES(1, 'abcdefg');
  160. INSERT INTO t1(rowid, ab) VALUES(2, 'abcdefg');
  161. INSERT INTO t1(rowid, ab) VALUES(3, 'abcdefg');
  162. COMMIT;
  163. }
  164. } {}
  165. faultsim_save_and_close
  166. do_faultsim_test 6.1 -faults oom* -prep {
  167. faultsim_restore_and_reopen
  168. execsql {
  169. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  170. }
  171. } -body {
  172. execsql {
  173. UPDATE t1 SET ab='abcdefg' WHERE rowid=2;
  174. }
  175. } -test {
  176. faultsim_test_result {0 {}}
  177. }
  178. #-------------------------------------------------------------------------
  179. #
  180. reset_db
  181. do_test 7.0 {
  182. execsql {
  183. CREATE VIRTUAL TABLE t1 USING fts5(ab);
  184. INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
  185. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  186. }
  187. } {}
  188. faultsim_save_and_close
  189. do_faultsim_test 7.1 -faults oom* -prep {
  190. faultsim_restore_and_reopen
  191. set big1 "[string repeat x 50] [string repeat y 50] [string repeat z 50]"
  192. execsql {
  193. BEGIN;
  194. INSERT INTO t1 VALUES($big1);
  195. }
  196. } -body {
  197. execsql { COMMIT }
  198. } -test {
  199. faultsim_test_result {0 {}}
  200. }
  201. finish_test