summaryrefslogtreecommitdiffstats
path: root/test/alterauth.test
blob: 12645b36f0826103413d152eb4943c8bca06bc92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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