securedel2.test 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # 2012 August 7
  2. #
  3. # The author disclaims copyright to this source code. In place of
  4. # a legal notice, here is a blessing:
  5. #
  6. # May you do good and not evil.
  7. # May you find forgiveness for yourself and forgive others.
  8. # May you share freely, never taking more than you give.
  9. #
  10. #*************************************************************************
  11. #
  12. # Tests for the secure_delete pragma.
  13. #
  14. set testdir [file dirname $argv0]
  15. source $testdir/tester.tcl
  16. set ::testprefix securedel2
  17. # Generate 1000 pseudo-random 64-bit blobs.
  18. #
  19. for {set i 1} {$i <= 1000} {incr i} {
  20. set aBlob($i) [string range [db one {SELECT quote(randomblob(8))}] 2 end-1]
  21. }
  22. proc detect_blob_prepare {zFile} {
  23. set nByte [file size $zFile]
  24. set ::detect_blob_data [hexio_read $zFile 0 $nByte]
  25. }
  26. proc detect_blob {zFile iBlob} {
  27. if {$zFile != ""} { detect_blob_prepare $zFile }
  28. string match "*$::aBlob($iBlob)*" $::detect_blob_data
  29. }
  30. do_test 1.1 {
  31. execsql { PRAGMA secure_delete = 1 }
  32. execsql { PRAGMA auto_vacuum = 0 }
  33. execsql { CREATE TABLE t1(x, y) }
  34. for {set i 1} {$i <= 1000} {incr i} {
  35. set x "X'[string repeat $aBlob($i) 1]'"
  36. set y "X'[string repeat $aBlob($i) 500]'"
  37. execsql "INSERT INTO t1 VALUES($x, $y)"
  38. }
  39. } {}
  40. do_test 1.2 { detect_blob test.db 1 } {1}
  41. forcecopy test.db test.db.bak
  42. do_execsql_test 1.3.1 { PRAGMA secure_delete = 0 } {0}
  43. do_execsql_test 1.3.2 { DELETE FROM t1 WHERE rowid = 1 }
  44. do_test 1.3.3 { detect_blob test.db 1 } {1}
  45. db close
  46. forcecopy test.db.bak test.db
  47. sqlite3 db test.db
  48. do_execsql_test 1.4.1 { PRAGMA secure_delete = 1 } {1}
  49. do_execsql_test 1.4.2 { DELETE FROM t1 WHERE rowid = 1 }
  50. do_test 1.4.3 { detect_blob test.db 1 } {0}
  51. do_execsql_test 1.5.1 { DELETE FROM t1 WHERE rowid>850 } {}
  52. do_test 1.5.2 {
  53. set n 0
  54. detect_blob_prepare test.db
  55. for {set i 851} {$i <= 1000} {incr i 5} {
  56. incr n [detect_blob {} $i]
  57. }
  58. set n
  59. } {0}
  60. db close
  61. sqlite3 db test.db
  62. do_test 1.6.1 {
  63. execsql {
  64. PRAGMA cache_size = 200;
  65. PRAGMA secure_delete = 1;
  66. CREATE TABLE t2(x);
  67. SELECT * FROM t1;
  68. }
  69. for {set i 100} {$i < 5000} {incr i} {
  70. execsql { INSERT INTO t2 VALUES(randomblob($i)) }
  71. }
  72. execsql { DELETE FROM t1 }
  73. } {}
  74. do_test 1.6.2 {
  75. set n 0
  76. detect_blob_prepare test.db
  77. for {set i 2} {$i <= 850} {incr i 5} {
  78. incr n [detect_blob {} $i]
  79. }
  80. set n
  81. } {0}
  82. finish_test