1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/vtab3.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,140 @@
1.4 +# 2006 June 10
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#***********************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this file is the authorisation callback and virtual tables.
1.16 +#
1.17 +# $Id: vtab3.test,v 1.3 2008/07/12 14:52:21 drh Exp $
1.18 +
1.19 +set testdir [file dirname $argv0]
1.20 +source $testdir/tester.tcl
1.21 +
1.22 +ifcapable !vtab||!auth {
1.23 + finish_test
1.24 + return
1.25 +}
1.26 +
1.27 +set ::auth_fail 0
1.28 +set ::auth_log [list]
1.29 +set ::auth_filter [list SQLITE_READ SQLITE_UPDATE SQLITE_SELECT SQLITE_PRAGMA]
1.30 +
1.31 +proc auth {code arg1 arg2 arg3 arg4} {
1.32 + if {[lsearch $::auth_filter $code]>-1} {
1.33 + return SQLITE_OK
1.34 + }
1.35 + lappend ::auth_log $code $arg1 $arg2 $arg3 $arg4
1.36 + incr ::auth_fail -1
1.37 + if {$::auth_fail == 0} {
1.38 + return SQLITE_DENY
1.39 + }
1.40 + return SQLITE_OK
1.41 +}
1.42 +
1.43 +do_test vtab3-1.1 {
1.44 + execsql {
1.45 + CREATE TABLE elephant(
1.46 + name VARCHAR(32),
1.47 + color VARCHAR(16),
1.48 + age INTEGER,
1.49 + UNIQUE(name, color)
1.50 + );
1.51 + }
1.52 +} {}
1.53 +
1.54 +
1.55 +do_test vtab3-1.2 {
1.56 + register_echo_module [sqlite3_connection_pointer db]
1.57 + db authorizer ::auth
1.58 + execsql {
1.59 + CREATE VIRTUAL TABLE pachyderm USING echo(elephant);
1.60 + }
1.61 + set ::auth_log
1.62 +} [list \
1.63 + SQLITE_INSERT sqlite_master {} main {} \
1.64 + SQLITE_CREATE_VTABLE pachyderm echo main {} \
1.65 +]
1.66 +
1.67 +do_test vtab3-1.3 {
1.68 + set ::auth_log [list]
1.69 + execsql {
1.70 + DROP TABLE pachyderm;
1.71 + }
1.72 + set ::auth_log
1.73 +} [list \
1.74 + SQLITE_DELETE sqlite_master {} main {} \
1.75 + SQLITE_DROP_VTABLE pachyderm echo main {} \
1.76 + SQLITE_DELETE pachyderm {} main {} \
1.77 + SQLITE_DELETE sqlite_master {} main {} \
1.78 +]
1.79 +
1.80 +do_test vtab3-1.4 {
1.81 + set ::auth_fail 1
1.82 + catchsql {
1.83 + CREATE VIRTUAL TABLE pachyderm USING echo(elephant);
1.84 + }
1.85 +} {1 {not authorized}}
1.86 +do_test vtab3-1.5 {
1.87 + execsql {
1.88 + SELECT name FROM sqlite_master WHERE type = 'table';
1.89 + }
1.90 +} {elephant}
1.91 +
1.92 +do_test vtab3-1.5 {
1.93 + set ::auth_fail 2
1.94 + catchsql {
1.95 + CREATE VIRTUAL TABLE pachyderm USING echo(elephant);
1.96 + }
1.97 +} {1 {not authorized}}
1.98 +do_test vtab3-1.6 {
1.99 + execsql {
1.100 + SELECT name FROM sqlite_master WHERE type = 'table';
1.101 + }
1.102 +} {elephant}
1.103 +
1.104 +do_test vtab3-1.5 {
1.105 + set ::auth_fail 3
1.106 + catchsql {
1.107 + CREATE VIRTUAL TABLE pachyderm USING echo(elephant);
1.108 + }
1.109 +} {0 {}}
1.110 +do_test vtab3-1.6 {
1.111 + execsql {
1.112 + SELECT name FROM sqlite_master WHERE type = 'table';
1.113 + }
1.114 +} {elephant pachyderm}
1.115 +
1.116 +foreach i [list 1 2 3 4] {
1.117 + set ::auth_fail $i
1.118 + do_test vtab3-1.7.$i.1 {
1.119 + set rc [catch {
1.120 + execsql {DROP TABLE pachyderm;}
1.121 + } msg]
1.122 + if {$msg eq "authorization denied"} {set msg "not authorized"}
1.123 + list $rc $msg
1.124 + } {1 {not authorized}}
1.125 + do_test vtab3-1.7.$i.2 {
1.126 + execsql {
1.127 + SELECT name FROM sqlite_master WHERE type = 'table';
1.128 + }
1.129 + } {elephant pachyderm}
1.130 +}
1.131 +do_test vtab3-1.8.1 {
1.132 + set ::auth_fail 0
1.133 + catchsql {
1.134 + DROP TABLE pachyderm;
1.135 + }
1.136 +} {0 {}}
1.137 +do_test vtab3-1.8.2 {
1.138 + execsql {
1.139 + SELECT name FROM sqlite_master WHERE type = 'table';
1.140 + }
1.141 +} {elephant}
1.142 +
1.143 +finish_test