OLD | NEW |
(Empty) | |
| 1 # 2015 October 31 |
| 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 file is testing that SQLite can follow symbolic links. |
| 13 # |
| 14 |
| 15 set testdir [file dirname $argv0] |
| 16 source $testdir/tester.tcl |
| 17 set testprefix symlink |
| 18 |
| 19 # This only runs on unix. |
| 20 if {$::tcl_platform(platform)!="unix"} { |
| 21 finish_test |
| 22 return |
| 23 } |
| 24 |
| 25 # Ensure that test.db has been created. |
| 26 # |
| 27 do_execsql_test 1.0 { |
| 28 CREATE TABLE t1(x, y); |
| 29 } |
| 30 |
| 31 # Test that SQLite follows symlinks when opening files. |
| 32 # |
| 33 forcedelete test.db2 |
| 34 do_test 1.1 { |
| 35 file link test.db2 test.db |
| 36 sqlite3 db2 test.db2 |
| 37 sqlite3_db_filename db2 main |
| 38 } [file join [pwd] test.db] |
| 39 |
| 40 # Test that if the symlink points to a file that does not exists, it is |
| 41 # created when it is opened. |
| 42 # |
| 43 do_test 1.2.1 { |
| 44 db2 close |
| 45 db close |
| 46 forcedelete test.db |
| 47 file exists test.db |
| 48 } 0 |
| 49 do_test 1.2.2 { |
| 50 sqlite3 db2 test.db2 |
| 51 file exists test.db |
| 52 } 1 |
| 53 do_test 1.2.3 { |
| 54 sqlite3_db_filename db2 main |
| 55 } [file join [pwd] test.db] |
| 56 db2 close |
| 57 |
| 58 # Test that a loop of symlinks cannot be opened. |
| 59 # |
| 60 do_test 1.3 { |
| 61 forcedelete test.db |
| 62 # Note: Tcl [file link] command is too smart to create loops of symlinks. |
| 63 exec ln -s test.db2 test.db |
| 64 list [catch { sqlite3 db test.db } msg] $msg |
| 65 } {1 {unable to open database file}} |
| 66 |
| 67 # Test that overly large paths cannot be opened. |
| 68 # |
| 69 do_test 1.4 { |
| 70 set name "test.db[string repeat x 502]" |
| 71 list [catch { sqlite3 db $name } msg] $msg |
| 72 } {1 {unable to open database file}} |
| 73 do_test 1.5 { |
| 74 set r [expr 510 - [string length test.db] - [string length [pwd]]] |
| 75 set name "test.db[string repeat x $r]" |
| 76 list [catch { sqlite3 db $name } msg] $msg |
| 77 } {1 {unable to open database file}} |
| 78 |
| 79 #------------------------------------------------------------------------- |
| 80 # Test that journal and wal files are created next to the real file, |
| 81 # not the symlink. |
| 82 # |
| 83 do_test 2.0 { |
| 84 catch { db close } |
| 85 catch { db2 close } |
| 86 forcedelete test.db test.db2 |
| 87 sqlite3 db test.db |
| 88 execsql { CREATE TABLE t1(x) } |
| 89 file link test.db2 test.db |
| 90 sqlite3 db2 test.db2 |
| 91 file exists test.db-journal |
| 92 } 0 |
| 93 |
| 94 do_test 2.1 { |
| 95 execsql { |
| 96 BEGIN; |
| 97 INSERT INTO t1 VALUES(1); |
| 98 } db2 |
| 99 file exists test.db-journal |
| 100 } 1 |
| 101 do_test 2.2 { |
| 102 file exists test.db2-journal |
| 103 } 0 |
| 104 do_test 2.3 { |
| 105 execsql { |
| 106 COMMIT; |
| 107 PRAGMA journal_mode = wal; |
| 108 INSERT INTO t1 VALUES(2); |
| 109 } db2 |
| 110 file exists test.db-wal |
| 111 } 1 |
| 112 do_test 2.4 { |
| 113 file exists test.db2-wal |
| 114 } 0 |
| 115 do_execsql_test 2.5 { |
| 116 SELECT * FROM t1; |
| 117 } {1 2} |
| 118 |
| 119 # Try to open a ridiculously long pathname. Bug found by |
| 120 # Kostya Serebryany using libFuzzer on 2015-11-30. |
| 121 # |
| 122 do_test 3.1 { |
| 123 db close |
| 124 catch {sqlite3 db [string repeat [string repeat x 100]/ 6]} res |
| 125 set res |
| 126 } {unable to open database file} |
| 127 |
| 128 |
| 129 finish_test |
OLD | NEW |