fts5secure4.test 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #
  12. source [file join [file dirname [info script]] fts5_common.tcl]
  13. return_if_no_fts5
  14. set ::testprefix fts5secure4
  15. #-------------------------------------------------------------------------
  16. # Test using the 'delete' command to attempt to delete a token that
  17. # is not present in the index in secure-delete mode.
  18. #
  19. do_execsql_test 1.0 {
  20. CREATE VIRTUAL TABLE t1 USING fts5(a, b, content=x1);
  21. CREATE TABLE x1(rowid INTEGER PRIMARY KEY, a, b);
  22. INSERT INTO x1 VALUES
  23. (1, 'hello world', 'today xyz'),
  24. (2, 'not the day', 'crunch crumble and chomp'),
  25. (3, 'one', 'two');
  26. INSERT INTO t1(t1) VALUES('rebuild');
  27. }
  28. do_execsql_test 1.1 {
  29. INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
  30. }
  31. do_execsql_test 1.2 {
  32. INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 4, 'nosuchtoken', '');
  33. }
  34. do_execsql_test 1.3 {
  35. INSERT INTO t1(t1) VALUES('integrity-check');
  36. }
  37. do_execsql_test 1.4 {
  38. INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 1, 'crunch', '');
  39. }
  40. do_execsql_test 1.5 {
  41. INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 3, 'crunch', '');
  42. }
  43. do_execsql_test 1.6 {
  44. INSERT INTO t1(t1) VALUES('integrity-check');
  45. }
  46. do_execsql_test 1.7 {
  47. CREATE VIRTUAL TABLE y1 USING fts5(xx, prefix='1,2');
  48. INSERT INTO y1(y1, rank) VALUES('pgsz', 64);
  49. INSERT INTO y1(y1, rank) VALUES('secure-delete', 1);
  50. }
  51. do_execsql_test 1.8 {
  52. BEGIN;
  53. INSERT INTO y1(rowid, xx) VALUES(1, 'abc def');
  54. INSERT INTO y1(rowid, xx) VALUES(2, 'reallyreallylongtoken');
  55. COMMIT;
  56. }
  57. do_execsql_test 1.9 {
  58. DELETE FROM y1 WHERE rowid=1;
  59. INSERT INTO y1(y1) VALUES('integrity-check');
  60. }
  61. do_execsql_test 1.10 {
  62. CREATE VIRTUAL TABLE w1 USING fts5(ww, content="");
  63. INSERT INTO w1(rowid, ww) VALUES(123, '');
  64. }
  65. do_catchsql_test 1.11 {
  66. INSERT INTO w1(w1, rowid, ww) VALUES('delete', 123, 'xyz');
  67. } {1 {database disk image is malformed}}
  68. do_catchsql_test 1.12 {
  69. DROP TABLE w1;
  70. CREATE VIRTUAL TABLE w1 USING fts5(ww, content="");
  71. INSERT INTO w1(rowid, ww) VALUES(123, '');
  72. DELETE FROM w1_data WHERE id>10;
  73. INSERT INTO w1(w1, rowid, ww) VALUES('delete', 123, 'xyz');
  74. } {1 {database disk image is malformed}}
  75. #-------------------------------------------------------------------------
  76. # Test using secure-delete with detail=none or detail=col.
  77. #
  78. foreach {tn d} {1 full 2 none 3 column} {
  79. reset_db
  80. do_execsql_test 2.$tn.1 "
  81. CREATE VIRTUAL TABLE x1 USING fts5(xx, yy, zz, detail=$d, prefix='10,20');
  82. INSERT INTO x1(x1, rank) VALUES('pgsz', 64);
  83. INSERT INTO x1(x1, rank) VALUES('secure-delete', 1);
  84. "
  85. do_execsql_test 2.$tn.2 {
  86. BEGIN;
  87. INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
  88. INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
  89. INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
  90. INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
  91. INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c');
  92. COMMIT;
  93. INSERT INTO x1(x1) VALUES('integrity-check');
  94. }
  95. do_execsql_test 2.$tn.3 {
  96. DELETE FROM x1 WHERE rowid IN (2, 4, 6);
  97. INSERT INTO x1(x1) VALUES('integrity-check');
  98. }
  99. do_execsql_test 2.$tn.4 {
  100. DELETE FROM x1 WHERE rowid IN (1, 3, 5);
  101. INSERT INTO x1(x1) VALUES('integrity-check');
  102. }
  103. do_execsql_test 2.$tn.5 {
  104. WITH s(i) AS (
  105. SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
  106. )
  107. INSERT INTO x1
  108. SELECT 'seems to be', 'used brew to', 'everything is working' FROM s
  109. UNION ALL
  110. SELECT 'used brew to', 'everything is working', 'seems to be' FROM s
  111. UNION ALL
  112. SELECT 'everything is working', 'seems to be', 'used brew to' FROM s
  113. UNION ALL
  114. SELECT 'abc', 'zzz', 'a b c d'
  115. UNION ALL
  116. SELECT 'z', 'z', 'z' FROM s
  117. }
  118. do_test 2.$tn.6 {
  119. for {set i 300} {$i > 200} {incr i -1} {
  120. execsql {
  121. DELETE FROM x1 WHERE rowid=$i;
  122. INSERT INTO x1(x1) VALUES('integrity-check');
  123. }
  124. }
  125. } {}
  126. do_test 2.$tn.7 {
  127. for {set i 1} {$i < 100} {incr i} {
  128. execsql {
  129. DELETE FROM x1 WHERE rowid=$i;
  130. INSERT INTO x1(x1) VALUES('integrity-check');
  131. }
  132. }
  133. } {}
  134. do_test 2.$tn.8 {
  135. foreach i [db eval {SELECT rowid FROM x1}] {
  136. execsql {
  137. DELETE FROM x1 WHERE rowid=$i;
  138. INSERT INTO x1(x1) VALUES('integrity-check');
  139. }
  140. }
  141. } {}
  142. do_execsql_test 2.$tn.9 {
  143. SELECT * FROM x1
  144. } {}
  145. }
  146. finish_test