summaryrefslogtreecommitdiffstats
path: root/test/alterauth.test
diff options
context:
space:
mode:
Diffstat (limited to 'test/alterauth.test')
-rw-r--r--test/alterauth.test72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/alterauth.test b/test/alterauth.test
new file mode 100644
index 0000000..12645b3
--- /dev/null
+++ b/test/alterauth.test
@@ -0,0 +1,72 @@
+# 2018 September 2
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#*************************************************************************
+#
+
+set testdir [file dirname $argv0]
+
+source $testdir/tester.tcl
+
+# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
+ifcapable !altertable {
+ finish_test
+ return
+}
+set testprefix alterauth
+
+set ::auth [list]
+proc xAuth {type args} {
+ if {$type == "SQLITE_ALTER_TABLE"} {
+ lappend ::auth [concat $type [lrange $args 0 3]]
+ }
+ return SQLITE_OK
+}
+db auth xAuth
+
+do_execsql_test 1.0 { CREATE TABLE t1(a, b, c); }
+
+do_test 1.1 {
+ set ::auth [list]
+ execsql { ALTER TABLE t1 RENAME TO t2 }
+ set ::auth
+} {{SQLITE_ALTER_TABLE main t1 {} {}}}
+
+do_test 1.2 {
+ set ::auth [list]
+ execsql { ALTER TABLE t2 RENAME c TO ccc }
+ set ::auth
+} {{SQLITE_ALTER_TABLE main t2 {} {}}}
+
+do_test 1.3 {
+ set ::auth [list]
+ execsql { ALTER TABLE t2 ADD COLUMN d }
+ set ::auth
+} {{SQLITE_ALTER_TABLE main t2 {} {}}}
+
+proc xAuth {type args} {
+ if {$type == "SQLITE_ALTER_TABLE"} {
+ return SQLITE_DENY
+ }
+ return SQLITE_OK
+}
+
+do_test 2.1 {
+ catchsql { ALTER TABLE t2 RENAME TO t3 }
+} {1 {not authorized}}
+
+do_test 2.2 {
+ catchsql { ALTER TABLE t2 RENAME d TO ddd }
+} {1 {not authorized}}
+
+do_test 2.3 {
+ catchsql { ALTER TABLE t2 ADD COLUMN e }
+} {1 {not authorized}}
+
+finish_test