auth.test 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403
  1. # 2003 April 4
  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. # This file implements regression tests for SQLite library. The
  12. # focus of this script is testing the sqlite3_set_authorizer() API
  13. # and related functionality.
  14. #
  15. # $Id: auth.test,v 1.46 2009/07/02 18:40:35 danielk1977 Exp $
  16. #
  17. set testdir [file dirname $argv0]
  18. source $testdir/tester.tcl
  19. # disable this test if the SQLITE_OMIT_AUTHORIZATION macro is
  20. # defined during compilation.
  21. if {[catch {db auth {}} msg]} {
  22. finish_test
  23. return
  24. }
  25. rename proc proc_real
  26. proc_real proc {name arguments script} {
  27. proc_real $name $arguments $script
  28. if {$name=="auth"} {
  29. db authorizer ::auth
  30. }
  31. }
  32. do_test auth-1.1.1 {
  33. db close
  34. set ::DB [sqlite3 db test.db]
  35. proc auth {code arg1 arg2 arg3 arg4} {
  36. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  37. return SQLITE_DENY
  38. }
  39. return SQLITE_OK
  40. }
  41. db authorizer ::auth
  42. catchsql {CREATE TABLE t1(a,b,c)}
  43. } {1 {not authorized}}
  44. do_test auth-1.1.2 {
  45. db errorcode
  46. } {23}
  47. do_test auth-1.1.3 {
  48. db authorizer
  49. } {::auth}
  50. do_test auth-1.1.4 {
  51. # Ticket #896.
  52. catchsql {
  53. SELECT x;
  54. }
  55. } {1 {no such column: x}}
  56. do_test auth-1.2 {
  57. execsql {SELECT name FROM sqlite_master}
  58. } {}
  59. do_test auth-1.3.1 {
  60. proc auth {code arg1 arg2 arg3 arg4} {
  61. if {$code=="SQLITE_CREATE_TABLE"} {
  62. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  63. return SQLITE_DENY
  64. }
  65. return SQLITE_OK
  66. }
  67. catchsql {CREATE TABLE t1(a,b,c)}
  68. } {1 {not authorized}}
  69. do_test auth-1.3.2 {
  70. db errorcode
  71. } {23}
  72. do_test auth-1.3.3 {
  73. set ::authargs
  74. } {t1 {} main {}}
  75. do_test auth-1.4 {
  76. execsql {SELECT name FROM sqlite_master}
  77. } {}
  78. ifcapable tempdb {
  79. do_test auth-1.5 {
  80. proc auth {code arg1 arg2 arg3 arg4} {
  81. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  82. return SQLITE_DENY
  83. }
  84. return SQLITE_OK
  85. }
  86. catchsql {CREATE TEMP TABLE t1(a,b,c)}
  87. } {1 {not authorized}}
  88. do_test auth-1.6 {
  89. execsql {SELECT name FROM sqlite_temp_master}
  90. } {}
  91. do_test auth-1.7.1 {
  92. proc auth {code arg1 arg2 arg3 arg4} {
  93. if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
  94. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  95. return SQLITE_DENY
  96. }
  97. return SQLITE_OK
  98. }
  99. catchsql {CREATE TEMP TABLE t1(a,b,c)}
  100. } {1 {not authorized}}
  101. do_test auth-1.7.2 {
  102. set ::authargs
  103. } {t1 {} temp {}}
  104. do_test auth-1.8 {
  105. execsql {SELECT name FROM sqlite_temp_master}
  106. } {}
  107. }
  108. do_test auth-1.9 {
  109. proc auth {code arg1 arg2 arg3 arg4} {
  110. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  111. return SQLITE_IGNORE
  112. }
  113. return SQLITE_OK
  114. }
  115. catchsql {CREATE TABLE t1(a,b,c)}
  116. } {0 {}}
  117. do_test auth-1.10 {
  118. execsql {SELECT name FROM sqlite_master}
  119. } {}
  120. do_test auth-1.11 {
  121. proc auth {code arg1 arg2 arg3 arg4} {
  122. if {$code=="SQLITE_CREATE_TABLE"} {
  123. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  124. return SQLITE_IGNORE
  125. }
  126. return SQLITE_OK
  127. }
  128. catchsql {CREATE TABLE t1(a,b,c)}
  129. } {0 {}}
  130. do_test auth-1.12 {
  131. execsql {SELECT name FROM sqlite_master}
  132. } {}
  133. ifcapable tempdb {
  134. do_test auth-1.13 {
  135. proc auth {code arg1 arg2 arg3 arg4} {
  136. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  137. return SQLITE_IGNORE
  138. }
  139. return SQLITE_OK
  140. }
  141. catchsql {CREATE TEMP TABLE t1(a,b,c)}
  142. } {0 {}}
  143. do_test auth-1.14 {
  144. execsql {SELECT name FROM sqlite_temp_master}
  145. } {}
  146. do_test auth-1.15 {
  147. proc auth {code arg1 arg2 arg3 arg4} {
  148. if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
  149. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  150. return SQLITE_IGNORE
  151. }
  152. return SQLITE_OK
  153. }
  154. catchsql {CREATE TEMP TABLE t1(a,b,c)}
  155. } {0 {}}
  156. do_test auth-1.16 {
  157. execsql {SELECT name FROM sqlite_temp_master}
  158. } {}
  159. do_test auth-1.17 {
  160. proc auth {code arg1 arg2 arg3 arg4} {
  161. if {$code=="SQLITE_CREATE_TABLE"} {
  162. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  163. return SQLITE_DENY
  164. }
  165. return SQLITE_OK
  166. }
  167. catchsql {CREATE TEMP TABLE t1(a,b,c)}
  168. } {0 {}}
  169. do_test auth-1.18 {
  170. execsql {SELECT name FROM sqlite_temp_master}
  171. } {t1}
  172. }
  173. do_test auth-1.19.1 {
  174. set ::authargs {}
  175. proc auth {code arg1 arg2 arg3 arg4} {
  176. if {$code=="SQLITE_CREATE_TEMP_TABLE"} {
  177. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  178. return SQLITE_DENY
  179. }
  180. return SQLITE_OK
  181. }
  182. catchsql {CREATE TABLE t2(a,b,c)}
  183. } {0 {}}
  184. do_test auth-1.19.2 {
  185. set ::authargs
  186. } {}
  187. do_test auth-1.20 {
  188. execsql {SELECT name FROM sqlite_master}
  189. } {t2}
  190. do_test auth-1.21.1 {
  191. proc auth {code arg1 arg2 arg3 arg4} {
  192. if {$code=="SQLITE_DROP_TABLE"} {
  193. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  194. return SQLITE_DENY
  195. }
  196. return SQLITE_OK
  197. }
  198. catchsql {DROP TABLE t2}
  199. } {1 {not authorized}}
  200. do_test auth-1.21.2 {
  201. set ::authargs
  202. } {t2 {} main {}}
  203. do_test auth-1.22 {
  204. execsql {SELECT name FROM sqlite_master}
  205. } {t2}
  206. do_test auth-1.23.1 {
  207. proc auth {code arg1 arg2 arg3 arg4} {
  208. if {$code=="SQLITE_DROP_TABLE"} {
  209. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  210. return SQLITE_IGNORE
  211. }
  212. return SQLITE_OK
  213. }
  214. catchsql {DROP TABLE t2}
  215. } {0 {}}
  216. do_test auth-1.23.2 {
  217. set ::authargs
  218. } {t2 {} main {}}
  219. do_test auth-1.24 {
  220. execsql {SELECT name FROM sqlite_master}
  221. } {t2}
  222. ifcapable tempdb {
  223. do_test auth-1.25 {
  224. proc auth {code arg1 arg2 arg3 arg4} {
  225. if {$code=="SQLITE_DROP_TEMP_TABLE"} {
  226. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  227. return SQLITE_DENY
  228. }
  229. return SQLITE_OK
  230. }
  231. catchsql {DROP TABLE t1}
  232. } {1 {not authorized}}
  233. do_test auth-1.26 {
  234. execsql {SELECT name FROM sqlite_temp_master}
  235. } {t1}
  236. do_test auth-1.27 {
  237. proc auth {code arg1 arg2 arg3 arg4} {
  238. if {$code=="SQLITE_DROP_TEMP_TABLE"} {
  239. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  240. return SQLITE_IGNORE
  241. }
  242. return SQLITE_OK
  243. }
  244. catchsql {DROP TABLE t1}
  245. } {0 {}}
  246. do_test auth-1.28 {
  247. execsql {SELECT name FROM sqlite_temp_master}
  248. } {t1}
  249. }
  250. do_test auth-1.29 {
  251. proc auth {code arg1 arg2 arg3 arg4} {
  252. if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
  253. return SQLITE_DENY
  254. }
  255. return SQLITE_OK
  256. }
  257. catchsql {INSERT INTO t2 VALUES(1,2,3)}
  258. } {1 {not authorized}}
  259. do_test auth-1.30 {
  260. execsql {SELECT * FROM t2}
  261. } {}
  262. do_test auth-1.31 {
  263. proc auth {code arg1 arg2 arg3 arg4} {
  264. if {$code=="SQLITE_INSERT" && $arg1=="t2"} {
  265. return SQLITE_IGNORE
  266. }
  267. return SQLITE_OK
  268. }
  269. catchsql {INSERT INTO t2 VALUES(1,2,3)}
  270. } {0 {}}
  271. do_test auth-1.32 {
  272. execsql {SELECT * FROM t2}
  273. } {}
  274. do_test auth-1.33 {
  275. proc auth {code arg1 arg2 arg3 arg4} {
  276. if {$code=="SQLITE_INSERT" && $arg1=="t1"} {
  277. return SQLITE_IGNORE
  278. }
  279. return SQLITE_OK
  280. }
  281. catchsql {INSERT INTO t2 VALUES(1,2,3)}
  282. } {0 {}}
  283. do_test auth-1.34 {
  284. execsql {SELECT * FROM t2}
  285. } {1 2 3}
  286. do_test auth-1.35.1 {
  287. proc auth {code arg1 arg2 arg3 arg4} {
  288. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
  289. return SQLITE_DENY
  290. }
  291. return SQLITE_OK
  292. }
  293. catchsql {SELECT * FROM t2}
  294. } {1 {access to t2.b is prohibited}}
  295. ifcapable attach {
  296. do_test auth-1.35.2 {
  297. execsql {ATTACH DATABASE 'test.db' AS two}
  298. catchsql {SELECT * FROM two.t2}
  299. } {1 {access to two.t2.b is prohibited}}
  300. execsql {DETACH DATABASE two}
  301. }
  302. do_test auth-1.36 {
  303. proc auth {code arg1 arg2 arg3 arg4} {
  304. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
  305. return SQLITE_IGNORE
  306. }
  307. return SQLITE_OK
  308. }
  309. catchsql {SELECT * FROM t2}
  310. } {0 {1 {} 3}}
  311. do_test auth-1.37 {
  312. proc auth {code arg1 arg2 arg3 arg4} {
  313. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
  314. return SQLITE_IGNORE
  315. }
  316. return SQLITE_OK
  317. }
  318. catchsql {SELECT * FROM t2 WHERE b=2}
  319. } {0 {}}
  320. do_test auth-1.38 {
  321. proc auth {code arg1 arg2 arg3 arg4} {
  322. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="a"} {
  323. return SQLITE_IGNORE
  324. }
  325. return SQLITE_OK
  326. }
  327. catchsql {SELECT * FROM t2 WHERE b=2}
  328. } {0 {{} 2 3}}
  329. do_test auth-1.39 {
  330. proc auth {code arg1 arg2 arg3 arg4} {
  331. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
  332. return SQLITE_IGNORE
  333. }
  334. return SQLITE_OK
  335. }
  336. catchsql {SELECT * FROM t2 WHERE b IS NULL}
  337. } {0 {1 {} 3}}
  338. do_test auth-1.40 {
  339. proc auth {code arg1 arg2 arg3 arg4} {
  340. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="b"} {
  341. return SQLITE_DENY
  342. }
  343. return SQLITE_OK
  344. }
  345. catchsql {SELECT a,c FROM t2 WHERE b IS NULL}
  346. } {1 {access to t2.b is prohibited}}
  347. do_test auth-1.41 {
  348. proc auth {code arg1 arg2 arg3 arg4} {
  349. if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
  350. return SQLITE_DENY
  351. }
  352. return SQLITE_OK
  353. }
  354. catchsql {UPDATE t2 SET a=11}
  355. } {0 {}}
  356. do_test auth-1.42 {
  357. execsql {SELECT * FROM t2}
  358. } {11 2 3}
  359. do_test auth-1.43 {
  360. proc auth {code arg1 arg2 arg3 arg4} {
  361. if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
  362. return SQLITE_DENY
  363. }
  364. return SQLITE_OK
  365. }
  366. catchsql {UPDATE t2 SET b=22, c=33}
  367. } {1 {not authorized}}
  368. do_test auth-1.44 {
  369. execsql {SELECT * FROM t2}
  370. } {11 2 3}
  371. do_test auth-1.45 {
  372. proc auth {code arg1 arg2 arg3 arg4} {
  373. if {$code=="SQLITE_UPDATE" && $arg1=="t2" && $arg2=="b"} {
  374. return SQLITE_IGNORE
  375. }
  376. return SQLITE_OK
  377. }
  378. catchsql {UPDATE t2 SET b=22, c=33}
  379. } {0 {}}
  380. do_test auth-1.46 {
  381. execsql {SELECT * FROM t2}
  382. } {11 2 33}
  383. do_test auth-1.47 {
  384. proc auth {code arg1 arg2 arg3 arg4} {
  385. if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
  386. return SQLITE_DENY
  387. }
  388. return SQLITE_OK
  389. }
  390. catchsql {DELETE FROM t2 WHERE a=11}
  391. } {1 {not authorized}}
  392. do_test auth-1.48 {
  393. execsql {SELECT * FROM t2}
  394. } {11 2 33}
  395. do_test auth-1.49 {
  396. proc auth {code arg1 arg2 arg3 arg4} {
  397. if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
  398. return SQLITE_IGNORE
  399. }
  400. return SQLITE_OK
  401. }
  402. catchsql {DELETE FROM t2 WHERE a=11}
  403. } {0 {}}
  404. do_test auth-1.50 {
  405. execsql {SELECT * FROM t2}
  406. } {}
  407. do_test auth-1.50.2 {
  408. execsql {INSERT INTO t2 VALUES(11, 2, 33)}
  409. } {}
  410. do_test auth-1.51 {
  411. proc auth {code arg1 arg2 arg3 arg4} {
  412. if {$code=="SQLITE_SELECT"} {
  413. return SQLITE_DENY
  414. }
  415. return SQLITE_OK
  416. }
  417. catchsql {SELECT * FROM t2}
  418. } {1 {not authorized}}
  419. do_test auth-1.52 {
  420. proc auth {code arg1 arg2 arg3 arg4} {
  421. if {$code=="SQLITE_SELECT"} {
  422. return SQLITE_IGNORE
  423. }
  424. return SQLITE_OK
  425. }
  426. catchsql {SELECT * FROM t2}
  427. } {0 {}}
  428. do_test auth-1.53 {
  429. proc auth {code arg1 arg2 arg3 arg4} {
  430. if {$code=="SQLITE_SELECT"} {
  431. return SQLITE_OK
  432. }
  433. return SQLITE_OK
  434. }
  435. catchsql {SELECT * FROM t2}
  436. } {0 {11 2 33}}
  437. # Update for version 3: There used to be a handful of test here that
  438. # tested the authorisation callback with the COPY command. The following
  439. # test makes the same database modifications as they used to.
  440. do_test auth-1.54 {
  441. execsql {INSERT INTO t2 VALUES(7, 8, 9);}
  442. } {}
  443. do_test auth-1.55 {
  444. execsql {SELECT * FROM t2}
  445. } {11 2 33 7 8 9}
  446. do_test auth-1.63 {
  447. proc auth {code arg1 arg2 arg3 arg4} {
  448. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  449. return SQLITE_DENY
  450. }
  451. return SQLITE_OK
  452. }
  453. catchsql {DROP TABLE t2}
  454. } {1 {not authorized}}
  455. do_test auth-1.64 {
  456. execsql {SELECT name FROM sqlite_master}
  457. } {t2}
  458. do_test auth-1.65 {
  459. proc auth {code arg1 arg2 arg3 arg4} {
  460. if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
  461. return SQLITE_DENY
  462. }
  463. return SQLITE_OK
  464. }
  465. catchsql {DROP TABLE t2}
  466. } {1 {not authorized}}
  467. do_test auth-1.66 {
  468. execsql {SELECT name FROM sqlite_master}
  469. } {t2}
  470. ifcapable tempdb {
  471. do_test auth-1.67 {
  472. proc auth {code arg1 arg2 arg3 arg4} {
  473. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  474. return SQLITE_DENY
  475. }
  476. return SQLITE_OK
  477. }
  478. catchsql {DROP TABLE t1}
  479. } {1 {not authorized}}
  480. do_test auth-1.68 {
  481. execsql {SELECT name FROM sqlite_temp_master}
  482. } {t1}
  483. do_test auth-1.69 {
  484. proc auth {code arg1 arg2 arg3 arg4} {
  485. if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
  486. return SQLITE_DENY
  487. }
  488. return SQLITE_OK
  489. }
  490. catchsql {DROP TABLE t1}
  491. } {1 {not authorized}}
  492. do_test auth-1.70 {
  493. execsql {SELECT name FROM sqlite_temp_master}
  494. } {t1}
  495. }
  496. do_test auth-1.71 {
  497. proc auth {code arg1 arg2 arg3 arg4} {
  498. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  499. return SQLITE_IGNORE
  500. }
  501. return SQLITE_OK
  502. }
  503. catchsql {DROP TABLE t2}
  504. } {0 {}}
  505. do_test auth-1.72 {
  506. execsql {SELECT name FROM sqlite_master}
  507. } {t2}
  508. do_test auth-1.73 {
  509. proc auth {code arg1 arg2 arg3 arg4} {
  510. if {$code=="SQLITE_DELETE" && $arg1=="t2"} {
  511. return SQLITE_IGNORE
  512. }
  513. return SQLITE_OK
  514. }
  515. catchsql {DROP TABLE t2}
  516. } {0 {}}
  517. do_test auth-1.74 {
  518. execsql {SELECT name FROM sqlite_master}
  519. } {t2}
  520. ifcapable tempdb {
  521. do_test auth-1.75 {
  522. proc auth {code arg1 arg2 arg3 arg4} {
  523. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  524. return SQLITE_IGNORE
  525. }
  526. return SQLITE_OK
  527. }
  528. catchsql {DROP TABLE t1}
  529. } {0 {}}
  530. do_test auth-1.76 {
  531. execsql {SELECT name FROM sqlite_temp_master}
  532. } {t1}
  533. do_test auth-1.77 {
  534. proc auth {code arg1 arg2 arg3 arg4} {
  535. if {$code=="SQLITE_DELETE" && $arg1=="t1"} {
  536. return SQLITE_IGNORE
  537. }
  538. return SQLITE_OK
  539. }
  540. catchsql {DROP TABLE t1}
  541. } {0 {}}
  542. do_test auth-1.78 {
  543. execsql {SELECT name FROM sqlite_temp_master}
  544. } {t1}
  545. }
  546. # Test cases auth-1.79 to auth-1.124 test creating and dropping views.
  547. # Omit these if the library was compiled with views omitted.
  548. ifcapable view {
  549. do_test auth-1.79 {
  550. proc auth {code arg1 arg2 arg3 arg4} {
  551. if {$code=="SQLITE_CREATE_VIEW"} {
  552. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  553. return SQLITE_DENY
  554. }
  555. return SQLITE_OK
  556. }
  557. catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
  558. } {1 {not authorized}}
  559. do_test auth-1.80 {
  560. set ::authargs
  561. } {v1 {} main {}}
  562. do_test auth-1.81 {
  563. execsql {SELECT name FROM sqlite_master}
  564. } {t2}
  565. do_test auth-1.82 {
  566. proc auth {code arg1 arg2 arg3 arg4} {
  567. if {$code=="SQLITE_CREATE_VIEW"} {
  568. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  569. return SQLITE_IGNORE
  570. }
  571. return SQLITE_OK
  572. }
  573. catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
  574. } {0 {}}
  575. do_test auth-1.83 {
  576. set ::authargs
  577. } {v1 {} main {}}
  578. do_test auth-1.84 {
  579. execsql {SELECT name FROM sqlite_master}
  580. } {t2}
  581. ifcapable tempdb {
  582. do_test auth-1.85 {
  583. proc auth {code arg1 arg2 arg3 arg4} {
  584. if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
  585. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  586. return SQLITE_DENY
  587. }
  588. return SQLITE_OK
  589. }
  590. catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
  591. } {1 {not authorized}}
  592. do_test auth-1.86 {
  593. set ::authargs
  594. } {v1 {} temp {}}
  595. do_test auth-1.87 {
  596. execsql {SELECT name FROM sqlite_temp_master}
  597. } {t1}
  598. do_test auth-1.88 {
  599. proc auth {code arg1 arg2 arg3 arg4} {
  600. if {$code=="SQLITE_CREATE_TEMP_VIEW"} {
  601. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  602. return SQLITE_IGNORE
  603. }
  604. return SQLITE_OK
  605. }
  606. catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
  607. } {0 {}}
  608. do_test auth-1.89 {
  609. set ::authargs
  610. } {v1 {} temp {}}
  611. do_test auth-1.90 {
  612. execsql {SELECT name FROM sqlite_temp_master}
  613. } {t1}
  614. }
  615. do_test auth-1.91 {
  616. proc auth {code arg1 arg2 arg3 arg4} {
  617. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  618. return SQLITE_DENY
  619. }
  620. return SQLITE_OK
  621. }
  622. catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
  623. } {1 {not authorized}}
  624. do_test auth-1.92 {
  625. execsql {SELECT name FROM sqlite_master}
  626. } {t2}
  627. do_test auth-1.93 {
  628. proc auth {code arg1 arg2 arg3 arg4} {
  629. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  630. return SQLITE_IGNORE
  631. }
  632. return SQLITE_OK
  633. }
  634. catchsql {CREATE VIEW v1 AS SELECT a+1,b+1 FROM t2}
  635. } {0 {}}
  636. do_test auth-1.94 {
  637. execsql {SELECT name FROM sqlite_master}
  638. } {t2}
  639. ifcapable tempdb {
  640. do_test auth-1.95 {
  641. proc auth {code arg1 arg2 arg3 arg4} {
  642. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  643. return SQLITE_DENY
  644. }
  645. return SQLITE_OK
  646. }
  647. catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
  648. } {1 {not authorized}}
  649. do_test auth-1.96 {
  650. execsql {SELECT name FROM sqlite_temp_master}
  651. } {t1}
  652. do_test auth-1.97 {
  653. proc auth {code arg1 arg2 arg3 arg4} {
  654. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  655. return SQLITE_IGNORE
  656. }
  657. return SQLITE_OK
  658. }
  659. catchsql {CREATE TEMPORARY VIEW v1 AS SELECT a+1,b+1 FROM t2}
  660. } {0 {}}
  661. do_test auth-1.98 {
  662. execsql {SELECT name FROM sqlite_temp_master}
  663. } {t1}
  664. }
  665. do_test auth-1.99 {
  666. proc auth {code arg1 arg2 arg3 arg4} {
  667. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  668. return SQLITE_DENY
  669. }
  670. return SQLITE_OK
  671. }
  672. catchsql {
  673. CREATE VIEW v2 AS SELECT a+1,b+1 FROM t2;
  674. DROP VIEW v2
  675. }
  676. } {1 {not authorized}}
  677. do_test auth-1.100 {
  678. execsql {SELECT name FROM sqlite_master}
  679. } {t2 v2}
  680. do_test auth-1.101 {
  681. proc auth {code arg1 arg2 arg3 arg4} {
  682. if {$code=="SQLITE_DROP_VIEW"} {
  683. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  684. return SQLITE_DENY
  685. }
  686. return SQLITE_OK
  687. }
  688. catchsql {DROP VIEW v2}
  689. } {1 {not authorized}}
  690. do_test auth-1.102 {
  691. set ::authargs
  692. } {v2 {} main {}}
  693. do_test auth-1.103 {
  694. execsql {SELECT name FROM sqlite_master}
  695. } {t2 v2}
  696. do_test auth-1.104 {
  697. proc auth {code arg1 arg2 arg3 arg4} {
  698. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  699. return SQLITE_IGNORE
  700. }
  701. return SQLITE_OK
  702. }
  703. catchsql {DROP VIEW v2}
  704. } {0 {}}
  705. do_test auth-1.105 {
  706. execsql {SELECT name FROM sqlite_master}
  707. } {t2 v2}
  708. do_test auth-1.106 {
  709. proc auth {code arg1 arg2 arg3 arg4} {
  710. if {$code=="SQLITE_DROP_VIEW"} {
  711. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  712. return SQLITE_IGNORE
  713. }
  714. return SQLITE_OK
  715. }
  716. catchsql {DROP VIEW v2}
  717. } {0 {}}
  718. do_test auth-1.107 {
  719. set ::authargs
  720. } {v2 {} main {}}
  721. do_test auth-1.108 {
  722. execsql {SELECT name FROM sqlite_master}
  723. } {t2 v2}
  724. do_test auth-1.109 {
  725. proc auth {code arg1 arg2 arg3 arg4} {
  726. if {$code=="SQLITE_DROP_VIEW"} {
  727. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  728. return SQLITE_OK
  729. }
  730. return SQLITE_OK
  731. }
  732. catchsql {DROP VIEW v2}
  733. } {0 {}}
  734. do_test auth-1.110 {
  735. set ::authargs
  736. } {v2 {} main {}}
  737. do_test auth-1.111 {
  738. execsql {SELECT name FROM sqlite_master}
  739. } {t2}
  740. ifcapable tempdb {
  741. do_test auth-1.112 {
  742. proc auth {code arg1 arg2 arg3 arg4} {
  743. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  744. return SQLITE_DENY
  745. }
  746. return SQLITE_OK
  747. }
  748. catchsql {
  749. CREATE TEMP VIEW v1 AS SELECT a+1,b+1 FROM t1;
  750. DROP VIEW v1
  751. }
  752. } {1 {not authorized}}
  753. do_test auth-1.113 {
  754. execsql {SELECT name FROM sqlite_temp_master}
  755. } {t1 v1}
  756. do_test auth-1.114 {
  757. proc auth {code arg1 arg2 arg3 arg4} {
  758. if {$code=="SQLITE_DROP_TEMP_VIEW"} {
  759. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  760. return SQLITE_DENY
  761. }
  762. return SQLITE_OK
  763. }
  764. catchsql {DROP VIEW v1}
  765. } {1 {not authorized}}
  766. do_test auth-1.115 {
  767. set ::authargs
  768. } {v1 {} temp {}}
  769. do_test auth-1.116 {
  770. execsql {SELECT name FROM sqlite_temp_master}
  771. } {t1 v1}
  772. do_test auth-1.117 {
  773. proc auth {code arg1 arg2 arg3 arg4} {
  774. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  775. return SQLITE_IGNORE
  776. }
  777. return SQLITE_OK
  778. }
  779. catchsql {DROP VIEW v1}
  780. } {0 {}}
  781. do_test auth-1.118 {
  782. execsql {SELECT name FROM sqlite_temp_master}
  783. } {t1 v1}
  784. do_test auth-1.119 {
  785. proc auth {code arg1 arg2 arg3 arg4} {
  786. if {$code=="SQLITE_DROP_TEMP_VIEW"} {
  787. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  788. return SQLITE_IGNORE
  789. }
  790. return SQLITE_OK
  791. }
  792. catchsql {DROP VIEW v1}
  793. } {0 {}}
  794. do_test auth-1.120 {
  795. set ::authargs
  796. } {v1 {} temp {}}
  797. do_test auth-1.121 {
  798. execsql {SELECT name FROM sqlite_temp_master}
  799. } {t1 v1}
  800. do_test auth-1.122 {
  801. proc auth {code arg1 arg2 arg3 arg4} {
  802. if {$code=="SQLITE_DROP_TEMP_VIEW"} {
  803. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  804. return SQLITE_OK
  805. }
  806. return SQLITE_OK
  807. }
  808. catchsql {DROP VIEW v1}
  809. } {0 {}}
  810. do_test auth-1.123 {
  811. set ::authargs
  812. } {v1 {} temp {}}
  813. do_test auth-1.124 {
  814. execsql {SELECT name FROM sqlite_temp_master}
  815. } {t1}
  816. }
  817. } ;# ifcapable view
  818. # Test cases auth-1.125 to auth-1.176 test creating and dropping triggers.
  819. # Omit these if the library was compiled with triggers omitted.
  820. #
  821. ifcapable trigger&&tempdb {
  822. do_test auth-1.125 {
  823. proc auth {code arg1 arg2 arg3 arg4} {
  824. if {$code=="SQLITE_CREATE_TRIGGER"} {
  825. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  826. return SQLITE_DENY
  827. }
  828. return SQLITE_OK
  829. }
  830. catchsql {
  831. CREATE TRIGGER r2 DELETE on t2 BEGIN
  832. SELECT NULL;
  833. END;
  834. }
  835. } {1 {not authorized}}
  836. do_test auth-1.126 {
  837. set ::authargs
  838. } {r2 t2 main {}}
  839. do_test auth-1.127 {
  840. execsql {SELECT name FROM sqlite_master}
  841. } {t2}
  842. do_test auth-1.128 {
  843. proc auth {code arg1 arg2 arg3 arg4} {
  844. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  845. return SQLITE_DENY
  846. }
  847. return SQLITE_OK
  848. }
  849. catchsql {
  850. CREATE TRIGGER r2 DELETE on t2 BEGIN
  851. SELECT NULL;
  852. END;
  853. }
  854. } {1 {not authorized}}
  855. do_test auth-1.129 {
  856. execsql {SELECT name FROM sqlite_master}
  857. } {t2}
  858. do_test auth-1.130 {
  859. proc auth {code arg1 arg2 arg3 arg4} {
  860. if {$code=="SQLITE_CREATE_TRIGGER"} {
  861. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  862. return SQLITE_IGNORE
  863. }
  864. return SQLITE_OK
  865. }
  866. catchsql {
  867. CREATE TRIGGER r2 DELETE on t2 BEGIN
  868. SELECT NULL;
  869. END;
  870. }
  871. } {0 {}}
  872. do_test auth-1.131 {
  873. set ::authargs
  874. } {r2 t2 main {}}
  875. do_test auth-1.132 {
  876. execsql {SELECT name FROM sqlite_master}
  877. } {t2}
  878. do_test auth-1.133 {
  879. proc auth {code arg1 arg2 arg3 arg4} {
  880. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  881. return SQLITE_IGNORE
  882. }
  883. return SQLITE_OK
  884. }
  885. catchsql {
  886. CREATE TRIGGER r2 DELETE on t2 BEGIN
  887. SELECT NULL;
  888. END;
  889. }
  890. } {0 {}}
  891. do_test auth-1.134 {
  892. execsql {SELECT name FROM sqlite_master}
  893. } {t2}
  894. do_test auth-1.135 {
  895. proc auth {code arg1 arg2 arg3 arg4} {
  896. if {$code=="SQLITE_CREATE_TRIGGER"} {
  897. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  898. return SQLITE_OK
  899. }
  900. return SQLITE_OK
  901. }
  902. catchsql {
  903. CREATE TABLE tx(id);
  904. CREATE TRIGGER r2 AFTER INSERT ON t2 BEGIN
  905. INSERT INTO tx VALUES(NEW.rowid);
  906. END;
  907. }
  908. } {0 {}}
  909. do_test auth-1.136.1 {
  910. set ::authargs
  911. } {r2 t2 main {}}
  912. do_test auth-1.136.2 {
  913. execsql {
  914. SELECT name FROM sqlite_master WHERE type='trigger'
  915. }
  916. } {r2}
  917. do_test auth-1.136.3 {
  918. proc auth {code arg1 arg2 arg3 arg4} {
  919. lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
  920. return SQLITE_OK
  921. }
  922. set ::authargs {}
  923. execsql {
  924. INSERT INTO t2 VALUES(1,2,3);
  925. }
  926. set ::authargs
  927. } {SQLITE_INSERT t2 {} main {} SQLITE_INSERT tx {} main r2 SQLITE_READ t2 ROWID main r2}
  928. do_test auth-1.136.4 {
  929. execsql {
  930. SELECT * FROM tx;
  931. }
  932. } {3}
  933. do_test auth-1.137 {
  934. execsql {SELECT name FROM sqlite_master}
  935. } {t2 tx r2}
  936. do_test auth-1.138 {
  937. proc auth {code arg1 arg2 arg3 arg4} {
  938. if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
  939. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  940. return SQLITE_DENY
  941. }
  942. return SQLITE_OK
  943. }
  944. catchsql {
  945. CREATE TRIGGER r1 DELETE on t1 BEGIN
  946. SELECT NULL;
  947. END;
  948. }
  949. } {1 {not authorized}}
  950. do_test auth-1.139 {
  951. set ::authargs
  952. } {r1 t1 temp {}}
  953. do_test auth-1.140 {
  954. execsql {SELECT name FROM sqlite_temp_master}
  955. } {t1}
  956. do_test auth-1.141 {
  957. proc auth {code arg1 arg2 arg3 arg4} {
  958. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  959. return SQLITE_DENY
  960. }
  961. return SQLITE_OK
  962. }
  963. catchsql {
  964. CREATE TRIGGER r1 DELETE on t1 BEGIN
  965. SELECT NULL;
  966. END;
  967. }
  968. } {1 {not authorized}}
  969. do_test auth-1.142 {
  970. execsql {SELECT name FROM sqlite_temp_master}
  971. } {t1}
  972. do_test auth-1.143 {
  973. proc auth {code arg1 arg2 arg3 arg4} {
  974. if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
  975. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  976. return SQLITE_IGNORE
  977. }
  978. return SQLITE_OK
  979. }
  980. catchsql {
  981. CREATE TRIGGER r1 DELETE on t1 BEGIN
  982. SELECT NULL;
  983. END;
  984. }
  985. } {0 {}}
  986. do_test auth-1.144 {
  987. set ::authargs
  988. } {r1 t1 temp {}}
  989. do_test auth-1.145 {
  990. execsql {SELECT name FROM sqlite_temp_master}
  991. } {t1}
  992. do_test auth-1.146 {
  993. proc auth {code arg1 arg2 arg3 arg4} {
  994. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  995. return SQLITE_IGNORE
  996. }
  997. return SQLITE_OK
  998. }
  999. catchsql {
  1000. CREATE TRIGGER r1 DELETE on t1 BEGIN
  1001. SELECT NULL;
  1002. END;
  1003. }
  1004. } {0 {}}
  1005. do_test auth-1.147 {
  1006. execsql {SELECT name FROM sqlite_temp_master}
  1007. } {t1}
  1008. do_test auth-1.148 {
  1009. proc auth {code arg1 arg2 arg3 arg4} {
  1010. if {$code=="SQLITE_CREATE_TEMP_TRIGGER"} {
  1011. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1012. return SQLITE_OK
  1013. }
  1014. return SQLITE_OK
  1015. }
  1016. catchsql {
  1017. CREATE TRIGGER r1 DELETE on t1 BEGIN
  1018. SELECT NULL;
  1019. END;
  1020. }
  1021. } {0 {}}
  1022. do_test auth-1.149 {
  1023. set ::authargs
  1024. } {r1 t1 temp {}}
  1025. do_test auth-1.150 {
  1026. execsql {SELECT name FROM sqlite_temp_master}
  1027. } {t1 r1}
  1028. do_test auth-1.151 {
  1029. proc auth {code arg1 arg2 arg3 arg4} {
  1030. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  1031. return SQLITE_DENY
  1032. }
  1033. return SQLITE_OK
  1034. }
  1035. catchsql {DROP TRIGGER r2}
  1036. } {1 {not authorized}}
  1037. do_test auth-1.152 {
  1038. execsql {SELECT name FROM sqlite_master}
  1039. } {t2 tx r2}
  1040. do_test auth-1.153 {
  1041. proc auth {code arg1 arg2 arg3 arg4} {
  1042. if {$code=="SQLITE_DROP_TRIGGER"} {
  1043. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1044. return SQLITE_DENY
  1045. }
  1046. return SQLITE_OK
  1047. }
  1048. catchsql {DROP TRIGGER r2}
  1049. } {1 {not authorized}}
  1050. do_test auth-1.154 {
  1051. set ::authargs
  1052. } {r2 t2 main {}}
  1053. do_test auth-1.155 {
  1054. execsql {SELECT name FROM sqlite_master}
  1055. } {t2 tx r2}
  1056. do_test auth-1.156 {
  1057. proc auth {code arg1 arg2 arg3 arg4} {
  1058. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  1059. return SQLITE_IGNORE
  1060. }
  1061. return SQLITE_OK
  1062. }
  1063. catchsql {DROP TRIGGER r2}
  1064. } {0 {}}
  1065. do_test auth-1.157 {
  1066. execsql {SELECT name FROM sqlite_master}
  1067. } {t2 tx r2}
  1068. do_test auth-1.158 {
  1069. proc auth {code arg1 arg2 arg3 arg4} {
  1070. if {$code=="SQLITE_DROP_TRIGGER"} {
  1071. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1072. return SQLITE_IGNORE
  1073. }
  1074. return SQLITE_OK
  1075. }
  1076. catchsql {DROP TRIGGER r2}
  1077. } {0 {}}
  1078. do_test auth-1.159 {
  1079. set ::authargs
  1080. } {r2 t2 main {}}
  1081. do_test auth-1.160 {
  1082. execsql {SELECT name FROM sqlite_master}
  1083. } {t2 tx r2}
  1084. do_test auth-1.161 {
  1085. proc auth {code arg1 arg2 arg3 arg4} {
  1086. if {$code=="SQLITE_DROP_TRIGGER"} {
  1087. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1088. return SQLITE_OK
  1089. }
  1090. return SQLITE_OK
  1091. }
  1092. catchsql {DROP TRIGGER r2}
  1093. } {0 {}}
  1094. do_test auth-1.162 {
  1095. set ::authargs
  1096. } {r2 t2 main {}}
  1097. do_test auth-1.163 {
  1098. execsql {
  1099. DROP TABLE tx;
  1100. DELETE FROM t2 WHERE a=1 AND b=2 AND c=3;
  1101. SELECT name FROM sqlite_master;
  1102. }
  1103. } {t2}
  1104. do_test auth-1.164 {
  1105. proc auth {code arg1 arg2 arg3 arg4} {
  1106. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  1107. return SQLITE_DENY
  1108. }
  1109. return SQLITE_OK
  1110. }
  1111. catchsql {DROP TRIGGER r1}
  1112. } {1 {not authorized}}
  1113. do_test auth-1.165 {
  1114. execsql {SELECT name FROM sqlite_temp_master}
  1115. } {t1 r1}
  1116. do_test auth-1.166 {
  1117. proc auth {code arg1 arg2 arg3 arg4} {
  1118. if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
  1119. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1120. return SQLITE_DENY
  1121. }
  1122. return SQLITE_OK
  1123. }
  1124. catchsql {DROP TRIGGER r1}
  1125. } {1 {not authorized}}
  1126. do_test auth-1.167 {
  1127. set ::authargs
  1128. } {r1 t1 temp {}}
  1129. do_test auth-1.168 {
  1130. execsql {SELECT name FROM sqlite_temp_master}
  1131. } {t1 r1}
  1132. do_test auth-1.169 {
  1133. proc auth {code arg1 arg2 arg3 arg4} {
  1134. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  1135. return SQLITE_IGNORE
  1136. }
  1137. return SQLITE_OK
  1138. }
  1139. catchsql {DROP TRIGGER r1}
  1140. } {0 {}}
  1141. do_test auth-1.170 {
  1142. execsql {SELECT name FROM sqlite_temp_master}
  1143. } {t1 r1}
  1144. do_test auth-1.171 {
  1145. proc auth {code arg1 arg2 arg3 arg4} {
  1146. if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
  1147. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1148. return SQLITE_IGNORE
  1149. }
  1150. return SQLITE_OK
  1151. }
  1152. catchsql {DROP TRIGGER r1}
  1153. } {0 {}}
  1154. do_test auth-1.172 {
  1155. set ::authargs
  1156. } {r1 t1 temp {}}
  1157. do_test auth-1.173 {
  1158. execsql {SELECT name FROM sqlite_temp_master}
  1159. } {t1 r1}
  1160. do_test auth-1.174 {
  1161. proc auth {code arg1 arg2 arg3 arg4} {
  1162. if {$code=="SQLITE_DROP_TEMP_TRIGGER"} {
  1163. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1164. return SQLITE_OK
  1165. }
  1166. return SQLITE_OK
  1167. }
  1168. catchsql {DROP TRIGGER r1}
  1169. } {0 {}}
  1170. do_test auth-1.175 {
  1171. set ::authargs
  1172. } {r1 t1 temp {}}
  1173. do_test auth-1.176 {
  1174. execsql {SELECT name FROM sqlite_temp_master}
  1175. } {t1}
  1176. } ;# ifcapable trigger
  1177. do_test auth-1.177 {
  1178. proc auth {code arg1 arg2 arg3 arg4} {
  1179. if {$code=="SQLITE_CREATE_INDEX"} {
  1180. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1181. return SQLITE_DENY
  1182. }
  1183. return SQLITE_OK
  1184. }
  1185. catchsql {CREATE INDEX i2 ON t2(a)}
  1186. } {1 {not authorized}}
  1187. do_test auth-1.178 {
  1188. set ::authargs
  1189. } {i2 t2 main {}}
  1190. do_test auth-1.179 {
  1191. execsql {SELECT name FROM sqlite_master}
  1192. } {t2}
  1193. do_test auth-1.180 {
  1194. proc auth {code arg1 arg2 arg3 arg4} {
  1195. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  1196. return SQLITE_DENY
  1197. }
  1198. return SQLITE_OK
  1199. }
  1200. catchsql {CREATE INDEX i2 ON t2(a)}
  1201. } {1 {not authorized}}
  1202. do_test auth-1.181 {
  1203. execsql {SELECT name FROM sqlite_master}
  1204. } {t2}
  1205. do_test auth-1.182 {
  1206. proc auth {code arg1 arg2 arg3 arg4} {
  1207. if {$code=="SQLITE_CREATE_INDEX"} {
  1208. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1209. return SQLITE_IGNORE
  1210. }
  1211. return SQLITE_OK
  1212. }
  1213. catchsql {CREATE INDEX i2 ON t2(b)}
  1214. } {0 {}}
  1215. do_test auth-1.183 {
  1216. set ::authargs
  1217. } {i2 t2 main {}}
  1218. do_test auth-1.184 {
  1219. execsql {SELECT name FROM sqlite_master}
  1220. } {t2}
  1221. do_test auth-1.185 {
  1222. proc auth {code arg1 arg2 arg3 arg4} {
  1223. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_master"} {
  1224. return SQLITE_IGNORE
  1225. }
  1226. return SQLITE_OK
  1227. }
  1228. catchsql {CREATE INDEX i2 ON t2(b)}
  1229. } {0 {}}
  1230. do_test auth-1.186 {
  1231. execsql {SELECT name FROM sqlite_master}
  1232. } {t2}
  1233. do_test auth-1.187 {
  1234. proc auth {code arg1 arg2 arg3 arg4} {
  1235. if {$code=="SQLITE_CREATE_INDEX"} {
  1236. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1237. return SQLITE_OK
  1238. }
  1239. return SQLITE_OK
  1240. }
  1241. catchsql {CREATE INDEX i2 ON t2(a)}
  1242. } {0 {}}
  1243. do_test auth-1.188 {
  1244. set ::authargs
  1245. } {i2 t2 main {}}
  1246. do_test auth-1.189 {
  1247. execsql {SELECT name FROM sqlite_master}
  1248. } {t2 i2}
  1249. ifcapable tempdb {
  1250. do_test auth-1.190 {
  1251. proc auth {code arg1 arg2 arg3 arg4} {
  1252. if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
  1253. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1254. return SQLITE_DENY
  1255. }
  1256. return SQLITE_OK
  1257. }
  1258. catchsql {CREATE INDEX i1 ON t1(a)}
  1259. } {1 {not authorized}}
  1260. do_test auth-1.191 {
  1261. set ::authargs
  1262. } {i1 t1 temp {}}
  1263. do_test auth-1.192 {
  1264. execsql {SELECT name FROM sqlite_temp_master}
  1265. } {t1}
  1266. do_test auth-1.193 {
  1267. proc auth {code arg1 arg2 arg3 arg4} {
  1268. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  1269. return SQLITE_DENY
  1270. }
  1271. return SQLITE_OK
  1272. }
  1273. catchsql {CREATE INDEX i1 ON t1(b)}
  1274. } {1 {not authorized}}
  1275. do_test auth-1.194 {
  1276. execsql {SELECT name FROM sqlite_temp_master}
  1277. } {t1}
  1278. do_test auth-1.195 {
  1279. proc auth {code arg1 arg2 arg3 arg4} {
  1280. if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
  1281. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1282. return SQLITE_IGNORE
  1283. }
  1284. return SQLITE_OK
  1285. }
  1286. catchsql {CREATE INDEX i1 ON t1(b)}
  1287. } {0 {}}
  1288. do_test auth-1.196 {
  1289. set ::authargs
  1290. } {i1 t1 temp {}}
  1291. do_test auth-1.197 {
  1292. execsql {SELECT name FROM sqlite_temp_master}
  1293. } {t1}
  1294. do_test auth-1.198 {
  1295. proc auth {code arg1 arg2 arg3 arg4} {
  1296. if {$code=="SQLITE_INSERT" && $arg1=="sqlite_temp_master"} {
  1297. return SQLITE_IGNORE
  1298. }
  1299. return SQLITE_OK
  1300. }
  1301. catchsql {CREATE INDEX i1 ON t1(c)}
  1302. } {0 {}}
  1303. do_test auth-1.199 {
  1304. execsql {SELECT name FROM sqlite_temp_master}
  1305. } {t1}
  1306. do_test auth-1.200 {
  1307. proc auth {code arg1 arg2 arg3 arg4} {
  1308. if {$code=="SQLITE_CREATE_TEMP_INDEX"} {
  1309. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1310. return SQLITE_OK
  1311. }
  1312. return SQLITE_OK
  1313. }
  1314. catchsql {CREATE INDEX i1 ON t1(a)}
  1315. } {0 {}}
  1316. do_test auth-1.201 {
  1317. set ::authargs
  1318. } {i1 t1 temp {}}
  1319. do_test auth-1.202 {
  1320. execsql {SELECT name FROM sqlite_temp_master}
  1321. } {t1 i1}
  1322. }
  1323. do_test auth-1.203 {
  1324. proc auth {code arg1 arg2 arg3 arg4} {
  1325. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  1326. return SQLITE_DENY
  1327. }
  1328. return SQLITE_OK
  1329. }
  1330. catchsql {DROP INDEX i2}
  1331. } {1 {not authorized}}
  1332. do_test auth-1.204 {
  1333. execsql {SELECT name FROM sqlite_master}
  1334. } {t2 i2}
  1335. do_test auth-1.205 {
  1336. proc auth {code arg1 arg2 arg3 arg4} {
  1337. if {$code=="SQLITE_DROP_INDEX"} {
  1338. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1339. return SQLITE_DENY
  1340. }
  1341. return SQLITE_OK
  1342. }
  1343. catchsql {DROP INDEX i2}
  1344. } {1 {not authorized}}
  1345. do_test auth-1.206 {
  1346. set ::authargs
  1347. } {i2 t2 main {}}
  1348. do_test auth-1.207 {
  1349. execsql {SELECT name FROM sqlite_master}
  1350. } {t2 i2}
  1351. do_test auth-1.208 {
  1352. proc auth {code arg1 arg2 arg3 arg4} {
  1353. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_master"} {
  1354. return SQLITE_IGNORE
  1355. }
  1356. return SQLITE_OK
  1357. }
  1358. catchsql {DROP INDEX i2}
  1359. } {0 {}}
  1360. do_test auth-1.209 {
  1361. execsql {SELECT name FROM sqlite_master}
  1362. } {t2 i2}
  1363. do_test auth-1.210 {
  1364. proc auth {code arg1 arg2 arg3 arg4} {
  1365. if {$code=="SQLITE_DROP_INDEX"} {
  1366. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1367. return SQLITE_IGNORE
  1368. }
  1369. return SQLITE_OK
  1370. }
  1371. catchsql {DROP INDEX i2}
  1372. } {0 {}}
  1373. do_test auth-1.211 {
  1374. set ::authargs
  1375. } {i2 t2 main {}}
  1376. do_test auth-1.212 {
  1377. execsql {SELECT name FROM sqlite_master}
  1378. } {t2 i2}
  1379. do_test auth-1.213 {
  1380. proc auth {code arg1 arg2 arg3 arg4} {
  1381. if {$code=="SQLITE_DROP_INDEX"} {
  1382. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1383. return SQLITE_OK
  1384. }
  1385. return SQLITE_OK
  1386. }
  1387. catchsql {DROP INDEX i2}
  1388. } {0 {}}
  1389. do_test auth-1.214 {
  1390. set ::authargs
  1391. } {i2 t2 main {}}
  1392. do_test auth-1.215 {
  1393. execsql {SELECT name FROM sqlite_master}
  1394. } {t2}
  1395. ifcapable tempdb {
  1396. do_test auth-1.216 {
  1397. proc auth {code arg1 arg2 arg3 arg4} {
  1398. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  1399. return SQLITE_DENY
  1400. }
  1401. return SQLITE_OK
  1402. }
  1403. catchsql {DROP INDEX i1}
  1404. } {1 {not authorized}}
  1405. do_test auth-1.217 {
  1406. execsql {SELECT name FROM sqlite_temp_master}
  1407. } {t1 i1}
  1408. do_test auth-1.218 {
  1409. proc auth {code arg1 arg2 arg3 arg4} {
  1410. if {$code=="SQLITE_DROP_TEMP_INDEX"} {
  1411. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1412. return SQLITE_DENY
  1413. }
  1414. return SQLITE_OK
  1415. }
  1416. catchsql {DROP INDEX i1}
  1417. } {1 {not authorized}}
  1418. do_test auth-1.219 {
  1419. set ::authargs
  1420. } {i1 t1 temp {}}
  1421. do_test auth-1.220 {
  1422. execsql {SELECT name FROM sqlite_temp_master}
  1423. } {t1 i1}
  1424. do_test auth-1.221 {
  1425. proc auth {code arg1 arg2 arg3 arg4} {
  1426. if {$code=="SQLITE_DELETE" && $arg1=="sqlite_temp_master"} {
  1427. return SQLITE_IGNORE
  1428. }
  1429. return SQLITE_OK
  1430. }
  1431. catchsql {DROP INDEX i1}
  1432. } {0 {}}
  1433. do_test auth-1.222 {
  1434. execsql {SELECT name FROM sqlite_temp_master}
  1435. } {t1 i1}
  1436. do_test auth-1.223 {
  1437. proc auth {code arg1 arg2 arg3 arg4} {
  1438. if {$code=="SQLITE_DROP_TEMP_INDEX"} {
  1439. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1440. return SQLITE_IGNORE
  1441. }
  1442. return SQLITE_OK
  1443. }
  1444. catchsql {DROP INDEX i1}
  1445. } {0 {}}
  1446. do_test auth-1.224 {
  1447. set ::authargs
  1448. } {i1 t1 temp {}}
  1449. do_test auth-1.225 {
  1450. execsql {SELECT name FROM sqlite_temp_master}
  1451. } {t1 i1}
  1452. do_test auth-1.226 {
  1453. proc auth {code arg1 arg2 arg3 arg4} {
  1454. if {$code=="SQLITE_DROP_TEMP_INDEX"} {
  1455. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1456. return SQLITE_OK
  1457. }
  1458. return SQLITE_OK
  1459. }
  1460. catchsql {DROP INDEX i1}
  1461. } {0 {}}
  1462. do_test auth-1.227 {
  1463. set ::authargs
  1464. } {i1 t1 temp {}}
  1465. do_test auth-1.228 {
  1466. execsql {SELECT name FROM sqlite_temp_master}
  1467. } {t1}
  1468. }
  1469. do_test auth-1.229 {
  1470. proc auth {code arg1 arg2 arg3 arg4} {
  1471. if {$code=="SQLITE_PRAGMA"} {
  1472. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1473. return SQLITE_DENY
  1474. }
  1475. return SQLITE_OK
  1476. }
  1477. catchsql {PRAGMA full_column_names=on}
  1478. } {1 {not authorized}}
  1479. do_test auth-1.230 {
  1480. set ::authargs
  1481. } {full_column_names on {} {}}
  1482. do_test auth-1.231 {
  1483. execsql2 {SELECT a FROM t2}
  1484. } {a 11 a 7}
  1485. do_test auth-1.232 {
  1486. proc auth {code arg1 arg2 arg3 arg4} {
  1487. if {$code=="SQLITE_PRAGMA"} {
  1488. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1489. return SQLITE_IGNORE
  1490. }
  1491. return SQLITE_OK
  1492. }
  1493. catchsql {PRAGMA full_column_names=on}
  1494. } {0 {}}
  1495. do_test auth-1.233 {
  1496. set ::authargs
  1497. } {full_column_names on {} {}}
  1498. do_test auth-1.234 {
  1499. execsql2 {SELECT a FROM t2}
  1500. } {a 11 a 7}
  1501. do_test auth-1.235 {
  1502. proc auth {code arg1 arg2 arg3 arg4} {
  1503. if {$code=="SQLITE_PRAGMA"} {
  1504. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1505. return SQLITE_OK
  1506. }
  1507. return SQLITE_OK
  1508. }
  1509. catchsql {PRAGMA full_column_names=on}
  1510. } {0 {}}
  1511. do_test auth-1.236 {
  1512. execsql2 {SELECT a FROM t2}
  1513. } {t2.a 11 t2.a 7}
  1514. do_test auth-1.237 {
  1515. proc auth {code arg1 arg2 arg3 arg4} {
  1516. if {$code=="SQLITE_PRAGMA"} {
  1517. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1518. return SQLITE_OK
  1519. }
  1520. return SQLITE_OK
  1521. }
  1522. catchsql {PRAGMA full_column_names=OFF}
  1523. } {0 {}}
  1524. do_test auth-1.238 {
  1525. set ::authargs
  1526. } {full_column_names OFF {} {}}
  1527. do_test auth-1.239 {
  1528. execsql2 {SELECT a FROM t2}
  1529. } {a 11 a 7}
  1530. do_test auth-1.240 {
  1531. proc auth {code arg1 arg2 arg3 arg4} {
  1532. if {$code=="SQLITE_TRANSACTION"} {
  1533. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1534. return SQLITE_DENY
  1535. }
  1536. return SQLITE_OK
  1537. }
  1538. catchsql {BEGIN}
  1539. } {1 {not authorized}}
  1540. do_test auth-1.241 {
  1541. set ::authargs
  1542. } {BEGIN {} {} {}}
  1543. do_test auth-1.242 {
  1544. proc auth {code arg1 arg2 arg3 arg4} {
  1545. if {$code=="SQLITE_TRANSACTION" && $arg1!="BEGIN"} {
  1546. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1547. return SQLITE_DENY
  1548. }
  1549. return SQLITE_OK
  1550. }
  1551. catchsql {BEGIN; INSERT INTO t2 VALUES(44,55,66); COMMIT}
  1552. } {1 {not authorized}}
  1553. do_test auth-1.243 {
  1554. set ::authargs
  1555. } {COMMIT {} {} {}}
  1556. do_test auth-1.244 {
  1557. execsql {SELECT * FROM t2}
  1558. } {11 2 33 7 8 9 44 55 66}
  1559. do_test auth-1.245 {
  1560. catchsql {ROLLBACK}
  1561. } {1 {not authorized}}
  1562. do_test auth-1.246 {
  1563. set ::authargs
  1564. } {ROLLBACK {} {} {}}
  1565. do_test auth-1.247 {
  1566. catchsql {END TRANSACTION}
  1567. } {1 {not authorized}}
  1568. do_test auth-1.248 {
  1569. set ::authargs
  1570. } {COMMIT {} {} {}}
  1571. do_test auth-1.249 {
  1572. db authorizer {}
  1573. catchsql {ROLLBACK}
  1574. } {0 {}}
  1575. do_test auth-1.250 {
  1576. execsql {SELECT * FROM t2}
  1577. } {11 2 33 7 8 9}
  1578. # ticket #340 - authorization for ATTACH and DETACH.
  1579. #
  1580. ifcapable attach {
  1581. do_test auth-1.251 {
  1582. db authorizer ::auth
  1583. proc auth {code arg1 arg2 arg3 arg4} {
  1584. if {$code=="SQLITE_ATTACH"} {
  1585. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1586. }
  1587. return SQLITE_OK
  1588. }
  1589. catchsql {
  1590. ATTACH DATABASE ':memory:' AS test1
  1591. }
  1592. } {0 {}}
  1593. do_test auth-1.252a {
  1594. set ::authargs
  1595. } {:memory: {} {} {}}
  1596. do_test auth-1.252b {
  1597. db eval {DETACH test1}
  1598. set ::attachfilename :memory:
  1599. db eval {ATTACH $::attachfilename AS test1}
  1600. set ::authargs
  1601. } {{} {} {} {}}
  1602. do_test auth-1.252c {
  1603. db eval {DETACH test1}
  1604. db eval {ATTACH ':mem' || 'ory:' AS test1}
  1605. set ::authargs
  1606. } {{} {} {} {}}
  1607. do_test auth-1.253 {
  1608. catchsql {DETACH DATABASE test1}
  1609. proc auth {code arg1 arg2 arg3 arg4} {
  1610. if {$code=="SQLITE_ATTACH"} {
  1611. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1612. return SQLITE_DENY
  1613. }
  1614. return SQLITE_OK
  1615. }
  1616. catchsql {
  1617. ATTACH DATABASE ':memory:' AS test1;
  1618. }
  1619. } {1 {not authorized}}
  1620. do_test auth-1.254 {
  1621. lindex [execsql {PRAGMA database_list}] 7
  1622. } {}
  1623. do_test auth-1.255 {
  1624. catchsql {DETACH DATABASE test1}
  1625. proc auth {code arg1 arg2 arg3 arg4} {
  1626. if {$code=="SQLITE_ATTACH"} {
  1627. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1628. return SQLITE_IGNORE
  1629. }
  1630. return SQLITE_OK
  1631. }
  1632. catchsql {
  1633. ATTACH DATABASE ':memory:' AS test1;
  1634. }
  1635. } {0 {}}
  1636. do_test auth-1.256 {
  1637. lindex [execsql {PRAGMA database_list}] 7
  1638. } {}
  1639. do_test auth-1.257 {
  1640. proc auth {code arg1 arg2 arg3 arg4} {
  1641. if {$code=="SQLITE_DETACH"} {
  1642. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1643. return SQLITE_OK
  1644. }
  1645. return SQLITE_OK
  1646. }
  1647. execsql {ATTACH DATABASE ':memory:' AS test1}
  1648. catchsql {
  1649. DETACH DATABASE test1;
  1650. }
  1651. } {0 {}}
  1652. do_test auth-1.258 {
  1653. lindex [execsql {PRAGMA database_list}] 7
  1654. } {}
  1655. do_test auth-1.259 {
  1656. execsql {ATTACH DATABASE ':memory:' AS test1}
  1657. proc auth {code arg1 arg2 arg3 arg4} {
  1658. if {$code=="SQLITE_DETACH"} {
  1659. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1660. return SQLITE_IGNORE
  1661. }
  1662. return SQLITE_OK
  1663. }
  1664. catchsql {
  1665. DETACH DATABASE test1;
  1666. }
  1667. } {0 {}}
  1668. ifcapable tempdb {
  1669. ifcapable schema_pragmas {
  1670. do_test auth-1.260 {
  1671. lindex [execsql {PRAGMA database_list}] 7
  1672. } {test1}
  1673. } ;# ifcapable schema_pragmas
  1674. do_test auth-1.261 {
  1675. proc auth {code arg1 arg2 arg3 arg4} {
  1676. if {$code=="SQLITE_DETACH"} {
  1677. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1678. return SQLITE_DENY
  1679. }
  1680. return SQLITE_OK
  1681. }
  1682. catchsql {
  1683. DETACH DATABASE test1;
  1684. }
  1685. } {1 {not authorized}}
  1686. ifcapable schema_pragmas {
  1687. do_test auth-1.262 {
  1688. lindex [execsql {PRAGMA database_list}] 7
  1689. } {test1}
  1690. } ;# ifcapable schema_pragmas
  1691. db authorizer {}
  1692. execsql {DETACH DATABASE test1}
  1693. db authorizer ::auth
  1694. # Authorization for ALTER TABLE. These tests are omitted if the library
  1695. # was built without ALTER TABLE support.
  1696. ifcapable altertable {
  1697. do_test auth-1.263 {
  1698. proc auth {code arg1 arg2 arg3 arg4} {
  1699. if {$code=="SQLITE_ALTER_TABLE"} {
  1700. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1701. return SQLITE_OK
  1702. }
  1703. return SQLITE_OK
  1704. }
  1705. catchsql {
  1706. ALTER TABLE t1 RENAME TO t1x
  1707. }
  1708. } {0 {}}
  1709. do_test auth-1.264 {
  1710. execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
  1711. } {t1x}
  1712. do_test auth-1.265 {
  1713. set authargs
  1714. } {temp t1 {} {}}
  1715. do_test auth-1.266 {
  1716. proc auth {code arg1 arg2 arg3 arg4} {
  1717. if {$code=="SQLITE_ALTER_TABLE"} {
  1718. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1719. return SQLITE_IGNORE
  1720. }
  1721. return SQLITE_OK
  1722. }
  1723. catchsql {
  1724. ALTER TABLE t1x RENAME TO t1
  1725. }
  1726. } {0 {}}
  1727. do_test auth-1.267 {
  1728. execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
  1729. } {t1x}
  1730. do_test auth-1.268 {
  1731. set authargs
  1732. } {temp t1x {} {}}
  1733. do_test auth-1.269 {
  1734. proc auth {code arg1 arg2 arg3 arg4} {
  1735. if {$code=="SQLITE_ALTER_TABLE"} {
  1736. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1737. return SQLITE_DENY
  1738. }
  1739. return SQLITE_OK
  1740. }
  1741. catchsql {
  1742. ALTER TABLE t1x RENAME TO t1
  1743. }
  1744. } {1 {not authorized}}
  1745. do_test auth-1.270 {
  1746. execsql {SELECT name FROM sqlite_temp_master WHERE type='table'}
  1747. } {t1x}
  1748. do_test auth-1.271 {
  1749. set authargs
  1750. } {temp t1x {} {}}
  1751. } ;# ifcapable altertable
  1752. } else {
  1753. db authorizer {}
  1754. db eval {
  1755. DETACH DATABASE test1;
  1756. }
  1757. }
  1758. }
  1759. ifcapable altertable {
  1760. db authorizer {}
  1761. catchsql {ALTER TABLE t1x RENAME TO t1}
  1762. db authorizer ::auth
  1763. do_test auth-1.272 {
  1764. proc auth {code arg1 arg2 arg3 arg4} {
  1765. if {$code=="SQLITE_ALTER_TABLE"} {
  1766. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1767. return SQLITE_OK
  1768. }
  1769. return SQLITE_OK
  1770. }
  1771. catchsql {
  1772. ALTER TABLE t2 RENAME TO t2x
  1773. }
  1774. } {0 {}}
  1775. do_test auth-1.273 {
  1776. execsql {SELECT name FROM sqlite_master WHERE type='table'}
  1777. } {t2x}
  1778. do_test auth-1.274 {
  1779. set authargs
  1780. } {main t2 {} {}}
  1781. do_test auth-1.275 {
  1782. proc auth {code arg1 arg2 arg3 arg4} {
  1783. if {$code=="SQLITE_ALTER_TABLE"} {
  1784. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1785. return SQLITE_IGNORE
  1786. }
  1787. return SQLITE_OK
  1788. }
  1789. catchsql {
  1790. ALTER TABLE t2x RENAME TO t2
  1791. }
  1792. } {0 {}}
  1793. do_test auth-1.276 {
  1794. execsql {SELECT name FROM sqlite_master WHERE type='table'}
  1795. } {t2x}
  1796. do_test auth-1.277 {
  1797. set authargs
  1798. } {main t2x {} {}}
  1799. do_test auth-1.278 {
  1800. proc auth {code arg1 arg2 arg3 arg4} {
  1801. if {$code=="SQLITE_ALTER_TABLE"} {
  1802. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1803. return SQLITE_DENY
  1804. }
  1805. return SQLITE_OK
  1806. }
  1807. catchsql {
  1808. ALTER TABLE t2x RENAME TO t2
  1809. }
  1810. } {1 {not authorized}}
  1811. do_test auth-1.279 {
  1812. execsql {SELECT name FROM sqlite_master WHERE type='table'}
  1813. } {t2x}
  1814. do_test auth-1.280 {
  1815. set authargs
  1816. } {main t2x {} {}}
  1817. db authorizer {}
  1818. catchsql {ALTER TABLE t2x RENAME TO t2}
  1819. } ;# ifcapable altertable
  1820. # Test the authorization callbacks for the REINDEX command.
  1821. ifcapable reindex {
  1822. proc auth {code args} {
  1823. if {$code=="SQLITE_REINDEX"} {
  1824. set ::authargs [concat $::authargs $args]
  1825. }
  1826. return SQLITE_OK
  1827. }
  1828. db authorizer auth
  1829. do_test auth-1.281 {
  1830. execsql {
  1831. CREATE TABLE t3(a PRIMARY KEY, b, c);
  1832. CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
  1833. CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
  1834. }
  1835. } {}
  1836. do_test auth-1.282 {
  1837. set ::authargs {}
  1838. execsql {
  1839. REINDEX t3_idx1;
  1840. }
  1841. set ::authargs
  1842. } {t3_idx1 {} main {}}
  1843. do_test auth-1.283 {
  1844. set ::authargs {}
  1845. execsql {
  1846. REINDEX BINARY;
  1847. }
  1848. set ::authargs
  1849. } {t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
  1850. do_test auth-1.284 {
  1851. set ::authargs {}
  1852. execsql {
  1853. REINDEX NOCASE;
  1854. }
  1855. set ::authargs
  1856. } {t3_idx2 {} main {}}
  1857. do_test auth-1.285 {
  1858. set ::authargs {}
  1859. execsql {
  1860. REINDEX t3;
  1861. }
  1862. set ::authargs
  1863. } {t3_idx2 {} main {} t3_idx1 {} main {} sqlite_autoindex_t3_1 {} main {}}
  1864. do_test auth-1.286 {
  1865. execsql {
  1866. DROP TABLE t3;
  1867. }
  1868. } {}
  1869. ifcapable tempdb {
  1870. do_test auth-1.287 {
  1871. execsql {
  1872. CREATE TEMP TABLE t3(a PRIMARY KEY, b, c);
  1873. CREATE INDEX t3_idx1 ON t3(c COLLATE BINARY);
  1874. CREATE INDEX t3_idx2 ON t3(b COLLATE NOCASE);
  1875. }
  1876. } {}
  1877. do_test auth-1.288 {
  1878. set ::authargs {}
  1879. execsql {
  1880. REINDEX temp.t3_idx1;
  1881. }
  1882. set ::authargs
  1883. } {t3_idx1 {} temp {}}
  1884. do_test auth-1.289 {
  1885. set ::authargs {}
  1886. execsql {
  1887. REINDEX BINARY;
  1888. }
  1889. set ::authargs
  1890. } {t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
  1891. do_test auth-1.290 {
  1892. set ::authargs {}
  1893. execsql {
  1894. REINDEX NOCASE;
  1895. }
  1896. set ::authargs
  1897. } {t3_idx2 {} temp {}}
  1898. do_test auth-1.291 {
  1899. set ::authargs {}
  1900. execsql {
  1901. REINDEX temp.t3;
  1902. }
  1903. set ::authargs
  1904. } {t3_idx2 {} temp {} t3_idx1 {} temp {} sqlite_autoindex_t3_1 {} temp {}}
  1905. proc auth {code args} {
  1906. if {$code=="SQLITE_REINDEX"} {
  1907. set ::authargs [concat $::authargs $args]
  1908. return SQLITE_DENY
  1909. }
  1910. return SQLITE_OK
  1911. }
  1912. do_test auth-1.292 {
  1913. set ::authargs {}
  1914. catchsql {
  1915. REINDEX temp.t3;
  1916. }
  1917. } {1 {not authorized}}
  1918. do_test auth-1.293 {
  1919. execsql {
  1920. DROP TABLE t3;
  1921. }
  1922. } {}
  1923. }
  1924. } ;# ifcapable reindex
  1925. ifcapable analyze {
  1926. proc auth {code args} {
  1927. if {$code=="SQLITE_ANALYZE"} {
  1928. set ::authargs [concat $::authargs $args]
  1929. }
  1930. return SQLITE_OK
  1931. }
  1932. do_test auth-1.294 {
  1933. set ::authargs {}
  1934. execsql {
  1935. CREATE TABLE t4(a,b,c);
  1936. CREATE INDEX t4i1 ON t4(a);
  1937. CREATE INDEX t4i2 ON t4(b,a,c);
  1938. INSERT INTO t4 VALUES(1,2,3);
  1939. ANALYZE;
  1940. }
  1941. set ::authargs
  1942. } {t4 {} main {} t2 {} main {}}
  1943. do_test auth-1.295 {
  1944. execsql {
  1945. SELECT count(*) FROM sqlite_stat1;
  1946. }
  1947. } 3
  1948. proc auth {code args} {
  1949. if {$code=="SQLITE_ANALYZE"} {
  1950. set ::authargs [concat $::authargs $args]
  1951. return SQLITE_DENY
  1952. }
  1953. return SQLITE_OK
  1954. }
  1955. do_test auth-1.296 {
  1956. set ::authargs {}
  1957. catchsql {
  1958. ANALYZE;
  1959. }
  1960. } {1 {not authorized}}
  1961. do_test auth-1.297 {
  1962. execsql {
  1963. SELECT count(*) FROM sqlite_stat1;
  1964. }
  1965. } 3
  1966. } ;# ifcapable analyze
  1967. # Authorization for ALTER TABLE ADD COLUMN.
  1968. # These tests are omitted if the library
  1969. # was built without ALTER TABLE support.
  1970. ifcapable {altertable} {
  1971. do_test auth-1.300 {
  1972. execsql {CREATE TABLE t5(x)}
  1973. proc auth {code arg1 arg2 arg3 arg4} {
  1974. if {$code=="SQLITE_ALTER_TABLE"} {
  1975. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1976. return SQLITE_OK
  1977. }
  1978. return SQLITE_OK
  1979. }
  1980. catchsql {
  1981. ALTER TABLE t5 ADD COLUMN new_col_1;
  1982. }
  1983. } {0 {}}
  1984. do_test auth-1.301 {
  1985. set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
  1986. regexp new_col_1 $x
  1987. } {1}
  1988. do_test auth-1.302 {
  1989. set authargs
  1990. } {main t5 {} {}}
  1991. do_test auth-1.303 {
  1992. proc auth {code arg1 arg2 arg3 arg4} {
  1993. if {$code=="SQLITE_ALTER_TABLE"} {
  1994. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  1995. return SQLITE_IGNORE
  1996. }
  1997. return SQLITE_OK
  1998. }
  1999. catchsql {
  2000. ALTER TABLE t5 ADD COLUMN new_col_2;
  2001. }
  2002. } {0 {}}
  2003. do_test auth-1.304 {
  2004. set x [execsql {SELECT sql FROM sqlite_master WHERE name='t5'}]
  2005. regexp new_col_2 $x
  2006. } {0}
  2007. do_test auth-1.305 {
  2008. set authargs
  2009. } {main t5 {} {}}
  2010. do_test auth-1.306 {
  2011. proc auth {code arg1 arg2 arg3 arg4} {
  2012. if {$code=="SQLITE_ALTER_TABLE"} {
  2013. set ::authargs [list $arg1 $arg2 $arg3 $arg4]
  2014. return SQLITE_DENY
  2015. }
  2016. return SQLITE_OK
  2017. }
  2018. catchsql {
  2019. ALTER TABLE t5 ADD COLUMN new_col_3
  2020. }
  2021. } {1 {not authorized}}
  2022. do_test auth-1.307 {
  2023. set x [execsql {SELECT sql FROM sqlite_temp_master WHERE type='t5'}]
  2024. regexp new_col_3 $x
  2025. } {0}
  2026. do_test auth-1.308 {
  2027. set authargs
  2028. } {main t5 {} {}}
  2029. execsql {DROP TABLE t5}
  2030. } ;# ifcapable altertable
  2031. do_test auth-2.1 {
  2032. proc auth {code arg1 arg2 arg3 arg4} {
  2033. if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
  2034. return SQLITE_DENY
  2035. }
  2036. return SQLITE_OK
  2037. }
  2038. db authorizer ::auth
  2039. execsql {CREATE TABLE t3(x INTEGER PRIMARY KEY, y, z)}
  2040. catchsql {SELECT * FROM t3}
  2041. } {1 {access to t3.x is prohibited}}
  2042. do_test auth-2.1 {
  2043. catchsql {SELECT y,z FROM t3}
  2044. } {0 {}}
  2045. do_test auth-2.2 {
  2046. catchsql {SELECT ROWID,y,z FROM t3}
  2047. } {1 {access to t3.x is prohibited}}
  2048. do_test auth-2.3 {
  2049. catchsql {SELECT OID,y,z FROM t3}
  2050. } {1 {access to t3.x is prohibited}}
  2051. do_test auth-2.4 {
  2052. proc auth {code arg1 arg2 arg3 arg4} {
  2053. if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="x"} {
  2054. return SQLITE_IGNORE
  2055. }
  2056. return SQLITE_OK
  2057. }
  2058. execsql {INSERT INTO t3 VALUES(44,55,66)}
  2059. catchsql {SELECT * FROM t3}
  2060. } {0 {{} 55 66}}
  2061. do_test auth-2.5 {
  2062. catchsql {SELECT rowid,y,z FROM t3}
  2063. } {0 {{} 55 66}}
  2064. do_test auth-2.6 {
  2065. proc auth {code arg1 arg2 arg3 arg4} {
  2066. if {$code=="SQLITE_READ" && $arg1=="t3" && $arg2=="ROWID"} {
  2067. return SQLITE_IGNORE
  2068. }
  2069. return SQLITE_OK
  2070. }
  2071. catchsql {SELECT * FROM t3}
  2072. } {0 {44 55 66}}
  2073. do_test auth-2.7 {
  2074. catchsql {SELECT ROWID,y,z FROM t3}
  2075. } {0 {44 55 66}}
  2076. do_test auth-2.8 {
  2077. proc auth {code arg1 arg2 arg3 arg4} {
  2078. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
  2079. return SQLITE_IGNORE
  2080. }
  2081. return SQLITE_OK
  2082. }
  2083. catchsql {SELECT ROWID,b,c FROM t2}
  2084. } {0 {{} 2 33 {} 8 9}}
  2085. do_test auth-2.9.1 {
  2086. # We have to flush the cache here in case the Tcl interface tries to
  2087. # reuse a statement compiled with sqlite3_prepare_v2(). In this case,
  2088. # the first error encountered is an SQLITE_SCHEMA error. Then, when
  2089. # trying to recompile the statement, the authorization error is encountered.
  2090. # If we do not flush the cache, the correct error message is returned, but
  2091. # the error code is SQLITE_SCHEMA, not SQLITE_ERROR as required by the test
  2092. # case after this one.
  2093. #
  2094. db cache flush
  2095. proc auth {code arg1 arg2 arg3 arg4} {
  2096. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="ROWID"} {
  2097. return bogus
  2098. }
  2099. return SQLITE_OK
  2100. }
  2101. catchsql {SELECT ROWID,b,c FROM t2}
  2102. } {1 {authorizer malfunction}}
  2103. do_test auth-2.9.2 {
  2104. db errorcode
  2105. } {1}
  2106. do_test auth-2.10 {
  2107. proc auth {code arg1 arg2 arg3 arg4} {
  2108. if {$code=="SQLITE_SELECT"} {
  2109. return bogus
  2110. }
  2111. return SQLITE_OK
  2112. }
  2113. catchsql {SELECT ROWID,b,c FROM t2}
  2114. } {1 {authorizer malfunction}}
  2115. do_test auth-2.11.1 {
  2116. proc auth {code arg1 arg2 arg3 arg4} {
  2117. if {$code=="SQLITE_READ" && $arg2=="a"} {
  2118. return SQLITE_IGNORE
  2119. }
  2120. return SQLITE_OK
  2121. }
  2122. catchsql {SELECT * FROM t2, t3}
  2123. } {0 {{} 2 33 44 55 66 {} 8 9 44 55 66}}
  2124. do_test auth-2.11.2 {
  2125. proc auth {code arg1 arg2 arg3 arg4} {
  2126. if {$code=="SQLITE_READ" && $arg2=="x"} {
  2127. return SQLITE_IGNORE
  2128. }
  2129. return SQLITE_OK
  2130. }
  2131. catchsql {SELECT * FROM t2, t3}
  2132. } {0 {11 2 33 {} 55 66 7 8 9 {} 55 66}}
  2133. # Make sure the OLD and NEW pseudo-tables of a trigger get authorized.
  2134. #
  2135. ifcapable trigger {
  2136. do_test auth-3.1 {
  2137. proc auth {code arg1 arg2 arg3 arg4} {
  2138. return SQLITE_OK
  2139. }
  2140. execsql {
  2141. CREATE TABLE tx(a1,a2,b1,b2,c1,c2);
  2142. CREATE TRIGGER r1 AFTER UPDATE ON t2 FOR EACH ROW BEGIN
  2143. INSERT INTO tx VALUES(OLD.a,NEW.a,OLD.b,NEW.b,OLD.c,NEW.c);
  2144. END;
  2145. UPDATE t2 SET a=a+1;
  2146. SELECT * FROM tx;
  2147. }
  2148. } {11 12 2 2 33 33 7 8 8 8 9 9}
  2149. do_test auth-3.2 {
  2150. proc auth {code arg1 arg2 arg3 arg4} {
  2151. if {$code=="SQLITE_READ" && $arg1=="t2" && $arg2=="c"} {
  2152. return SQLITE_IGNORE
  2153. }
  2154. return SQLITE_OK
  2155. }
  2156. execsql {
  2157. DELETE FROM tx;
  2158. UPDATE t2 SET a=a+100;
  2159. SELECT * FROM tx;
  2160. }
  2161. } {12 112 2 2 {} {} 8 108 8 8 {} {}}
  2162. } ;# ifcapable trigger
  2163. # Make sure the names of views and triggers are passed on on arg4.
  2164. #
  2165. ifcapable trigger {
  2166. do_test auth-4.1 {
  2167. proc auth {code arg1 arg2 arg3 arg4} {
  2168. lappend ::authargs $code $arg1 $arg2 $arg3 $arg4
  2169. return SQLITE_OK
  2170. }
  2171. set authargs {}
  2172. execsql {
  2173. UPDATE t2 SET a=a+1;
  2174. }
  2175. set authargs
  2176. } [list \
  2177. SQLITE_READ t2 a main {} \
  2178. SQLITE_UPDATE t2 a main {} \
  2179. SQLITE_INSERT tx {} main r1 \
  2180. SQLITE_READ t2 a main r1 \
  2181. SQLITE_READ t2 a main r1 \
  2182. SQLITE_READ t2 b main r1 \
  2183. SQLITE_READ t2 b main r1 \
  2184. SQLITE_READ t2 c main r1 \
  2185. SQLITE_READ t2 c main r1]
  2186. }
  2187. ifcapable {view && trigger} {
  2188. do_test auth-4.2 {
  2189. execsql {
  2190. CREATE VIEW v1 AS SELECT a+b AS x FROM t2;
  2191. CREATE TABLE v1chng(x1,x2);
  2192. CREATE TRIGGER r2 INSTEAD OF UPDATE ON v1 BEGIN
  2193. INSERT INTO v1chng VALUES(OLD.x,NEW.x);
  2194. END;
  2195. SELECT * FROM v1;
  2196. }
  2197. } {115 117}
  2198. do_test auth-4.3 {
  2199. set authargs {}
  2200. execsql {
  2201. UPDATE v1 SET x=1 WHERE x=117
  2202. }
  2203. set authargs
  2204. } [list \
  2205. SQLITE_UPDATE v1 x main {} \
  2206. SQLITE_SELECT {} {} {} v1 \
  2207. SQLITE_READ t2 a main v1 \
  2208. SQLITE_READ t2 b main v1 \
  2209. SQLITE_READ v1 x main v1 \
  2210. SQLITE_READ v1 x main v1 \
  2211. SQLITE_SELECT {} {} {} v1 \
  2212. SQLITE_READ v1 x main v1 \
  2213. SQLITE_INSERT v1chng {} main r2 \
  2214. SQLITE_READ v1 x main r2 \
  2215. SQLITE_READ v1 x main r2 \
  2216. ]
  2217. do_test auth-4.4 {
  2218. execsql {
  2219. CREATE TRIGGER r3 INSTEAD OF DELETE ON v1 BEGIN
  2220. INSERT INTO v1chng VALUES(OLD.x,NULL);
  2221. END;
  2222. SELECT * FROM v1;
  2223. }
  2224. } {115 117}
  2225. do_test auth-4.5 {
  2226. set authargs {}
  2227. execsql {
  2228. DELETE FROM v1 WHERE x=117
  2229. }
  2230. set authargs
  2231. } [list \
  2232. SQLITE_DELETE v1 {} main {} \
  2233. SQLITE_SELECT {} {} {} v1 \
  2234. SQLITE_READ t2 a main v1 \
  2235. SQLITE_READ t2 b main v1 \
  2236. SQLITE_READ v1 x main v1 \
  2237. SQLITE_READ v1 x main v1 \
  2238. SQLITE_SELECT {} {} {} v1 \
  2239. SQLITE_READ v1 x main v1 \
  2240. SQLITE_INSERT v1chng {} main r3 \
  2241. SQLITE_READ v1 x main r3 \
  2242. ]
  2243. } ;# ifcapable view && trigger
  2244. # Ticket #1338: Make sure authentication works in the presence of an AS
  2245. # clause.
  2246. #
  2247. do_test auth-5.1 {
  2248. proc auth {code arg1 arg2 arg3 arg4} {
  2249. return SQLITE_OK
  2250. }
  2251. execsql {
  2252. SELECT count(a) AS cnt FROM t4 ORDER BY cnt
  2253. }
  2254. } {1}
  2255. # Ticket #1607
  2256. #
  2257. ifcapable compound&&subquery {
  2258. ifcapable trigger {
  2259. execsql {
  2260. DROP TABLE tx;
  2261. }
  2262. ifcapable view {
  2263. execsql {
  2264. DROP TABLE v1chng;
  2265. }
  2266. }
  2267. }
  2268. ifcapable stat4 {
  2269. set stat4 "sqlite_stat4 "
  2270. } else {
  2271. ifcapable stat3 {
  2272. set stat4 "sqlite_stat3 "
  2273. } else {
  2274. set stat4 ""
  2275. }
  2276. }
  2277. do_test auth-5.2 {
  2278. execsql {
  2279. SELECT name FROM (
  2280. SELECT * FROM sqlite_master UNION ALL SELECT * FROM sqlite_temp_master)
  2281. WHERE type='table'
  2282. ORDER BY name
  2283. }
  2284. } "sqlite_stat1 ${stat4}t1 t2 t3 t4"
  2285. }
  2286. # Ticket #3944
  2287. #
  2288. ifcapable trigger {
  2289. do_test auth-5.3.1 {
  2290. execsql {
  2291. CREATE TABLE t5 ( x );
  2292. CREATE TRIGGER t5_tr1 AFTER INSERT ON t5 BEGIN
  2293. UPDATE t5 SET x = 1 WHERE NEW.x = 0;
  2294. END;
  2295. }
  2296. } {}
  2297. set ::authargs [list]
  2298. proc auth {args} {
  2299. eval lappend ::authargs $args
  2300. return SQLITE_OK
  2301. }
  2302. do_test auth-5.3.2 {
  2303. execsql { INSERT INTO t5 (x) values(0) }
  2304. set ::authargs
  2305. } [list SQLITE_INSERT t5 {} main {} \
  2306. SQLITE_UPDATE t5 x main t5_tr1 \
  2307. SQLITE_READ t5 x main t5_tr1 \
  2308. ]
  2309. do_test auth-5.3.2 {
  2310. execsql { SELECT * FROM t5 }
  2311. } {1}
  2312. }
  2313. # Ticket [0eb70d77cb05bb22720]: Invalid pointer passsed to the authorizer
  2314. # callback when updating a ROWID.
  2315. #
  2316. do_test auth-6.1 {
  2317. execsql {
  2318. CREATE TABLE t6(a,b,c,d,e,f,g,h);
  2319. INSERT INTO t6 VALUES(1,2,3,4,5,6,7,8);
  2320. }
  2321. } {}
  2322. set ::authargs [list]
  2323. proc auth {args} {
  2324. eval lappend ::authargs $args
  2325. return SQLITE_OK
  2326. }
  2327. do_test auth-6.2 {
  2328. execsql {UPDATE t6 SET rowID=rowID+100}
  2329. set ::authargs
  2330. } [list SQLITE_READ t6 ROWID main {} \
  2331. SQLITE_UPDATE t6 ROWID main {} \
  2332. ]
  2333. do_test auth-6.3 {
  2334. execsql {SELECT rowid, * FROM t6}
  2335. } {101 1 2 3 4 5 6 7 8}
  2336. rename proc {}
  2337. rename proc_real proc
  2338. finish_test