1# 2014-09-10 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 6# May you do good and not evil. 7# May you find forgiveness for yourself and forgive others. 8# May you share freely, never taking more than you give. 9# 10#*********************************************************************** 11# 12# This file implements tests of the SQLITE_USER_AUTHENTICATION extension. 13# 14 15set testdir [file dirname $argv0] 16source $testdir/tester.tcl 17set testprefix userauth01 18 19ifcapable !userauth { 20 finish_test 21 return 22} 23 24# Create a no-authentication-required database 25# 26do_execsql_test userauth01-1.0 { 27 CREATE TABLE t1(x); 28 INSERT INTO t1 VALUES(1),(2.5),('three'),(x'4444'),(NULL); 29 SELECT quote(x) FROM t1 ORDER BY x; 30 SELECT name FROM sqlite_master; 31} {NULL 1 2.5 'three' X'4444' t1} 32 33# Calling sqlite3_user_authenticate() on a no-authentication-required 34# database connection is a harmless no-op. 35# 36do_test userauth01-1.1 { 37 sqlite3_user_authenticate db alice pw-4-alice 38 execsql { 39 SELECT quote(x) FROM t1 ORDER BY x; 40 SELECT name FROM sqlite_master; 41 } 42} {NULL 1 2.5 'three' X'4444' t1} 43 44# If sqlite3_user_add(D,U,P,N,A) is called on a no-authentication-required 45# database and A is false, then the call fails with an SQLITE_AUTH error. 46# 47do_test userauth01-1.2 { 48 sqlite3_user_add db bob pw-4-bob 0 49} {SQLITE_AUTH} 50do_test userauth01-1.3 { 51 execsql { 52 SELECT quote(x) FROM t1 ORDER BY x; 53 SELECT name FROM sqlite_master; 54 } 55} {NULL 1 2.5 'three' X'4444' t1} 56 57# When called on a no-authentication-required 58# database and when A is true, the sqlite3_user_add(D,U,P,N,A) routine 59# converts the database into an authentication-required database and 60# logs the database connection D in using user U with password P,N. 61# 62do_test userauth01-1.4 { 63 sqlite3_user_add db alice pw-4-alice 1 64} {SQLITE_OK} 65do_test userauth01-1.5 { 66 execsql { 67 SELECT quote(x) FROM t1 ORDER BY x; 68 SELECT uname, isadmin FROM sqlite_user ORDER BY uname; 69 SELECT name FROM sqlite_master ORDER BY name; 70 } 71} {NULL 1 2.5 'three' X'4444' alice 1 sqlite_user t1} 72 73 74finish_test 75