Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/fts5/test/fts5secure8.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `sqlite / ext / fts5 / test / fts5secure8.test` 173 lines ยท 4336 bytes Raw Blame History 1 # 2023 Nov 23 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 13 source [file join [file dirname [info script]] fts5_common.tcl] 14 ifcapable !fts5 { finish_test ; return } 15 set ::testprefix fts5secure8 16 17 proc sql_repeat {txt n} { 18 string repeat $txt $n 19 } 20 db func repeat sql_repeat 21 22 do_execsql_test 1.0 { 23 CREATE VIRTUAL TABLE ft USING fts5(x); 24 25 INSERT INTO ft(ft, rank) VALUES('pgsz', 64); 26 27 INSERT INTO ft(rowid, x) VALUES(100, 'hello world'); 28 INSERT INTO ft(rowid, x) VALUES(200, 'one day'); 29 30 BEGIN; 31 INSERT INTO ft(rowid, x) VALUES(45, 'one two three'); 32 UPDATE ft SET x = repeat('hello world ', 500) WHERE rowid=100; 33 COMMIT 34 } 35 36 do_execsql_test 1.1 { 37 INSERT INTO ft(ft, rank) VALUES('secure-delete', 1); 38 DELETE FROM ft WHERE rowid=100; 39 } 40 41 do_execsql_test 1.2 { 42 PRAGMA integrity_check; 43 } {ok} 44 45 do_execsql_test 2.0 { 46 CREATE VIRTUAL TABLE xyz USING fts5 ( 47 name, 48 content='' 49 ); 50 51 INSERT INTO xyz(xyz, rank) VALUES('secure-delete', 1); 52 INSERT INTO xyz (rowid, name) VALUES(1, 'A'); 53 INSERT INTO xyz (rowid, name) VALUES(2, 'A'); 54 INSERT INTO xyz(xyz, rowid, name) VALUES('delete', 2, 'A'); 55 } 56 57 do_execsql_test 2.1 { 58 pragma quick_check; 59 } {ok} 60 61 do_catchsql_test 2.2 { 62 INSERT INTO xyz(xyz, rank) VALUES('secure-delete', 'hello world'); 63 } {1 {SQL logic error}} 64 65 #------------------------------------------------------------------------- 66 # 67 reset_db 68 do_execsql_test 3.0 { 69 CREATE VIRTUAL TABLE t1 USING fts5(c, detail='none'); 70 INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); 71 INSERT INTO t1(rowid, c) VALUES(1, 'a'); 72 } 73 74 do_execsql_test 3.1 { 75 BEGIN; 76 DELETE FROM t1 WHERE rowid = 1; 77 INSERT INTO t1(rowid, c) VALUES(1, 'a'); 78 } 79 80 do_execsql_test 3.2 { 81 INSERT INTO t1(rowid, c) VALUES(2, 'a'); 82 COMMIT; 83 } 84 85 do_execsql_test 3.3 { 86 SELECT rowid FROM t1 ORDER BY rowid; 87 } {1 2} 88 89 # Expected {1 2}. Observed {1}. 90 do_execsql_test 3.4 { 91 SELECT rowid FROM t1 WHERE t1 MATCH 'a' ORDER BY rowid; 92 } {1 2} 93 94 # Expected {ok}. Observed: SQLITE_CORRUPT_VTAB, "checksum mismatch". 95 do_execsql_test 3.5 { 96 INSERT INTO t1(t1) VALUES('integrity-check'); 97 } {} 98 99 # control: the same script without secure-delete is correct 100 do_execsql_test 3.6 { 101 CREATE VIRTUAL TABLE t1b USING fts5(c, detail='none'); 102 INSERT INTO t1b(rowid, c) VALUES(1, 'a'); 103 INSERT OR REPLACE INTO t1b(rowid, c) VALUES(1, 'a'), (2, 'a'); 104 SELECT rowid FROM t1b WHERE t1b MATCH 'a' ORDER BY rowid; 105 } {1 2} 106 107 # control: the same script with detail=full is correct 108 do_execsql_test 3.7 { 109 CREATE VIRTUAL TABLE t1c USING fts5(c, detail='full'); 110 INSERT INTO t1c(t1c, rank) VALUES('secure-delete', 1); 111 INSERT INTO t1c(rowid, c) VALUES(1, 'a'); 112 INSERT OR REPLACE INTO t1c(rowid, c) VALUES(1, 'a'), (2, 'a'); 113 SELECT rowid FROM t1c WHERE t1c MATCH 'a' ORDER BY rowid; 114 } {1 2} 115 116 #------------------------------------------------------------------------- 117 118 foreach {tn bSecure} { 119 0 0 120 1 1 121 } { 122 reset_db 123 do_execsql_test 4.$tn.0 { 124 CREATE VIRTUAL TABLE f USING fts5(x); 125 INSERT INTO f(f, rank) VALUES('pgsz', 32); 126 } 127 if {$bSecure} { 128 execsql { INSERT INTO f(f, rank) VALUES('secure-delete', 1) } 129 } 130 131 do_execsql_test 4.$tn.1 { 132 WITH s(i) AS ( 133 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<6 134 ) 135 INSERT INTO f(rowid, x) 136 SELECT i, trim ( 137 replace(printf('%.40c', '.'), '.', iif(i<=4, 'cd ', 'zz ')) 138 ) FROM s; 139 } 140 141 # execsql_pp { SELECT fts5_decode(id, block) FROM f_data } 142 do_execsql_test 4.$tn.2 { 143 DELETE FROM f WHERE rowid = 4; 144 } 145 # execsql_pp { SELECT fts5_decode(id, block) FROM f_data } 146 147 do_execsql_test 4.$tn.3 { 148 SELECT rowid FROM f('cd') 149 } {1 2 3} 150 do_execsql_test 4.$tn.4 { 151 SELECT rowid FROM f('zz') 152 } {5 6} 153 154 do_execsql_test 4.$tn.5 { 155 SELECT rowid FROM f WHERE f MATCH 'cd' AND rowid>=5 156 } 157 do_execsql_test 4.$tn.6 { 158 SELECT rowid FROM f('zz AND cd'); 159 } 160 do_execsql_test 4.$tn.7 { 161 SELECT rowid FROM f('zz NOT cd'); 162 } {5 6} 163 do_execsql_test 4.$tn.8 { 164 SELECT rowid FROM f('zz NOT cd') ORDER BY rowid DESC; 165 } {6 5} 166 167 } 168 169 170 171 finish_test 172 173