blob: 9badc560d4e0cbd42498553fe5ce26f499189f93 [file] [log] [blame]
dan2aba5d92012-08-07 17:41:50 +00001# 2012 August 7
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# Tests for the secure_delete pragma.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set ::testprefix securedel2
18
19# Generate 1000 pseudo-random 64-bit blobs.
20#
21for {set i 1} {$i <= 1000} {incr i} {
22 set aBlob($i) [string range [db one {SELECT quote(randomblob(8))}] 2 end-1]
23}
24
25proc detect_blob_prepare {zFile} {
26 set nByte [file size $zFile]
27 set ::detect_blob_data [hexio_read $zFile 0 $nByte]
28}
29
30proc detect_blob {zFile iBlob} {
31 if {$zFile != ""} { detect_blob_prepare $zFile }
32 string match "*$::aBlob($iBlob)*" $::detect_blob_data
33}
34
35do_test 1.1 {
36 execsql { PRAGMA secure_delete = 1 }
danacf239b2012-08-08 10:14:10 +000037 execsql { PRAGMA auto_vacuum = 0 }
dan2aba5d92012-08-07 17:41:50 +000038 execsql { CREATE TABLE t1(x, y) }
39 for {set i 1} {$i <= 1000} {incr i} {
40 set x "X'[string repeat $aBlob($i) 1]'"
41 set y "X'[string repeat $aBlob($i) 500]'"
42 execsql "INSERT INTO t1 VALUES($x, $y)"
43 }
44} {}
45
46do_test 1.2 { detect_blob test.db 1 } {1}
47
48forcecopy test.db test.db.bak
49do_execsql_test 1.3.1 { PRAGMA secure_delete = 0 } {0}
50do_execsql_test 1.3.2 { DELETE FROM t1 WHERE rowid = 1 }
51do_test 1.3.3 { detect_blob test.db 1 } {1}
52
53db close
54forcecopy test.db.bak test.db
55sqlite3 db test.db
56do_execsql_test 1.4.1 { PRAGMA secure_delete = 1 } {1}
57do_execsql_test 1.4.2 { DELETE FROM t1 WHERE rowid = 1 }
58do_test 1.4.3 { detect_blob test.db 1 } {0}
59
60do_execsql_test 1.5.1 { DELETE FROM t1 WHERE rowid>850 } {}
61do_test 1.5.2 {
62 set n 0
63 detect_blob_prepare test.db
64 for {set i 851} {$i <= 1000} {incr i 5} {
65 incr n [detect_blob {} $i]
66 }
67 set n
68} {0}
69
70db close
71sqlite3 db test.db
72do_test 1.6.1 {
73 execsql {
74 PRAGMA cache_size = 200;
75 PRAGMA secure_delete = 1;
76 CREATE TABLE t2(x);
77 SELECT * FROM t1;
78 }
79 for {set i 100} {$i < 5000} {incr i} {
80 execsql { INSERT INTO t2 VALUES(randomblob($i)) }
81 }
82 execsql { DELETE FROM t1 }
83} {}
84
85do_test 1.6.2 {
86 set n 0
87 detect_blob_prepare test.db
88 for {set i 2} {$i <= 850} {incr i 5} {
89 incr n [detect_blob {} $i]
90 }
91 set n
92} {0}
93
94finish_test