@@ -381,9 +381,30 @@ do_test rekey-delete-and-query-wal-3 {
381381db close
382382file delete -force test.db
383383
384+ # attach an encrypted database
385+ # without specifying key, verify it fails
386+ setup test.db "'testkey'"
387+ do_test attach-database-with-default-key {
388+ sqlite_orig db2 test2.db
389+
390+ execsql {
391+ PRAGMA key = 'testkey';
392+ CREATE TABLE t2(a,b);
393+ INSERT INTO t2 VALUES ('test1', 'test2');
394+ } db2
395+
396+ catchsql {
397+ ATTACH 'test.db' AS db;
398+ } db2
399+
400+ } {1 {unable to open database: test.db}}
401+ db2 close
402+ file delete -force test.db
403+ file delete -force test2.db
404+
384405# attach an encrypted database
385406# where both database have the same
386- # key
407+ # key explicitly
387408setup test.db "'testkey'"
388409do_test attach-database-with-same-key {
389410 sqlite_orig db2 test2.db
@@ -396,7 +417,7 @@ do_test attach-database-with-same-key {
396417
397418 execsql {
398419 SELECT count(*) FROM t2;
399- ATTACH 'test.db' AS db;
420+ ATTACH 'test.db' AS db KEY 'testkey' ;
400421 SELECT count(*) FROM db.t1;
401422 } db2
402423
@@ -581,7 +602,7 @@ file delete -force test.db
581602
582603# create an unencrypted database, attach a new encrypted volume
583604# copy data between, verify the encypted database is good afterwards
584- do_test unencryped -attach {
605+ do_test unencrypted -attach {
585606 sqlite_orig db test.db
586607
587608 execsql {
@@ -1335,7 +1356,7 @@ do_test default-use-hmac-attach {
13351356 PRAGMA cipher_default_use_hmac = OFF;
13361357 PRAGMA key = 'testkey';
13371358 SELECT count(*) FROM t1;
1338- ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2;
1359+ ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2 KEY 'testkey' ;
13391360 SELECT count(*) from db2.t1;
13401361 PRAGMA cipher_default_use_hmac = ON;
13411362 }
@@ -1352,7 +1373,7 @@ do_test attach-1.1.8-database-from-2.0-fails {
13521373 catchsql {
13531374 PRAGMA key = 'testkey';
13541375 CREATE table t1(a,b);
1355- ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2;
1376+ ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2 KEY 'testkey' ;
13561377 }
13571378} {1 {file is encrypted or is not a database}}
13581379db close
@@ -1376,7 +1397,7 @@ do_test change-default-use-hmac-attach {
13761397 PRAGMA key = 'testkey';
13771398 SELECT count(*) FROM t1;
13781399 PRAGMA cipher_default_use_hmac = OFF;
1379- ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2;
1400+ ATTACH 'sqlcipher-1.1.8-testkey.db' AS db2 KEY 'testkey' ;
13801401 SELECT count(*) from db2.t1;
13811402 PRAGMA cipher_default_use_hmac = ON;
13821403 }
0 commit comments