Mercurial > vim
annotate src/testdir/test_swap.vim @ 12771:8984342ab09e v8.0.1263
patch 8.0.1263: others can read the swap file if a user is careless
commit https://github.com/vim/vim/commit/5a73e0ca54c77e067c3b12ea6f35e3e8681e8cf8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 4 21:35:01 2017 +0100
patch 8.0.1263: others can read the swap file if a user is careless
Problem: Others can read the swap file if a user is careless with his
primary group.
Solution: If the group permission allows for reading but the world
permissions doesn't, make sure the group is right.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 04 Nov 2017 21:45:04 +0100 |
parents | 0b6c09957b43 |
children | bda267b9fc68 |
rev | line source |
---|---|
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Tests for the swap feature |
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
3 "" Tests for 'directory' option. |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
4 "func Test_swap_directory() |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
5 " if !has("unix") |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
6 " return |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
7 " endif |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
8 " let content = ['start of testfile', |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
9 " \ 'line 2 Abcdefghij', |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
10 " \ 'line 3 Abcdefghij', |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
11 " \ 'end of testfile'] |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
12 " call writefile(content, 'Xtest1') |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
13 " |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
14 " " '.', swap file in the same directory as file |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
15 " set dir=.,~ |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
16 " |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
17 " " Verify that the swap file doesn't exist in the current directory |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
18 " call assert_equal([], glob(".Xtest1*.swp", 1, 1, 1)) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
19 " edit Xtest1 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
20 " let swfname = split(execute("swapname"))[0] |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
21 " call assert_equal([swfname], glob(swfname, 1, 1, 1)) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
22 " |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
23 " " './dir', swap file in a directory relative to the file |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
24 " set dir=./Xtest2,.,~ |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
25 " |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
26 " call mkdir("Xtest2") |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
27 " edit Xtest1 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
28 " call assert_equal([], glob(swfname, 1, 1, 1)) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
29 " let swfname = "Xtest2/Xtest1.swp" |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
30 " call assert_equal(swfname, split(execute("swapname"))[0]) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
31 " call assert_equal([swfname], glob("Xtest2/*", 1, 1, 1)) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
32 " |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
33 " " 'dir', swap file in directory relative to the current dir |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
34 " set dir=Xtest.je,~ |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
35 " |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
36 " call mkdir("Xtest.je") |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
37 " call writefile(content, 'Xtest2/Xtest3') |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
38 " edit Xtest2/Xtest3 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
39 " call assert_equal(["Xtest2/Xtest3"], glob("Xtest2/*", 1, 1, 1)) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
40 " let swfname = "Xtest.je/Xtest3.swp" |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
41 " call assert_equal(swfname, split(execute("swapname"))[0]) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
42 " call assert_equal([swfname], glob("Xtest.je/*", 1, 1, 1)) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
43 " |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
44 " set dir& |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
45 " call delete("Xtest1") |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
46 " call delete("Xtest2", "rf") |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
47 " call delete("Xtest.je", "rf") |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
48 "endfunc |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
49 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
50 func Test_swap_group() |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 if !has("unix") |
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 return |
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
53 endif |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
54 let groups = split(system('groups')) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
55 if len(groups) <= 1 |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
56 throw 'Skipped: need at least two groups, got ' . groups |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
57 endif |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
59 call delete('Xtest') |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
60 split Xtest |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
61 call setline(1, 'just some text') |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
62 wq |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
63 if system('ls -l Xtest') !~ ' ' . groups[0] . ' \d' |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
64 throw 'Skipped: test file does not have the first group' |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
65 else |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
66 silent !chmod 640 Xtest |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
67 call system('chgrp ' . groups[1] . ' Xtest') |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
68 if system('ls -l Xtest') !~ ' ' . groups[1] . ' \d' |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
69 throw 'Skipped: cannot set second group on test file' |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
70 else |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
71 split Xtest |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
72 let swapname = substitute(execute('swapname'), '[[:space:]]', '', 'g') |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
73 call assert_match('Xtest', swapname) |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
74 " Group of swapfile must now match original file. |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
75 call assert_match(' ' . groups[1] . ' \d', system('ls -l ' . swapname)) |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
77 bwipe! |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
78 endif |
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
79 endif |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 |
12771
8984342ab09e
patch 8.0.1263: others can read the swap file if a user is careless
Christian Brabandt <cb@256bit.org>
parents:
12750
diff
changeset
|
81 call delete('Xtest') |
12750
0b6c09957b43
patch 8.0.1253: still too many old style tests
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 endfunc |