drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 1 | # 2003 January 12 |
| 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 | # This file implements regression tests for SQLite library. The |
| 12 | # focus of this script testing the sqlite_set_authorizer() API. |
| 13 | # |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 14 | # $Id: auth.test,v 1.2 2003/01/13 23:27:34 drh Exp $ |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 15 | # |
| 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
| 19 | |
| 20 | if {[info command sqlite_set_authorizer]!=""} { |
| 21 | |
| 22 | do_test auth-1.1 { |
| 23 | db close |
| 24 | set ::DB [sqlite db test.db] |
| 25 | proc auth {code arg1 arg2} { |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 26 | if {$code=="SQLITE_INSERT" |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 27 | && [string compare -nocase $arg1 sqlite_master]==0} { |
| 28 | return SQLITE_DENY |
| 29 | } |
| 30 | return SQLITE_OK |
| 31 | } |
| 32 | sqlite_set_authorizer $::DB ::auth |
| 33 | catchsql {CREATE TABLE t1(a,b,c)} |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 34 | } {1 {not authorized}} |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 35 | do_test auth-1.2 { |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 36 | execsql {SELECT name FROM sqlite_master} |
| 37 | } {} |
| 38 | do_test auth-1.3 { |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 39 | proc auth {code arg1 arg2} { |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 40 | if {$code=="SQLITE_CREATE_TABLE"} { |
| 41 | return SQLITE_DENY |
| 42 | } |
| 43 | return SQLITE_OK |
| 44 | } |
| 45 | catchsql {CREATE TABLE t1(a,b,c)} |
| 46 | } {1 {not authorized}} |
| 47 | do_test auth-1.4 { |
| 48 | execsql {SELECT name FROM sqlite_master} |
| 49 | } {} |
| 50 | |
| 51 | do_test auth-1.5 { |
| 52 | proc auth {code arg1 arg2} { |
| 53 | if {$code=="SQLITE_INSERT" |
| 54 | && [string compare -nocase $arg1 sqlite_temp_master]==0} { |
| 55 | return SQLITE_DENY |
| 56 | } |
| 57 | return SQLITE_OK |
| 58 | } |
| 59 | catchsql {CREATE TEMP TABLE t1(a,b,c)} |
| 60 | } {1 {not authorized}} |
| 61 | do_test auth-1.6 { |
| 62 | execsql {SELECT name FROM sqlite_temp_master} |
| 63 | } {} |
| 64 | do_test auth-1.7 { |
| 65 | proc auth {code arg1 arg2} { |
| 66 | if {$code=="SQLITE_CREATE_TEMP_TABLE"} { |
| 67 | return SQLITE_DENY |
| 68 | } |
| 69 | return SQLITE_OK |
| 70 | } |
| 71 | catchsql {CREATE TEMP TABLE t1(a,b,c)} |
| 72 | } {1 {not authorized}} |
| 73 | do_test auth-1.8 { |
| 74 | execsql {SELECT name FROM sqlite_temp_master} |
| 75 | } {} |
| 76 | |
| 77 | do_test auth-1.9 { |
| 78 | proc auth {code arg1 arg2} { |
| 79 | if {$code=="SQLITE_INSERT" |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 80 | && [string compare -nocase $arg1 sqlite_master]==0} { |
| 81 | return SQLITE_IGNORE |
| 82 | } |
| 83 | return SQLITE_OK |
| 84 | } |
| 85 | catchsql {CREATE TABLE t1(a,b,c)} |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 86 | } {0 {}} |
| 87 | do_test auth-1.10 { |
| 88 | execsql {SELECT name FROM sqlite_master} |
| 89 | } {} |
| 90 | do_test auth-1.11 { |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 91 | proc auth {code arg1 arg2} { |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 92 | if {$code=="SQLITE_CREATE_TABLE"} { |
| 93 | return SQLITE_IGNORE |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 94 | } |
| 95 | return SQLITE_OK |
| 96 | } |
| 97 | catchsql {CREATE TABLE t1(a,b,c)} |
| 98 | } {0 {}} |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 99 | do_test auth-1.12 { |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 100 | execsql {SELECT name FROM sqlite_master} |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 101 | } {} |
| 102 | do_test auth-1.13 { |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 103 | proc auth {code arg1 arg2} { |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 104 | if {$code=="SQLITE_INSERT" |
| 105 | && [string compare -nocase $arg1 sqlite_temp_master]==0} { |
| 106 | return SQLITE_IGNORE |
| 107 | } |
| 108 | return SQLITE_OK |
| 109 | } |
| 110 | catchsql {CREATE TEMP TABLE t1(a,b,c)} |
| 111 | } {0 {}} |
| 112 | do_test auth-1.14 { |
| 113 | execsql {SELECT name FROM sqlite_temp_master} |
| 114 | } {} |
| 115 | do_test auth-1.15 { |
| 116 | proc auth {code arg1 arg2} { |
| 117 | if {$code=="SQLITE_CREATE_TEMP_TABLE"} { |
| 118 | return SQLITE_IGNORE |
| 119 | } |
| 120 | return SQLITE_OK |
| 121 | } |
| 122 | catchsql {CREATE TEMP TABLE t1(a,b,c)} |
| 123 | } {0 {}} |
| 124 | do_test auth-1.16 { |
| 125 | execsql {SELECT name FROM sqlite_temp_master} |
| 126 | } {} |
| 127 | |
| 128 | do_test auth-1.17 { |
| 129 | proc auth {code arg1 arg2} { |
| 130 | if {$code=="SQLITE_CREATE_TABLE"} { |
| 131 | return SQLITE_DEBY |
| 132 | } |
| 133 | return SQLITE_OK |
| 134 | } |
| 135 | catchsql {CREATE TEMP TABLE t1(a,b,c)} |
| 136 | } {0 {}} |
| 137 | do_test auth-1.18 { |
| 138 | execsql {SELECT name FROM sqlite_temp_master} |
| 139 | } {t1} |
| 140 | do_test auth-1.19 { |
| 141 | proc auth {code arg1 arg2} { |
| 142 | if {$code=="SQLITE_CREATE_TEMP_TABLE"} { |
| 143 | return SQLITE_DEBY |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 144 | } |
| 145 | return SQLITE_OK |
| 146 | } |
| 147 | catchsql {CREATE TABLE t2(a,b,c)} |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 148 | } {0 {}} |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 149 | do_test auth-1.20 { |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 150 | execsql {SELECT name FROM sqlite_master} |
| 151 | } {t2} |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 152 | |
drh | e5f9c64 | 2003-01-13 23:27:31 +0000 | [diff] [blame^] | 153 | |
| 154 | |
| 155 | |
drh | 1962bda | 2003-01-12 19:33:52 +0000 | [diff] [blame] | 156 | } ;# End of the "if( db command exists )" |
| 157 | |
| 158 | finish_test |