2 # codec.test developed by Stephen Lombardo (Zetetic LLC)
3 # sjlombardo at zetetic dot net
6 # Copyright (c) 2018, ZETETIC LLC
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the ZETETIC LLC nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
18 # THIS SOFTWARE IS PROVIDED BY ZETETIC LLC ''AS IS'' AND ANY
19 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 # DISCLAIMED. IN NO EVENT SHALL ZETETIC LLC BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # This file implements regression tests for SQLite library. The
30 # focus of this script is testing code cipher features.
32 # NOTE: tester.tcl has overridden the definition of sqlite3 to
33 # automatically pass in a key value. Thus tests in this file
34 # should explicitly close and open db with sqlite_orig in order
35 # to bypass default key assignment.
37 set testdir [file dirname $argv0]
38 source $testdir/tester.tcl
39 source $testdir/sqlcipher.tcl
41 proc codec-test-setup {} {
42 sqlite_orig db test.db
45 PRAGMA key = 'testkey';
46 CREATE table t1(a INTEGER PRIMARY KEY,b);
50 for {set i 1} {$i<=10000} {incr i} {
51 execsql "INSERT INTO t1(a,b) VALUES($i,'value $i');"
62 do_test codec-error-journal-delete {
65 sqlite_orig db test.db
68 PRAGMA key = 'testkey';
69 PRAGMA cipher_test_on = fail_encrypt;
70 UPDATE t1 SET b = 'fail' WHERE a = 5000;
74 sqlite_orig db test.db
77 PRAGMA cipher_test_off = fail_encrypt;
78 PRAGMA key = 'testkey';
79 PRAGMA cipher_integrity_check;
80 PRAGMA integrity_check;
81 SELECT b FROM t1 where a = 5000;
84 } {ok ok {value 5000}}
86 file delete -force test.db
88 do_test codec-error-journal-wal {
91 sqlite_orig db test.db
94 PRAGMA key = 'testkey';
95 PRAGMA cipher_test_on = fail_encrypt;
96 UPDATE t1 SET b = 'fail' WHERE a = 5000;
100 sqlite_orig db test.db
103 PRAGMA cipher_test_off = fail_encrypt;
104 PRAGMA key = 'testkey';
105 PRAGMA cipher_integrity_check;
106 PRAGMA integrity_check;
107 SELECT b FROM t1 where a = 5000;
110 } {ok ok {value 5000}}
112 file delete -force test.db
114 do_test codec-error-journal-wal-transaction {
117 sqlite_orig db test.db
120 PRAGMA key = 'testkey';
122 UPDATE t1 SET b = 'success' WHERE a = 1;
123 PRAGMA cipher_test_on = fail_encrypt;
124 UPDATE t1 SET b = 'fail' WHERE a = 5000;
129 sqlite_orig db test.db
132 PRAGMA cipher_test_off = fail_encrypt;
133 PRAGMA key = 'testkey';
134 PRAGMA cipher_integrity_check;
135 PRAGMA integrity_check;
136 SELECT b FROM t1 where a = 1;
137 SELECT b FROM t1 where a = 5000;
140 } {ok ok {value 1} {value 5000}}
142 file delete -force test.db
144 do_test codec-error-journal-wal-read {
147 sqlite_orig db test.db
150 PRAGMA key = 'testkey';
151 SELECT count(*) FROM sqlite_schema;
152 PRAGMA cipher_test_on = fail_decrypt;
153 UPDATE t1 SET b = 'fail' WHERE a = 5000;
157 sqlite_orig db test.db
160 PRAGMA cipher_test_off = fail_decrypt;
161 PRAGMA key = 'testkey';
162 PRAGMA cipher_integrity_check;
163 PRAGMA integrity_check;
164 SELECT b FROM t1 where a = 5000;
167 } {ok ok {value 5000}}
169 file delete -force test.db