Skip to content

Commit 2b7a28f

Browse files
committed
tests for large schemas and behavior with auto vacuum enabled
1 parent bedfc5b commit 2b7a28f

1 file changed

Lines changed: 96 additions & 3 deletions

File tree

test/crypto.test

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -791,8 +791,9 @@ do_test hmac-tamper-resistence {
791791

792792
db close
793793

794-
# write some junk into the middle of the page
795-
hexio_write test.db 2560 00
794+
# write some junk into the hmac segment, leaving
795+
# the page data valid but with an invalid signature
796+
hexio_write test.db 1000 0000
796797

797798
sqlite_orig db test.db
798799

@@ -801,7 +802,7 @@ do_test hmac-tamper-resistence {
801802
SELECT count(*) FROM t1;
802803
}
803804

804-
} {1 {database disk image is malformed}}
805+
} {1 {file is encrypted or is not a database}}
805806
db close
806807
file delete -force test.db
807808

@@ -1461,6 +1462,98 @@ db close
14611462
file delete -force test.db
14621463

14631464

1465+
# create a database with many hundred tables such that the schema
1466+
# will overflow the first several pages of the database. verify the schema
1467+
# is intact on open.
1468+
do_test multipage-schema {
1469+
sqlite_orig db test.db
1470+
execsql {
1471+
PRAGMA key = 'testkey';
1472+
BEGIN EXCLUSIVE;
1473+
} db
1474+
1475+
for {set i 1} {$i<=300} {incr i} {
1476+
execsql "CREATE TABLE tab$i (a TEXT, b TEXT, c TEXT, d TEXT, e TEXT, f TEXT, g TEXT, h TEXT, i TEXT, j TEXT, k, TEXT, l, m TEXT, n TEXT, o TEXT, p TEXT);" db
1477+
}
1478+
1479+
execsql {
1480+
COMMIT;
1481+
} db
1482+
1483+
db close
1484+
sqlite_orig db test.db
14641485

1486+
execsql {
1487+
PRAGMA key = 'testkey';
1488+
SELECT count(*) FROM sqlite_master where type = 'table';
1489+
} db
1490+
1491+
} {300}
1492+
db close
1493+
file delete -force test.db
1494+
1495+
# create a database with many hundred tables such that the schema
1496+
# will overflow the first several pages of the database. this time, enable
1497+
# autovacuum on the database, which will cause sqlite to do some "short reads"
1498+
# after the end of the main database file. verify that there are no HMAC errors
1499+
# resulting from the short reads, and that the schema is intact when
1500+
# the database is reopened
1501+
do_test multipage-schema-autovacuum-shortread {
1502+
sqlite_orig db test.db
1503+
execsql {
1504+
PRAGMA key = 'testkey';
1505+
PRAGMA auto_vacuum = FULL;
1506+
BEGIN EXCLUSIVE;
1507+
} db
1508+
1509+
for {set i 1} {$i<=300} {incr i} {
1510+
execsql "CREATE TABLE tab$i (a TEXT, b TEXT, c TEXT, d TEXT, e TEXT, f TEXT, g TEXT, h TEXT, i TEXT, j TEXT, k, TEXT, l, m TEXT, n TEXT, o TEXT, p TEXT);" db
1511+
}
1512+
1513+
execsql {
1514+
COMMIT;
1515+
} db
1516+
1517+
db close
1518+
sqlite_orig db test.db
1519+
1520+
execsql {
1521+
PRAGMA key = 'testkey';
1522+
SELECT count(*) FROM sqlite_master where type = 'table';
1523+
} db
1524+
1525+
} {300}
1526+
db close
1527+
file delete -force test.db
1528+
1529+
# same as multi-page-schema-autovacuum-shortread, except
1530+
# using write ahead log mode
1531+
do_test multipage-schema-autovacuum-shortread-wal {
1532+
sqlite_orig db test.db
1533+
execsql {
1534+
PRAGMA key = 'testkey';
1535+
PRAGMA auto_vacuum = FULL;
1536+
PRAGMA journal_mode = WAL;
1537+
BEGIN EXCLUSIVE;
1538+
} db
1539+
1540+
for {set i 1} {$i<=300} {incr i} {
1541+
execsql "CREATE TABLE tab$i (a TEXT, b TEXT, c TEXT, d TEXT, e TEXT, f TEXT, g TEXT, h TEXT, i TEXT, j TEXT, k, TEXT, l, m TEXT, n TEXT, o TEXT, p TEXT);" db
1542+
}
1543+
1544+
execsql {
1545+
COMMIT;
1546+
} db
1547+
1548+
db close
1549+
sqlite_orig db test.db
1550+
1551+
execsql {
1552+
PRAGMA key = 'testkey';
1553+
SELECT count(*) FROM sqlite_master where type = 'table';
1554+
} db
1555+
} {300}
1556+
db close
1557+
file delete -force test.db
14651558

14661559
finish_test

0 commit comments

Comments
 (0)