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 # The database is initially empty.
42 # set an hex key create some basic data
43 # create table and insert operations should work
44 # close database, open it again with the same
45 # hex key. verify that the table is readable
46 # and the data just inserted is visible
47 setup test.db "\"x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836481'\""
48 do_test will-open-with-correct-raw-key {
49 sqlite_orig db test.db
51 PRAGMA key = "x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836481'";
52 SELECT name FROM sqlite_schema WHERE type='table';
57 file delete -force test.db
59 # set an encryption key (non-hex) and create some basic data
60 # create table and insert operations should work
61 # close database, open it again with the same
62 # key. verify that the table is readable
63 # and the data just inserted is visible
64 setup test.db "'testkey'"
65 do_test will-open-with-correct-derived-key {
67 sqlite_orig db test.db
69 PRAGMA key = 'testkey';
70 SELECT name FROM sqlite_schema WHERE type='table';
75 file delete -force test.db
77 # set an encryption key (non-hex) and create
78 # temp tables, verify you can read from
80 setup test.db "'testkey'"
81 do_test test-temp-master {
82 sqlite_orig db test.db
84 PRAGMA key = 'testkey';
85 CREATE TEMPORARY TABLE temp_t1(a,b);
86 INSERT INTO temp_t1(a,b) VALUES ('test1', 'test2');
87 SELECT name FROM sqlite_temp_master WHERE type='table';
88 SELECT * from temp_t1;
90 } {ok temp_t1 test1 test2}
92 file delete -force test.db
94 # verify that a when a standard database is encrypted the first
95 # 16 bytes are not "SQLite format 3\0"
96 do_test test-sqlcipher-header-overwrite {
97 sqlite_orig db test.db
100 CREATE TABLE t1(a,b);
103 set header [hexio_read test.db 0 16]
104 string equal $header "53514C69746520666F726D6174203300"
106 file delete -force test.db
108 # open the database and try to read from it without
109 # providing a passphrase. verify that the
110 # an error is returned from the library
111 setup test.db "'testkey'"
112 do_test wont-open-without-key {
113 sqlite_orig db test.db
115 SELECT name FROM sqlite_schema WHERE type='table';
117 } {1 {file is not a database}}
119 file delete -force test.db
121 # open the database and try to set an invalid
122 # passphrase. verify that an error is returned
123 # and that data couldn't be read
124 setup test.db "'testkey'"
125 do_test wont-open-with-invalid-derived-key {
126 sqlite_orig db test.db
128 PRAGMA key = 'testkey2';
129 SELECT name FROM sqlite_schema WHERE type='table';
131 } {1 {file is not a database}}
133 file delete -force test.db
135 # open the database and try to set an invalid
136 # hex key. verify that an error is returned
137 # and that data couldn't be read
138 setup test.db "'testkey'"
139 do_test wont-open-with-invalid-raw-key {
140 sqlite_orig db test.db
142 PRAGMA key = "x'98483C6EB40B6C31A448C22A66DED3B5E5E8D5119CAC8327B655C8B5C4836480'";
143 SELECT name FROM sqlite_schema WHERE type='table';
145 } {1 {file is not a database}}
147 file delete -force test.db
149 # test a large number of inserts in a transaction to a memory database
150 do_test memory-database {
151 sqlite_orig db :memory:
153 PRAGMA key = 'testkey3';
155 CREATE TABLE t2(a,b);
157 for {set i 1} {$i<=25000} {incr i} {
158 set r [expr {int(rand()*500000)}]
159 execsql "INSERT INTO t2 VALUES($i,$r);"
163 SELECT count(*) FROM t2;
165 SELECT count(*) FROM t2;
170 # test a large number of inserts in a transaction for multiple pages
171 do_test multi-page-database {
172 sqlite_orig db test.db
174 PRAGMA key = 'testkey';
175 CREATE TABLE t2(a,b);
178 for {set i 1} {$i<=25000} {incr i} {
179 set r [expr {int(rand()*500000)}]
180 execsql "INSERT INTO t2 VALUES($i,$r);"
184 SELECT count(*) FROM t2;
188 file delete -force test.db
190 # attach an encrypted database
191 # without specifying key, verify it fails
192 # even if the source passwords are the same
193 # because the kdf salts are different
194 setup test.db "'testkey'"
195 do_test attach-database-with-default-key {
196 sqlite_orig db2 test2.db
200 PRAGMA key = 'testkey';
201 PRAGMA cipher_add_random = "x'deadbaad'";
202 CREATE TABLE t2(a,b);
203 INSERT INTO t2 VALUES ('test1', 'test2');
206 lappend rc [catchsql {
207 ATTACH 'test.db' AS db;
210 lappend rc [string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]]
212 } {{1 {file is not a database}} 0}
214 file delete -force test.db
215 file delete -force test2.db
217 # attach an empty encrypted database
218 # without specifying key, verify the database has the same
219 # salt and as the original
220 setup test.db "'testkey'"
221 do_test attach-empty-database-with-default-key {
222 sqlite_orig db test.db
226 PRAGMA key='testkey';
227 INSERT INTO t1(a,b) values (1,2);
228 ATTACH DATABASE 'test2.db' AS test;
229 CREATE TABLE test.t1(a,b);
230 INSERT INTO test.t1 SELECT * FROM t1;
231 DETACH DATABASE test;
234 sqlite_orig db2 test2.db
236 lappend rc [execsql {
237 PRAGMA key='testkey';
238 SELECT count(*) FROM t1;
240 lappend rc [string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]]
244 file delete -force test.db
245 file delete -force test2.db
247 # attach an empty encrypted database as the first operation on a keyed database. Verify
248 # that the new database has the same salt as the original.
250 # HISTORICAL NOTE: The original behavior of SQLCipher under these conditions
251 # was that the databases would have different salts but the same keys. This was because
252 # derivation of the key spec would not have occurred yet. However, upstream check-in
253 # https://sqlite.org/src/info/a02da71f3a80dd8e changed this behavior by
254 # forcing a read of the main database schema during the attach operation.
255 # This causes the main database to be opened and the key derivation logic to fire which
256 # reads the salt. Thus the current behavior of this test should now be identical
257 # to the previous attach-empty-database-with-default-key.
259 setup test.db "'testkey'"
260 do_test attach-empty-database-with-default-key-first-op {
261 sqlite_orig db test.db
265 PRAGMA key='testkey';
266 ATTACH DATABASE 'test2.db' AS test;
267 CREATE TABLE test.t1(a,b);
268 INSERT INTO test.t1 SELECT * FROM t1;
269 DETACH DATABASE test;
272 sqlite_orig db2 test2.db
274 lappend rc [execsql {
275 PRAGMA key='testkey';
276 SELECT count(*) FROM t1;
279 lappend rc [string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]]
283 file delete -force test.db
284 file delete -force test2.db
286 # attach an empty encrypted database
287 # on a keyed database when PRAGMA cipher_store_pass = 1
288 # and verify different salts
289 setup test.db "'testkey'"
290 do_test attach-empty-database-with-cipher-store-pass {
291 sqlite_orig db test.db
295 PRAGMA key='testkey';
296 PRAGMA cipher_store_pass = 1;
297 INSERT INTO t1(a,b) VALUES (1,2);
298 ATTACH DATABASE 'test2.db' AS test;
299 CREATE TABLE test.t1(a,b);
300 INSERT INTO test.t1 SELECT * FROM t1;
301 DETACH DATABASE test;
304 sqlite_orig db2 test2.db
306 lappend rc [execsql {
307 PRAGMA key='testkey';
308 SELECT count(*) FROM t1;
310 lappend rc [string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]]
314 file delete -force test.db
315 file delete -force test2.db
317 # attach an encrypted database
318 # without specifying key, verify it attaches
319 # correctly when PRAGMA cipher_store_pass = 1
321 do_test attach-database-with-default-key-using-cipher-store-pass {
322 sqlite_orig db1 test.db
324 PRAGMA key = 'testkey';
325 CREATE TABLE t1(a,b);
326 INSERT INTO t1(a,b) VALUES('foo', 'bar');
330 sqlite_orig db2 test2.db
332 PRAGMA key = 'testkey';
333 CREATE TABLE t2(a,b);
334 INSERT INTO t2 VALUES ('test1', 'test2');
338 sqlite_orig db1 test.db
340 PRAGMA key = 'testkey';
341 PRAGMA cipher_store_pass = 1;
342 ATTACH DATABASE 'test2.db' as db2;
343 SELECT sqlcipher_export('db2');
348 sqlite_orig db2 test2.db
350 PRAGMA key = 'testkey';
356 file delete -force test.db
357 file delete -force test2.db
359 # attach an encrypted database
360 # where both database have the same
361 # key explicitly and verify they have different
363 setup test.db "'testkey'"
364 do_test attach-database-with-same-key {
365 sqlite_orig db2 test2.db
370 PRAGMA key = 'testkey';
371 CREATE TABLE t2(a,b);
372 INSERT INTO t2 VALUES ('test1', 'test2');
375 lappend rc [execsql {
376 SELECT count(*) FROM t2;
377 ATTACH 'test.db' AS db KEY 'testkey';
378 SELECT count(*) FROM db.t1;
381 lappend rc [string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]]
384 file delete -force test.db
385 file delete -force test2.db
387 # attach an encrypted database
388 # where databases have different keys
389 setup test.db "'testkey'"
390 do_test attach-database-with-different-keys {
391 sqlite_orig db2 test2.db
394 PRAGMA key = 'testkey2';
395 CREATE TABLE t2(a,b);
396 INSERT INTO t2 VALUES ('test1', 'test2');
400 ATTACH 'test.db' AS db KEY 'testkey';
401 SELECT count(*) FROM db.t1;
402 SELECT count(*) FROM t2;
407 file delete -force test.db
408 file delete -force test2.db
410 # test locking across multiple handles
411 setup test.db "'testkey'"
412 do_test locking-across-multiple-handles-start {
413 sqlite_orig db test.db
416 PRAGMA key = 'testkey';
418 INSERT INTO t1 VALUES(1,2);
421 sqlite_orig dba test.db
423 PRAGMA key = 'testkey';
424 SELECT count(*) FROM t1;
427 } {1 {database is locked}}
429 do_test locking-accross-multiple-handles-finish {
435 SELECT count(*) FROM t1;
440 file delete -force test.db
443 setup test.db "'testkey'"
444 do_test alter-schema {
445 sqlite_orig db test.db
447 PRAGMA key = 'testkey';
448 ALTER TABLE t1 ADD COLUMN c;
449 INSERT INTO t1 VALUES (1,2,3);
450 INSERT INTO t1 VALUES (1,2,4);
451 CREATE TABLE t1a (a);
452 INSERT INTO t1a VALUES ('teststring');
456 sqlite_orig db test.db
458 PRAGMA key = 'testkey';
459 SELECT count(*) FROM t1 WHERE a IS NOT NULL;
460 SELECT count(*) FROM t1 WHERE c IS NOT NULL;
464 } {ok 3 2 teststring}
466 file delete -force test.db
468 # test alterations of KDF iterations and ciphers
470 setup test.db "'testkey'"
471 do_test verify-errors-for-rekey-kdf-and-cipher-changes {
472 sqlite_orig db test.db
474 PRAGMA key = 'testkey';
475 PRAGMA rekey_kdf_iter = 1000;
476 PRAGMA rekey_cipher = 'aes-256-ecb';
478 } {ok {PRAGMA rekey_kdf_iter is no longer supported.} {PRAGMA rekey_cipher is no longer supported.}}
480 file delete -force test.db
483 setup test.db "'testkey'"
484 do_test verify-errors-for-cipher-change {
485 sqlite_orig db test.db
487 PRAGMA key = 'testkey';
488 PRAGMA cipher = 'aes-256-ecb';
490 } {ok {PRAGMA cipher is no longer supported.}}
492 file delete -force test.db
495 # 1. create a database with a custom page size,
496 # 2. create table and insert operations should work
497 # 3. close database, open it again with the same
499 # 4. verify that the table is readable
500 # and the data just inserted is visible
501 do_test custom-pagesize-pragma-cipher-page-size {
502 sqlite_orig db test.db
505 PRAGMA key = 'testkey';
506 PRAGMA cipher_page_size = 8192;
507 CREATE table t1(a,b);
511 for {set i 1} {$i<=1000} {incr i} {
512 set r [expr {int(rand()*500000)}]
513 execsql "INSERT INTO t1 VALUES($i,'value $r');"
521 sqlite_orig db test.db
524 PRAGMA key = 'testkey';
525 PRAGMA cipher_page_size = 8192;
526 SELECT count(*) FROM t1;
531 file delete -force test.db
533 # run the same logic as previous test but use
534 # pragma page_size instead
535 do_test custom-pagesize-pragma-pagesize {
536 sqlite_orig db test.db
539 PRAGMA key = 'testkey';
540 PRAGMA page_size = 8192;
541 CREATE table t1(a,b);
545 for {set i 1} {$i<=1000} {incr i} {
546 set r [expr {int(rand()*500000)}]
547 execsql "INSERT INTO t1 VALUES($i,'value $r');"
555 sqlite_orig db test.db
558 PRAGMA key = 'testkey';
559 PRAGMA page_size = 8192;
560 SELECT count(*) FROM t1;
565 file delete -force test.db
567 # open the database with the default page size
568 ## and verfiy that it is not readable
569 do_test custom-pagesize-must-match {
570 sqlite_orig db test.db
572 PRAGMA key = 'testkey';
573 PRAGMA cipher_page_size = 8192;
574 CREATE table t1(a,b);
578 sqlite_orig db test.db
581 PRAGMA key = 'testkey';
582 SELECT name FROM sqlite_schema WHERE type='table';
584 } {1 {file is not a database}}
586 file delete -force test.db
589 # 1. create a database with WAL journal mode
590 # 2. create table and insert operations should work
591 # 3. close database, open it again
592 # 4. verify that the table is present, readable, and that
593 # the journal mode is WAL
594 do_test journal-mode-wal {
595 sqlite_orig db test.db
598 PRAGMA key = 'testkey';
599 PRAGMA journal_mode = WAL;
600 CREATE table t1(a,b);
604 for {set i 1} {$i<=1000} {incr i} {
605 set r [expr {int(rand()*500000)}]
606 execsql "INSERT INTO t1 VALUES($i,'value $r');"
614 sqlite_orig db test.db
617 PRAGMA key = 'testkey';
618 SELECT count(*) FROM t1;
624 file delete -force test.db
626 # open a database and try to use an invalid
627 # passphrase. verify that an error is returned
628 # and that data couldn't be read. without closing the databsae
629 # set the correct key and verify it is working.
630 setup test.db "'testkey'"
631 do_test multiple-key-calls-safe-wrong-key-first {
632 sqlite_orig db test.db
635 lappend rc [catchsql {
636 PRAGMA key = 'testkey2';
637 SELECT count(*) FROM sqlite_schema;
640 lappend rc [execsql {
641 PRAGMA key = 'testkey';
642 SELECT count(*) FROM sqlite_schema;
644 } {{1 {file is not a database}} {ok 1}}
646 file delete -force test.db
648 # open a databse and use the valid key. Then
649 # use pragma key to try to set an invalid key
650 # without closing the database. It should not do anything
652 setup test.db "'testkey'"
653 do_test multiple-key-calls-safe {
654 sqlite_orig db test.db
656 PRAGMA key = 'testkey';
657 PRAGMA cache_size = 0;
658 SELECT name FROM sqlite_schema WHERE type='table';
659 PRAGMA key = 'wrong key';
660 SELECT name FROM sqlite_schema WHERE type='table';
661 PRAGMA key = 'testkey';
662 SELECT name FROM sqlite_schema WHERE type='table';
664 } {ok t1 ok t1 ok t1}
667 file delete -force test.db
669 # 1. create a database with a custom hmac kdf iteration count,
670 # 2. create table and insert operations should work
671 # 3. close database, open it again with the same
672 # key and hmac kdf iteration count
673 # 4. verify that the table is readable
674 # and the data just inserted is visible
675 do_test custom-hmac-kdf-iter {
676 sqlite_orig db test.db
679 PRAGMA key = 'testkey';
680 PRAGMA kdf_iter = 10;
681 CREATE table t1(a,b);
685 for {set i 1} {$i<=1000} {incr i} {
686 set r [expr {int(rand()*500000)}]
687 execsql "INSERT INTO t1 VALUES($i,'value $r');"
695 sqlite_orig db test.db
698 PRAGMA key = 'testkey';
699 PRAGMA kdf_iter = 10;
700 SELECT count(*) FROM t1;
706 # open the database with the default hmac
707 # kdf iteration count
708 # to verify that it is not readable
709 do_test custom-hmac-kdf-iter-must-match {
710 sqlite_orig db test.db
712 PRAGMA key = 'testkey';
713 SELECT name FROM sqlite_schema WHERE type='table';
715 } {1 {file is not a database}}
717 file delete -force test.db
719 # open the database and turn on auto_vacuum
720 # then insert a bunch of data, delete it
721 # and verify that the file has become smaller
722 # but can still be opened with the proper
724 do_test auto-vacuum {
725 sqlite_orig db test.db
729 PRAGMA key = 'testkey';
730 PRAGMA auto_vacuum=FULL;
731 CREATE table t1(a,b);
735 for {set i 1} {$i<=10000} {incr i} {
736 set r [expr {int(rand()*500000)}]
737 execsql "INSERT INTO t1 VALUES($i,'value $r');"
740 lappend rc [execsql {
742 SELECT count(*) FROM t1;
745 # grab current size of file
746 set sz [file size test.db]
748 # delete some records, and verify
749 # autovacuum removes them
751 DELETE FROM t1 WHERE rowid > 5000;
756 # grab new file size, post
758 set sz2 [file size test.db]
760 # verify that the new size is
761 # smaller than the old size
762 if {$sz > $sz2} { lappend rc true }
764 sqlite_orig db test.db
766 lappend rc [execsql {
767 PRAGMA key = 'testkey';
768 SELECT count(*) FROM t1;
771 } {10000 true {ok 5000}}
773 file delete -force test.db
775 # test kdf_iter and other pragmas
776 # before a key is set. Verify that they
778 do_test cipher-options-before-keys {
779 sqlite_orig db test.db
782 PRAGMA kdf_iter = 1000;
783 PRAGMA cipher_page_size = 8192;
784 PRAGMA cipher_use_hmac = OFF;
785 PRAGMA key = 'testkey';
786 CREATE table t1(a,b);
787 INSERT INTO t1 VALUES(1,2);
791 sqlite_orig db test.db
794 PRAGMA key = 'testkey';
795 SELECT count(*) FROM t1;
800 file delete -force test.db
802 # verify memory security behavior
803 # initially should report OFF
804 # then enable, check that it is ON
805 # try to turn if off, but verify that it
807 do_test verify-memory-security {
808 sqlite_orig db test.db
810 PRAGMA cipher_memory_security;
811 PRAGMA cipher_memory_security = ON;
812 PRAGMA cipher_memory_security;
813 PRAGMA cipher_memory_security = OFF;
814 PRAGMA cipher_memory_security;
818 file delete -force test.db
820 # create two new database files, write to each
821 # and verify that they have different (i.e. random)
823 do_test test-random-salt {
824 sqlite_orig db test.db
825 sqlite_orig db2 test2.db
828 CREATE TABLE t1(a,b);
829 INSERT INTO t1(a,b) VALUES (1,2);
833 CREATE TABLE t1(a,b);
834 INSERT INTO t1(a,b) VALUES (1,2);
838 string equal [hexio_read test.db 0 16] [hexio_read test2.db 0 16]
840 file delete -force test.db
841 file delete -force test2.db
843 # test scenario where multiple handles are opened
844 # to a file that does not exist, where both handles
846 do_test multiple-handles-same-key-and-salt {
847 sqlite_orig db test.db
848 sqlite_orig dba test.db
851 PRAGMA key = 'testkey';
854 PRAGMA key = 'testkey';
858 CREATE TABLE t1(a,b);
859 INSERT INTO t1 VALUES(1,2);
863 SELECT count(*) FROM t1;
866 SELECT count(*) FROM t1;
872 file delete -force test.db
874 do_test test_flags_fail_encrypt {
875 sqlite_orig db :memory:
878 PRAGMA cipher_test_on = fail_encrypt;
880 PRAGMA cipher_test_off = fail_encrypt;
886 do_test test_flags_fail_decrypt {
887 sqlite_orig db :memory:
890 PRAGMA cipher_test_on = fail_decrypt;
892 PRAGMA cipher_test_off = fail_decrypt;
898 do_test test_flags_fail_migrate {
899 sqlite_orig db :memory:
902 PRAGMA cipher_test_on = fail_migrate;
904 PRAGMA cipher_test_off = fail_migrate;
910 do_test test_flags_combo {
911 sqlite_orig db :memory:
914 PRAGMA cipher_test_on = fail_encrypt;
915 PRAGMA cipher_test_on = fail_migrate;
917 PRAGMA cipher_test_off = fail_encrypt;
918 PRAGMA cipher_test_off = fail_migrate;
925 # it should raise an error
927 sqlite_orig db test.db
933 } {1 {An error occurred with PRAGMA key or rekey. PRAGMA key requires a key of one or more characters. PRAGMA rekey can only be run on an existing encrypted database. Use sqlcipher_export() and ATTACH to convert encrypted/plaintext databases.}}
935 file delete -force test.db
937 # configure URI filename support
938 # create a new encrypted database with the key via parameter
940 # open normally providing key via pragma verify
945 sqlite_orig db file:test.db?a=a&key=testkey&c=c
948 CREATE TABLE t1(a,b);
949 INSERT INTO t1 VALUES(1,2);
953 sqlite_orig db test.db
956 PRAGMA key = 'testkey';
957 SELECT count(*) FROM t1;
961 sqlite_orig db test.db
964 PRAGMA key = 'testkey';
965 SELECT count(*) FROM t1;
971 # verify wrong key fails
973 sqlite_orig db test.db
976 SELECT count(*) FROM t1;
978 } {1 {file is not a database}}
980 file delete -force test.db