danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 1 | # 2008 October 29 |
| 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. |
| 12 | # |
danielk1977 | 6f4c73e | 2009-06-26 07:12:06 +0000 | [diff] [blame] | 13 | # $Id: tkt3457.test,v 1.3 2009/06/26 07:12:07 danielk1977 Exp $ |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 14 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
| 17 | |
| 18 | if {$tcl_platform(platform) != "unix"} { |
| 19 | finish_test |
| 20 | return |
| 21 | } |
| 22 | |
| 23 | #----------------------------------------------------------------------- |
| 24 | # To roll back a hot-journal file, the application needs read and write |
| 25 | # permission on the journal file in question. The following tests test |
| 26 | # the outcome of trying to rollback a hot-journal file when this is not |
| 27 | # the case. |
| 28 | # |
| 29 | # tkt3457-1.2: Application has neither read, nor write permission on |
| 30 | # the hot-journal file. Result: SQLITE_CANTOPEN. |
| 31 | # |
| 32 | # tkt3457-1.3: Application has write but not read permission on |
| 33 | # the hot-journal file. Result: SQLITE_CANTOPEN. |
| 34 | # |
mistachkin | a8e97da | 2013-01-04 22:26:47 +0000 | [diff] [blame] | 35 | # tkt3457-1.4: Application has read but not write permission on |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 36 | # the hot-journal file. Result: SQLITE_CANTOPEN. |
| 37 | # |
| 38 | # tkt3457-1.5: Application has read/write permission on the hot-journal |
| 39 | # file. Result: SQLITE_OK. |
| 40 | # |
| 41 | do_test tkt3457-1.1 { |
| 42 | execsql { |
| 43 | CREATE TABLE t1(a, b, c); |
| 44 | INSERT INTO t1 VALUES(1, 2, 3); |
| 45 | BEGIN; |
| 46 | INSERT INTO t1 VALUES(4, 5, 6); |
| 47 | } |
| 48 | |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 49 | forcecopy test.db bak.db |
| 50 | forcecopy test.db-journal bak.db-journal |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 51 | |
danielk1977 | 6f4c73e | 2009-06-26 07:12:06 +0000 | [diff] [blame] | 52 | # Fix the first journal-header in the journal-file. Because the |
| 53 | # journal file has not yet been synced, the 8-byte magic string at the |
| 54 | # start of the first journal-header has not been written by SQLite. |
| 55 | # So write it now. |
| 56 | set fd [open bak.db-journal a+] |
| 57 | fconfigure $fd -encoding binary -translation binary |
| 58 | seek $fd 0 |
| 59 | puts -nonewline $fd "\xd9\xd5\x05\xf9\x20\xa1\x63\xd7" |
| 60 | close $fd |
| 61 | |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 62 | execsql COMMIT |
| 63 | } {} |
| 64 | |
drh | e1186ab | 2013-01-04 20:45:13 +0000 | [diff] [blame] | 65 | # Disable fchmod to make sure SQLite itself does not try to change the |
| 66 | # permission bits on us |
| 67 | # |
| 68 | catch { |
| 69 | test_syscall install fchmod |
| 70 | test_syscall fault 1 1 |
| 71 | } |
| 72 | |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 73 | do_test tkt3457-1.2 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 74 | forcecopy bak.db-journal test.db-journal |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 75 | file attributes test.db-journal -permissions --------- |
| 76 | catchsql { SELECT * FROM t1 } |
| 77 | } {1 {unable to open database file}} |
| 78 | do_test tkt3457-1.3 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 79 | forcecopy bak.db-journal test.db-journal |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 80 | file attributes test.db-journal -permissions -w--w--w- |
| 81 | catchsql { SELECT * FROM t1 } |
| 82 | } {1 {unable to open database file}} |
| 83 | do_test tkt3457-1.4 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 84 | forcecopy bak.db-journal test.db-journal |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 85 | file attributes test.db-journal -permissions r--r--r-- |
| 86 | catchsql { SELECT * FROM t1 } |
| 87 | } {1 {unable to open database file}} |
| 88 | |
| 89 | do_test tkt3457-1.5 { |
mistachkin | fda06be | 2011-08-02 00:57:34 +0000 | [diff] [blame] | 90 | forcecopy bak.db-journal test.db-journal |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 91 | file attributes test.db-journal -permissions rw-rw-rw- |
| 92 | catchsql { SELECT * FROM t1 } |
| 93 | } {0 {1 2 3 4 5 6}} |
| 94 | |
drh | e1186ab | 2013-01-04 20:45:13 +0000 | [diff] [blame] | 95 | # Reenable fchmod |
| 96 | catch { |
| 97 | test_syscall uninstall |
| 98 | test_syscall fault 0 0 |
| 99 | } |
| 100 | |
danielk1977 | 281d8bd | 2008-10-29 07:01:56 +0000 | [diff] [blame] | 101 | finish_test |