/ Hex Artifact Content
Login

Artifact 5cfa94ed90c6617c42b7ba4b133fd79678b251c7:


0000: 23 20 32 30 30 38 20 4f 63 74 6f 62 65 72 20 32  # 2008 October 2
0010: 37 0a 23 0a 23 20 54 68 65 20 61 75 74 68 6f 72  7.#.# The author
0020: 20 64 69 73 63 6c 61 69 6d 73 20 63 6f 70 79 72   disclaims copyr
0030: 69 67 68 74 20 74 6f 20 74 68 69 73 20 73 6f 75  ight to this sou
0040: 72 63 65 20 63 6f 64 65 2e 20 20 49 6e 20 70 6c  rce code.  In pl
0050: 61 63 65 20 6f 66 0a 23 20 61 20 6c 65 67 61 6c  ace of.# a legal
0060: 20 6e 6f 74 69 63 65 2c 20 68 65 72 65 20 69 73   notice, here is
0070: 20 61 20 62 6c 65 73 73 69 6e 67 3a 0a 23 0a 23   a blessing:.#.#
0080: 20 20 20 20 4d 61 79 20 79 6f 75 20 64 6f 20 67      May you do g
0090: 6f 6f 64 20 61 6e 64 20 6e 6f 74 20 65 76 69 6c  ood and not evil
00a0: 2e 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 66  ..#    May you f
00b0: 69 6e 64 20 66 6f 72 67 69 76 65 6e 65 73 73 20  ind forgiveness 
00c0: 66 6f 72 20 79 6f 75 72 73 65 6c 66 20 61 6e 64  for yourself and
00d0: 20 66 6f 72 67 69 76 65 20 6f 74 68 65 72 73 2e   forgive others.
00e0: 0a 23 20 20 20 20 4d 61 79 20 79 6f 75 20 73 68  .#    May you sh
00f0: 61 72 65 20 66 72 65 65 6c 79 2c 20 6e 65 76 65  are freely, neve
0100: 72 20 74 61 6b 69 6e 67 20 6d 6f 72 65 20 74 68  r taking more th
0110: 61 6e 20 79 6f 75 20 67 69 76 65 2e 0a 23 0a 23  an you give..#.#
0120: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0130: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0140: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0150: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0160: 2a 2a 2a 2a 2a 2a 2a 0a 23 0a 23 20 54 65 73 74  *******.#.# Test
0170: 20 74 68 61 74 20 74 68 65 20 74 72 75 6e 63 61   that the trunca
0180: 74 65 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20  te optimization 
0190: 69 73 20 64 69 73 61 62 6c 65 64 20 69 66 20 74  is disabled if t
01a0: 68 65 20 53 51 4c 49 54 45 5f 44 45 4c 45 54 45  he SQLITE_DELETE
01b0: 0a 23 20 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e  .# authorization
01c0: 20 63 61 6c 6c 62 61 63 6b 20 72 65 74 75 72 6e   callback return
01d0: 73 20 53 51 4c 49 54 45 5f 49 47 4e 4f 52 45 2e  s SQLITE_IGNORE.
01e0: 0a 23 0a 23 20 24 49 64 3a 20 61 75 74 68 33 2e  .#.# $Id: auth3.
01f0: 74 65 73 74 2c 76 20 31 2e 32 20 32 30 30 39 2f  test,v 1.2 2009/
0200: 30 35 2f 30 34 20 30 31 3a 35 38 3a 33 31 20 64  05/04 01:58:31 d
0210: 72 68 20 45 78 70 20 24 0a 23 0a 0a 73 65 74 20  rh Exp $.#..set 
0220: 74 65 73 74 64 69 72 20 5b 66 69 6c 65 20 64 69  testdir [file di
0230: 72 6e 61 6d 65 20 24 61 72 67 76 30 5d 0a 73 6f  rname $argv0].so
0240: 75 72 63 65 20 24 74 65 73 74 64 69 72 2f 74 65  urce $testdir/te
0250: 73 74 65 72 2e 74 63 6c 0a 0a 23 20 64 69 73 61  ster.tcl..# disa
0260: 62 6c 65 20 74 68 69 73 20 74 65 73 74 20 69 66  ble this test if
0270: 20 74 68 65 20 53 51 4c 49 54 45 5f 4f 4d 49 54   the SQLITE_OMIT
0280: 5f 41 55 54 48 4f 52 49 5a 41 54 49 4f 4e 20 6d  _AUTHORIZATION m
0290: 61 63 72 6f 20 69 73 0a 23 20 64 65 66 69 6e 65  acro is.# define
02a0: 64 20 64 75 72 69 6e 67 20 63 6f 6d 70 69 6c 61  d during compila
02b0: 74 69 6f 6e 2e 0a 69 66 20 7b 5b 63 61 74 63 68  tion..if {[catch
02c0: 20 7b 64 62 20 61 75 74 68 20 7b 7d 7d 20 6d 73   {db auth {}} ms
02d0: 67 5d 7d 20 7b 0a 20 20 66 69 6e 69 73 68 5f 74  g]} {.  finish_t
02e0: 65 73 74 0a 20 20 72 65 74 75 72 6e 0a 7d 0a 0a  est.  return.}..
02f0: 23 20 44 69 73 61 62 6c 65 20 74 68 65 20 73 74  # Disable the st
0300: 61 74 65 6d 65 6e 74 20 63 61 63 68 65 20 66 6f  atement cache fo
0310: 72 20 74 68 65 73 65 20 74 65 73 74 73 2e 0a 23  r these tests..#
0320: 20 0a 64 62 20 63 61 63 68 65 20 73 69 7a 65 20   .db cache size 
0330: 30 0a 0a 64 62 20 61 75 74 68 6f 72 69 7a 65 72  0..db authorizer
0340: 20 3a 3a 61 75 74 68 0a 70 72 6f 63 20 61 75 74   ::auth.proc aut
0350: 68 20 7b 63 6f 64 65 20 61 72 67 31 20 61 72 67  h {code arg1 arg
0360: 32 20 61 72 67 33 20 61 72 67 34 20 61 72 67 73  2 arg3 arg4 args
0370: 7d 20 7b 0a 20 20 69 66 20 7b 24 63 6f 64 65 3d  } {.  if {$code=
0380: 3d 22 53 51 4c 49 54 45 5f 44 45 4c 45 54 45 22  ="SQLITE_DELETE"
0390: 7d 20 7b 0a 20 20 20 20 72 65 74 75 72 6e 20 24  } {.    return $
03a0: 3a 3a 61 75 74 68 63 6f 64 65 0a 20 20 7d 0a 20  ::authcode.  }. 
03b0: 20 72 65 74 75 72 6e 20 53 51 4c 49 54 45 5f 4f   return SQLITE_O
03c0: 4b 0a 7d 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  K.}..#----------
03d0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
03f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0400: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0410: 0a 23 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  .# The following
0420: 20 74 65 73 74 73 20 2d 20 61 75 74 68 33 2d 31   tests - auth3-1
0430: 2e 2a 20 2d 20 74 65 73 74 20 74 68 61 74 20 72  .* - test that r
0440: 65 74 75 72 6e 20 76 61 6c 75 65 73 20 6f 66 20  eturn values of 
0450: 53 51 4c 49 54 45 5f 44 45 4e 59 2c 0a 23 20 53  SQLITE_DENY,.# S
0460: 51 4c 49 54 45 5f 49 47 4e 4f 52 45 2c 20 53 51  QLITE_IGNORE, SQ
0470: 4c 49 54 45 5f 4f 4b 20 61 6e 64 20 3c 69 6e 76  LITE_OK and <inv
0480: 61 6c 69 64 3e 20 61 72 65 20 63 6f 72 72 65 63  alid> are correc
0490: 74 6c 79 20 68 61 6e 64 6c 65 64 20 77 68 65 6e  tly handled when
04a0: 20 72 65 74 75 72 6e 65 64 0a 23 20 62 79 20 61   returned.# by a
04b0: 6e 20 53 51 4c 49 54 45 5f 44 45 4c 45 54 45 20  n SQLITE_DELETE 
04c0: 61 75 74 68 6f 72 69 7a 61 74 69 6f 6e 20 63 61  authorization ca
04d0: 6c 6c 62 61 63 6b 20 74 72 69 67 67 65 72 65 64  llback triggered
04e0: 20 62 79 20 61 20 0a 23 20 22 44 45 4c 45 54 45   by a .# "DELETE
04f0: 20 46 52 4f 4d 20 3c 74 61 62 6c 65 2d 6e 61 6d   FROM <table-nam
0500: 65 3e 22 20 73 74 61 74 65 6d 65 6e 74 2e 0a 23  e>" statement..#
0510: 0a 64 6f 5f 74 65 73 74 20 61 75 74 68 33 2d 31  .do_test auth3-1
0520: 2e 31 20 7b 0a 20 20 65 78 65 63 73 71 6c 20 7b  .1 {.  execsql {
0530: 0a 20 20 20 20 43 52 45 41 54 45 20 54 41 42 4c  .    CREATE TABL
0540: 45 20 74 31 28 61 2c 62 2c 63 29 3b 0a 20 20 20  E t1(a,b,c);.   
0550: 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31 20   INSERT INTO t1 
0560: 56 41 4c 55 45 53 28 31 2c 20 32 2c 20 33 29 3b  VALUES(1, 2, 3);
0570: 0a 20 20 20 20 49 4e 53 45 52 54 20 49 4e 54 4f  .    INSERT INTO
0580: 20 74 31 20 56 41 4c 55 45 53 28 34 2c 20 35 2c   t1 VALUES(4, 5,
0590: 20 36 29 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 64 6f   6);.  }.} {}.do
05a0: 5f 74 65 73 74 20 61 75 74 68 33 2e 31 2e 32 20  _test auth3.1.2 
05b0: 7b 0a 20 20 73 65 74 20 3a 3a 61 75 74 68 63 6f  {.  set ::authco
05c0: 64 65 20 53 51 4c 49 54 45 5f 44 45 4e 59 0a 20  de SQLITE_DENY. 
05d0: 20 63 61 74 63 68 73 71 6c 20 7b 20 44 45 4c 45   catchsql { DELE
05e0: 54 45 20 46 52 4f 4d 20 74 31 20 7d 0a 7d 20 7b  TE FROM t1 }.} {
05f0: 31 20 7b 6e 6f 74 20 61 75 74 68 6f 72 69 7a 65  1 {not authorize
0600: 64 7d 7d 0a 64 6f 5f 74 65 73 74 20 61 75 74 68  d}}.do_test auth
0610: 33 2e 31 2e 33 20 7b 0a 20 20 73 65 74 20 3a 3a  3.1.3 {.  set ::
0620: 61 75 74 68 63 6f 64 65 20 53 51 4c 49 54 45 5f  authcode SQLITE_
0630: 49 4e 56 41 4c 49 44 0a 20 20 63 61 74 63 68 73  INVALID.  catchs
0640: 71 6c 20 7b 20 44 45 4c 45 54 45 20 46 52 4f 4d  ql { DELETE FROM
0650: 20 74 31 20 7d 0a 7d 20 7b 31 20 7b 61 75 74 68   t1 }.} {1 {auth
0660: 6f 72 69 7a 65 72 20 6d 61 6c 66 75 6e 63 74 69  orizer malfuncti
0670: 6f 6e 7d 7d 0a 64 6f 5f 74 65 73 74 20 61 75 74  on}}.do_test aut
0680: 68 33 2e 31 2e 34 20 7b 0a 20 20 65 78 65 63 73  h3.1.4 {.  execs
0690: 71 6c 20 7b 20 53 45 4c 45 43 54 20 2a 20 46 52  ql { SELECT * FR
06a0: 4f 4d 20 74 31 20 7d 0a 7d 20 7b 31 20 32 20 33  OM t1 }.} {1 2 3
06b0: 20 34 20 35 20 36 7d 0a 64 6f 5f 74 65 73 74 20   4 5 6}.do_test 
06c0: 61 75 74 68 33 2d 31 2e 35 20 7b 0a 20 20 73 65  auth3-1.5 {.  se
06d0: 74 20 3a 3a 61 75 74 68 63 6f 64 65 20 53 51 4c  t ::authcode SQL
06e0: 49 54 45 5f 49 47 4e 4f 52 45 0a 20 20 65 78 65  ITE_IGNORE.  exe
06f0: 63 73 71 6c 20 7b 20 0a 20 20 20 20 44 45 4c 45  csql { .    DELE
0700: 54 45 20 46 52 4f 4d 20 74 31 3b 0a 20 20 20 20  TE FROM t1;.    
0710: 53 45 4c 45 43 54 20 2a 20 46 52 4f 4d 20 74 31  SELECT * FROM t1
0720: 3b 0a 20 20 7d 0a 7d 20 7b 7d 0a 64 6f 5f 74 65  ;.  }.} {}.do_te
0730: 73 74 20 61 75 74 68 33 2d 31 2e 36 20 7b 0a 20  st auth3-1.6 {. 
0740: 20 73 65 74 20 3a 3a 61 75 74 68 63 6f 64 65 20   set ::authcode 
0750: 53 51 4c 49 54 45 5f 4f 4b 0a 20 20 65 78 65 63  SQLITE_OK.  exec
0760: 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45 52 54  sql {.    INSERT
0770: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
0780: 31 2c 20 32 2c 20 33 29 3b 0a 20 20 20 20 49 4e  1, 2, 3);.    IN
0790: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
07a0: 55 45 53 28 34 2c 20 35 2c 20 36 29 3b 0a 20 20  UES(4, 5, 6);.  
07b0: 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31    DELETE FROM t1
07c0: 3b 0a 20 20 20 20 53 45 4c 45 43 54 20 2a 20 46  ;.    SELECT * F
07d0: 52 4f 4d 20 74 31 3b 0a 20 20 7d 0a 7d 20 7b 7d  ROM t1;.  }.} {}
07e0: 0a 0a 23 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ..#-------------
07f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0800: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0810: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0820: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 0a 23 20  -------------.# 
0830: 54 68 65 73 65 20 74 65 73 74 73 20 2d 20 61 75  These tests - au
0840: 74 68 33 2d 32 2e 2a 20 2d 20 74 65 73 74 20 74  th3-2.* - test t
0850: 68 61 74 20 72 65 74 75 72 6e 69 6e 67 20 53 51  hat returning SQ
0860: 4c 49 54 45 5f 49 47 4e 4f 52 45 20 72 65 61 6c  LITE_IGNORE real
0870: 6c 79 20 64 6f 65 73 0a 23 20 64 69 73 61 62 6c  ly does.# disabl
0880: 65 20 74 68 65 20 74 72 75 6e 63 61 74 65 20 6f  e the truncate o
0890: 70 74 69 6d 69 7a 61 74 69 6f 6e 2e 0a 23 0a 64  ptimization..#.d
08a0: 6f 5f 74 65 73 74 20 61 75 74 68 33 2d 32 2e 31  o_test auth3-2.1
08b0: 20 7b 0a 20 20 73 65 74 20 3a 3a 61 75 74 68 63   {.  set ::authc
08c0: 6f 64 65 20 53 51 4c 49 54 45 5f 4f 4b 0a 20 20  ode SQLITE_OK.  
08d0: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 49 4e  execsql {.    IN
08e0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
08f0: 55 45 53 28 31 2c 20 32 2c 20 33 29 3b 0a 20 20  UES(1, 2, 3);.  
0900: 20 20 49 4e 53 45 52 54 20 49 4e 54 4f 20 74 31    INSERT INTO t1
0910: 20 56 41 4c 55 45 53 28 34 2c 20 35 2c 20 36 29   VALUES(4, 5, 6)
0920: 3b 0a 20 20 7d 0a 20 20 73 65 74 20 73 71 6c 69  ;.  }.  set sqli
0930: 74 65 5f 73 65 61 72 63 68 5f 63 6f 75 6e 74 20  te_search_count 
0940: 30 0a 20 20 65 78 65 63 73 71 6c 20 7b 0a 20 20  0.  execsql {.  
0950: 20 20 44 45 4c 45 54 45 20 46 52 4f 4d 20 74 31    DELETE FROM t1
0960: 3b 0a 20 20 7d 0a 20 20 73 65 74 20 73 71 6c 69  ;.  }.  set sqli
0970: 74 65 5f 73 65 61 72 63 68 5f 63 6f 75 6e 74 0a  te_search_count.
0980: 7d 20 7b 30 7d 0a 0a 64 6f 5f 74 65 73 74 20 61  } {0}..do_test a
0990: 75 74 68 33 2d 32 2e 32 20 7b 0a 20 20 73 65 74  uth3-2.2 {.  set
09a0: 20 3a 3a 61 75 74 68 63 6f 64 65 20 53 51 4c 49   ::authcode SQLI
09b0: 54 45 5f 49 47 4e 4f 52 45 0a 20 20 65 78 65 63  TE_IGNORE.  exec
09c0: 73 71 6c 20 7b 0a 20 20 20 20 49 4e 53 45 52 54  sql {.    INSERT
09d0: 20 49 4e 54 4f 20 74 31 20 56 41 4c 55 45 53 28   INTO t1 VALUES(
09e0: 31 2c 20 32 2c 20 33 29 3b 0a 20 20 20 20 49 4e  1, 2, 3);.    IN
09f0: 53 45 52 54 20 49 4e 54 4f 20 74 31 20 56 41 4c  SERT INTO t1 VAL
0a00: 55 45 53 28 34 2c 20 35 2c 20 36 29 3b 0a 20 20  UES(4, 5, 6);.  
0a10: 7d 0a 20 20 73 65 74 20 73 71 6c 69 74 65 5f 73  }.  set sqlite_s
0a20: 65 61 72 63 68 5f 63 6f 75 6e 74 20 30 0a 20 20  earch_count 0.  
0a30: 65 78 65 63 73 71 6c 20 7b 0a 20 20 20 20 44 45  execsql {.    DE
0a40: 4c 45 54 45 20 46 52 4f 4d 20 74 31 3b 0a 20 20  LETE FROM t1;.  
0a50: 7d 0a 20 20 73 65 74 20 73 71 6c 69 74 65 5f 73  }.  set sqlite_s
0a60: 65 61 72 63 68 5f 63 6f 75 6e 74 0a 7d 20 7b 31  earch_count.} {1
0a70: 7d 0a 0a 66 69 6e 69 73 68 5f 74 65 73 74 0a     }..finish_test.