summaryrefslogtreecommitdiffstats
path: root/ext/fts5/test/fts5secure5.test
blob: ca8570211cb62bc9730f59dfa150b04624c17abf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# 2023 April 14
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#*************************************************************************
#

source [file join [file dirname [info script]] fts5_common.tcl]
return_if_no_fts5
set ::testprefix fts5secure5
return_if_no_fts5

proc dump {} {
  execsql_pp {
    SELECT id, quote(block), fts5_decode_none(id, block) FROM ft1_data
  }
}

do_execsql_test 1.0 {
  CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
  INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
}

do_execsql_test 1.1 {
  BEGIN;
    INSERT INTO ft1(rowid, a) VALUES(1, 'abcd');
    INSERT INTO ft1(rowid, a) VALUES(2, 'abcd');
    INSERT INTO ft1(rowid, a) VALUES(3, 'abcd');
  COMMIT;
}
do_execsql_test 1.2 {
  DELETE FROM ft1 WHERE rowid=1;
}
do_execsql_test 1.3 {
  INSERT INTO ft1(ft1) VALUES('integrity-check');
}
do_execsql_test 1.4 {
  DELETE FROM ft1 WHERE rowid=3;
}
do_execsql_test 1.5 {
  INSERT INTO ft1(ft1) VALUES('integrity-check');
}
do_execsql_test 1.6 {
  DELETE FROM ft1 WHERE rowid=3;
}
do_execsql_test 1.7 {
  INSERT INTO ft1(ft1) VALUES('integrity-check');
}

#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
  CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
  INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
}

do_execsql_test 2.1 {
  BEGIN;
    INSERT INTO ft1(rowid, a) VALUES(1, 'abcd one');
    INSERT INTO ft1(rowid, a) VALUES(2, 'abcd two');
    INSERT INTO ft1(rowid, a) VALUES(3, 'abcd two');
    INSERT INTO ft1(rowid, a) VALUES(4, 'abcd two');
    INSERT INTO ft1(rowid, a) VALUES(5, 'abcd three');
  COMMIT;
}

do_execsql_test 2.2a {
  DELETE FROM ft1 WHERE rowid=3;
}
do_execsql_test 2.2b {
  INSERT INTO ft1(ft1) VALUES('integrity-check');
}
do_execsql_test 2.3a {
  DELETE FROM ft1 WHERE rowid=2;
}
do_execsql_test 2.3b {
  INSERT INTO ft1(ft1) VALUES('integrity-check');
}
do_execsql_test 2.4a {
  DELETE FROM ft1 WHERE rowid=4;
}
do_execsql_test 2.4b {
  INSERT INTO ft1(ft1) VALUES('integrity-check');
}

#-------------------------------------------------------------------------
reset_db
do_execsql_test 3.0 {
  CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none, prefix=1);
  INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
  INSERT INTO ft1(ft1, rank) VALUES('pgsz', 64);
}
do_execsql_test 3.1 {
  BEGIN;
    INSERT INTO ft1(a) VALUES('c');
  COMMIT;
}
do_execsql_test 3.2 {
  DELETE FROM ft1 WHERE rowid IN (1);
  INSERT INTO ft1(ft1) VALUES('integrity-check');
}

#-------------------------------------------------------------------------
reset_db
do_execsql_test 4.0 {
  CREATE VIRTUAL TABLE ft1 USING fts5(a, detail=none);
  INSERT INTO ft1(ft1, rank) VALUES('secure-delete', 1);
  INSERT INTO ft1(ft1, rank) VALUES('pgsz', 64);

  WITH s(i) AS (
    SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<500
  )
  INSERT INTO ft1 SELECT 'abcdefg' FROM s;
}

do_test 4.1 {
  for {set i 500} {$i > 0} {incr i -1} {
    execsql { DELETE FROM ft1 WHERE rowid=$i }
    execsql { INSERT INTO ft1(ft1) VALUES('integrity-check') }
  }
} {}

finish_test