author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
# 2006 June 10 |
sl@0 | 2 |
# |
sl@0 | 3 |
# The author disclaims copyright to this source code. In place of |
sl@0 | 4 |
# a legal notice, here is a blessing: |
sl@0 | 5 |
# |
sl@0 | 6 |
# May you do good and not evil. |
sl@0 | 7 |
# May you find forgiveness for yourself and forgive others. |
sl@0 | 8 |
# May you share freely, never taking more than you give. |
sl@0 | 9 |
# |
sl@0 | 10 |
#*********************************************************************** |
sl@0 | 11 |
# This file implements regression tests for SQLite library. The |
sl@0 | 12 |
# focus of this file is the authorisation callback and virtual tables. |
sl@0 | 13 |
# |
sl@0 | 14 |
# $Id: vtab3.test,v 1.3 2008/07/12 14:52:21 drh Exp $ |
sl@0 | 15 |
|
sl@0 | 16 |
set testdir [file dirname $argv0] |
sl@0 | 17 |
source $testdir/tester.tcl |
sl@0 | 18 |
|
sl@0 | 19 |
ifcapable !vtab||!auth { |
sl@0 | 20 |
finish_test |
sl@0 | 21 |
return |
sl@0 | 22 |
} |
sl@0 | 23 |
|
sl@0 | 24 |
set ::auth_fail 0 |
sl@0 | 25 |
set ::auth_log [list] |
sl@0 | 26 |
set ::auth_filter [list SQLITE_READ SQLITE_UPDATE SQLITE_SELECT SQLITE_PRAGMA] |
sl@0 | 27 |
|
sl@0 | 28 |
proc auth {code arg1 arg2 arg3 arg4} { |
sl@0 | 29 |
if {[lsearch $::auth_filter $code]>-1} { |
sl@0 | 30 |
return SQLITE_OK |
sl@0 | 31 |
} |
sl@0 | 32 |
lappend ::auth_log $code $arg1 $arg2 $arg3 $arg4 |
sl@0 | 33 |
incr ::auth_fail -1 |
sl@0 | 34 |
if {$::auth_fail == 0} { |
sl@0 | 35 |
return SQLITE_DENY |
sl@0 | 36 |
} |
sl@0 | 37 |
return SQLITE_OK |
sl@0 | 38 |
} |
sl@0 | 39 |
|
sl@0 | 40 |
do_test vtab3-1.1 { |
sl@0 | 41 |
execsql { |
sl@0 | 42 |
CREATE TABLE elephant( |
sl@0 | 43 |
name VARCHAR(32), |
sl@0 | 44 |
color VARCHAR(16), |
sl@0 | 45 |
age INTEGER, |
sl@0 | 46 |
UNIQUE(name, color) |
sl@0 | 47 |
); |
sl@0 | 48 |
} |
sl@0 | 49 |
} {} |
sl@0 | 50 |
|
sl@0 | 51 |
|
sl@0 | 52 |
do_test vtab3-1.2 { |
sl@0 | 53 |
register_echo_module [sqlite3_connection_pointer db] |
sl@0 | 54 |
db authorizer ::auth |
sl@0 | 55 |
execsql { |
sl@0 | 56 |
CREATE VIRTUAL TABLE pachyderm USING echo(elephant); |
sl@0 | 57 |
} |
sl@0 | 58 |
set ::auth_log |
sl@0 | 59 |
} [list \ |
sl@0 | 60 |
SQLITE_INSERT sqlite_master {} main {} \ |
sl@0 | 61 |
SQLITE_CREATE_VTABLE pachyderm echo main {} \ |
sl@0 | 62 |
] |
sl@0 | 63 |
|
sl@0 | 64 |
do_test vtab3-1.3 { |
sl@0 | 65 |
set ::auth_log [list] |
sl@0 | 66 |
execsql { |
sl@0 | 67 |
DROP TABLE pachyderm; |
sl@0 | 68 |
} |
sl@0 | 69 |
set ::auth_log |
sl@0 | 70 |
} [list \ |
sl@0 | 71 |
SQLITE_DELETE sqlite_master {} main {} \ |
sl@0 | 72 |
SQLITE_DROP_VTABLE pachyderm echo main {} \ |
sl@0 | 73 |
SQLITE_DELETE pachyderm {} main {} \ |
sl@0 | 74 |
SQLITE_DELETE sqlite_master {} main {} \ |
sl@0 | 75 |
] |
sl@0 | 76 |
|
sl@0 | 77 |
do_test vtab3-1.4 { |
sl@0 | 78 |
set ::auth_fail 1 |
sl@0 | 79 |
catchsql { |
sl@0 | 80 |
CREATE VIRTUAL TABLE pachyderm USING echo(elephant); |
sl@0 | 81 |
} |
sl@0 | 82 |
} {1 {not authorized}} |
sl@0 | 83 |
do_test vtab3-1.5 { |
sl@0 | 84 |
execsql { |
sl@0 | 85 |
SELECT name FROM sqlite_master WHERE type = 'table'; |
sl@0 | 86 |
} |
sl@0 | 87 |
} {elephant} |
sl@0 | 88 |
|
sl@0 | 89 |
do_test vtab3-1.5 { |
sl@0 | 90 |
set ::auth_fail 2 |
sl@0 | 91 |
catchsql { |
sl@0 | 92 |
CREATE VIRTUAL TABLE pachyderm USING echo(elephant); |
sl@0 | 93 |
} |
sl@0 | 94 |
} {1 {not authorized}} |
sl@0 | 95 |
do_test vtab3-1.6 { |
sl@0 | 96 |
execsql { |
sl@0 | 97 |
SELECT name FROM sqlite_master WHERE type = 'table'; |
sl@0 | 98 |
} |
sl@0 | 99 |
} {elephant} |
sl@0 | 100 |
|
sl@0 | 101 |
do_test vtab3-1.5 { |
sl@0 | 102 |
set ::auth_fail 3 |
sl@0 | 103 |
catchsql { |
sl@0 | 104 |
CREATE VIRTUAL TABLE pachyderm USING echo(elephant); |
sl@0 | 105 |
} |
sl@0 | 106 |
} {0 {}} |
sl@0 | 107 |
do_test vtab3-1.6 { |
sl@0 | 108 |
execsql { |
sl@0 | 109 |
SELECT name FROM sqlite_master WHERE type = 'table'; |
sl@0 | 110 |
} |
sl@0 | 111 |
} {elephant pachyderm} |
sl@0 | 112 |
|
sl@0 | 113 |
foreach i [list 1 2 3 4] { |
sl@0 | 114 |
set ::auth_fail $i |
sl@0 | 115 |
do_test vtab3-1.7.$i.1 { |
sl@0 | 116 |
set rc [catch { |
sl@0 | 117 |
execsql {DROP TABLE pachyderm;} |
sl@0 | 118 |
} msg] |
sl@0 | 119 |
if {$msg eq "authorization denied"} {set msg "not authorized"} |
sl@0 | 120 |
list $rc $msg |
sl@0 | 121 |
} {1 {not authorized}} |
sl@0 | 122 |
do_test vtab3-1.7.$i.2 { |
sl@0 | 123 |
execsql { |
sl@0 | 124 |
SELECT name FROM sqlite_master WHERE type = 'table'; |
sl@0 | 125 |
} |
sl@0 | 126 |
} {elephant pachyderm} |
sl@0 | 127 |
} |
sl@0 | 128 |
do_test vtab3-1.8.1 { |
sl@0 | 129 |
set ::auth_fail 0 |
sl@0 | 130 |
catchsql { |
sl@0 | 131 |
DROP TABLE pachyderm; |
sl@0 | 132 |
} |
sl@0 | 133 |
} {0 {}} |
sl@0 | 134 |
do_test vtab3-1.8.2 { |
sl@0 | 135 |
execsql { |
sl@0 | 136 |
SELECT name FROM sqlite_master WHERE type = 'table'; |
sl@0 | 137 |
} |
sl@0 | 138 |
} {elephant} |
sl@0 | 139 |
|
sl@0 | 140 |
finish_test |