interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / alterauth.test

72 lines · 1547 bytes Raw Blame History
1# 2018 September 2
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
13set testdir [file dirname $argv0]
14
15source $testdir/tester.tcl
16
17# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
18ifcapable !altertable {
19 finish_test
20 return
21}
22set testprefix alterauth
23
24set ::auth [list]
25proc xAuth {type args} {
26 if {$type == "SQLITE_ALTER_TABLE"} {
27 lappend ::auth [concat $type [lrange $args 0 3]]
28 }
29 return SQLITE_OK
30}
31db auth xAuth
32
33do_execsql_test 1.0 { CREATE TABLE t1(a, b, c); }
34
35do_test 1.1 {
36 set ::auth [list]
37 execsql { ALTER TABLE t1 RENAME TO t2 }
38 set ::auth
39} {{SQLITE_ALTER_TABLE main t1 {} {}}}
40
41do_test 1.2 {
42 set ::auth [list]
43 execsql { ALTER TABLE t2 RENAME c TO ccc }
44 set ::auth
45} {{SQLITE_ALTER_TABLE main t2 {} {}}}
46
47do_test 1.3 {
48 set ::auth [list]
49 execsql { ALTER TABLE t2 ADD COLUMN d }
50 set ::auth
51} {{SQLITE_ALTER_TABLE main t2 {} {}}}
52
53proc xAuth {type args} {
54 if {$type == "SQLITE_ALTER_TABLE"} {
55 return SQLITE_DENY
56 }
57 return SQLITE_OK
58}
59
60do_test 2.1 {
61 catchsql { ALTER TABLE t2 RENAME TO t3 }
62} {1 {not authorized}}
63
64do_test 2.2 {
65 catchsql { ALTER TABLE t2 RENAME d TO ddd }
66} {1 {not authorized}}
67
68do_test 2.3 {
69 catchsql { ALTER TABLE t2 ADD COLUMN e }
70} {1 {not authorized}}
71
72finish_test