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