Skip to content

Commit 8a734f2

Browse files
committed
expand rekey tests
1 parent 1397c0b commit 8a734f2

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

test/crypto.test

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,113 @@ do_test rekey-as-first-operation {
201201
db close
202202
file delete -force test.db
203203

204+
# create a new database, insert some data
205+
# then rekey it with the same password
206+
do_test rekey-same-passkey {
207+
sqlite_orig db test.db
208+
209+
execsql {
210+
PRAGMA key = 'test123';
211+
CREATE TABLE t1(a,b);
212+
BEGIN;
213+
}
214+
215+
for {set i 1} {$i<=1000} {incr i} {
216+
set r [expr {int(rand()*500000)}]
217+
execsql "INSERT INTO t1 VALUES($i,'value $r');"
218+
}
219+
220+
execsql {
221+
COMMIT;
222+
SELECT count(*) FROM t1;
223+
PRAGMA rekey = 'test123';
224+
SELECT count(*) FROM t1;
225+
}
226+
} {1000 1000}
227+
db close
228+
file delete -force test.db
229+
230+
# create a new database, insert some data
231+
# then rekey it. Make sure it is immediately
232+
# readable. Then close it and make sure it can be
233+
# read back
234+
do_test rekey-and-query-1 {
235+
sqlite_orig db test.db
236+
237+
execsql {
238+
PRAGMA key = 'test123';
239+
CREATE TABLE t1(a,b);
240+
BEGIN;
241+
}
242+
243+
for {set i 1} {$i<=1000} {incr i} {
244+
set r [expr {int(rand()*500000)}]
245+
execsql "INSERT INTO t1 VALUES($i,'value $r');"
246+
}
247+
248+
execsql {
249+
COMMIT;
250+
SELECT count(*) FROM t1;
251+
PRAGMA rekey = 'test321';
252+
SELECT count(*) FROM t1;
253+
}
254+
} {1000 1000}
255+
256+
db close
257+
258+
do_test rekey-and-query-2 {
259+
sqlite_orig db test.db
260+
execsql {
261+
PRAGMA key = 'test321';
262+
SELECT count(*) FROM t1;
263+
}
264+
} {1000}
265+
db close
266+
file delete -force test.db
267+
268+
# create a new database, insert some data
269+
# delete about 50% of the data
270+
# write some new data
271+
# delete another 50%
272+
# then rekey it. Make sure it is immediately
273+
# readable. Then close it and make sure it can be
274+
# read back
275+
do_test rekey-delete-and-query-1 {
276+
sqlite_orig db test.db
277+
278+
execsql {
279+
PRAGMA key = 'test123';
280+
CREATE TABLE t1(a,b);
281+
CREATE INDEX ta_a ON t1(a);
282+
BEGIN;
283+
}
284+
285+
for {set i 1} {$i<10000} {incr i} {
286+
set r [expr {int(rand()*500000)}]
287+
execsql "INSERT INTO t1 VALUES($i,'value $r');"
288+
}
289+
290+
execsql {
291+
COMMIT;
292+
DELETE FROM t1 WHERE a > 5000;
293+
BEGIN;
294+
}
295+
296+
for {set i 10000} {$i<12500} {incr i} {
297+
set r [expr {int(rand()*500000)}]
298+
execsql "INSERT INTO t1 VALUES($i,'value $r');"
299+
}
300+
301+
execsql {
302+
PRAGMA rekey = 'test321';
303+
SELECT count(*) FROM t1;
304+
}
305+
} {7500}
306+
307+
db close
308+
file delete -force test.db
309+
310+
204311
# attach an encrypted database
205312
# where both database have the same
206313
# key

0 commit comments

Comments
 (0)