auth3.test 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # 2008 October 27
  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. # Test that the truncate optimization is disabled if the SQLITE_DELETE
  13. # authorization callback returns SQLITE_IGNORE.
  14. #
  15. # $Id: auth3.test,v 1.2 2009/05/04 01:58:31 drh Exp $
  16. #
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
  20. # defined during compilation.
  21. if {[catch {db auth {}} msg]} {
  22. finish_test
  23. return
  24. }
  25. # Disable the statement cache for these tests.
  26. #
  27. db cache size 0
  28. db authorizer ::auth
  29. proc auth {code arg1 arg2 arg3 arg4} {
  30. if {$code=="SQLITE_DELETE"} {
  31. return $::authcode
  32. }
  33. return SQLITE_OK
  34. }
  35. #--------------------------------------------------------------------------
  36. # The following tests - auth3-1.* - test that return values of SQLITE_DENY,
  37. # SQLITE_IGNORE, SQLITE_OK and <invalid> are correctly handled when returned
  38. # by an SQLITE_DELETE authorization callback triggered by a
  39. # "DELETE FROM <table-name>" statement.
  40. #
  41. do_test auth3-1.1 {
  42. execsql {
  43. CREATE TABLE t1(a,b,c);
  44. INSERT INTO t1 VALUES(1, 2, 3);
  45. INSERT INTO t1 VALUES(4, 5, 6);
  46. }
  47. } {}
  48. do_test auth3.1.2 {
  49. set ::authcode SQLITE_DENY
  50. catchsql { DELETE FROM t1 }
  51. } {1 {not authorized}}
  52. do_test auth3.1.3 {
  53. set ::authcode SQLITE_INVALID
  54. catchsql { DELETE FROM t1 }
  55. } {1 {authorizer malfunction}}
  56. do_test auth3.1.4 {
  57. execsql { SELECT * FROM t1 }
  58. } {1 2 3 4 5 6}
  59. do_test auth3-1.5 {
  60. set ::authcode SQLITE_IGNORE
  61. execsql {
  62. DELETE FROM t1;
  63. SELECT * FROM t1;
  64. }
  65. } {}
  66. do_test auth3-1.6 {
  67. set ::authcode SQLITE_OK
  68. execsql {
  69. INSERT INTO t1 VALUES(1, 2, 3);
  70. INSERT INTO t1 VALUES(4, 5, 6);
  71. DELETE FROM t1;
  72. SELECT * FROM t1;
  73. }
  74. } {}
  75. #--------------------------------------------------------------------------
  76. # These tests - auth3-2.* - test that returning SQLITE_IGNORE really does
  77. # disable the truncate optimization.
  78. #
  79. do_test auth3-2.1 {
  80. set ::authcode SQLITE_OK
  81. execsql {
  82. INSERT INTO t1 VALUES(1, 2, 3);
  83. INSERT INTO t1 VALUES(4, 5, 6);
  84. }
  85. set sqlite_search_count 0
  86. execsql {
  87. DELETE FROM t1;
  88. }
  89. set sqlite_search_count
  90. } {0}
  91. do_test auth3-2.2 {
  92. set ::authcode SQLITE_IGNORE
  93. execsql {
  94. INSERT INTO t1 VALUES(1, 2, 3);
  95. INSERT INTO t1 VALUES(4, 5, 6);
  96. }
  97. set sqlite_search_count 0
  98. execsql {
  99. DELETE FROM t1;
  100. }
  101. set sqlite_search_count
  102. } {1}
  103. finish_test