xref: /vim-8.2.3635/src/testdir/test_crypt.vim (revision b1c9198a)
1" Tests for encryption.
2
3if !has('cryptv')
4  finish
5endif
6
7func Common_head_only(text)
8  " This was crashing Vim
9  split Xtest.txt
10  call setline(1, a:text)
11  wq
12  call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", "tx")
13  call delete('Xtest.txt')
14  call assert_match('VimCrypt', getline(1))
15  bwipe!
16endfunc
17
18func Test_head_only_2()
19  call Common_head_only('VimCrypt~02!abc')
20endfunc
21
22func Test_head_only_3()
23  call Common_head_only('VimCrypt~03!abc')
24endfunc
25
26func Crypt_uncrypt(method)
27  exe "set cryptmethod=" . a:method
28  " If the blowfish test fails 'cryptmethod' will be 'zip' now.
29  call assert_equal(a:method, &cryptmethod)
30
31  split Xtest.txt
32  let text = ['01234567890123456789012345678901234567',
33	\ 'line 2  foo bar blah',
34	\ 'line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx']
35  call setline(1, text)
36  call feedkeys(":X\<CR>foobar\<CR>foobar\<CR>", 'xt')
37  w!
38  bwipe!
39  call feedkeys(":split Xtest.txt\<CR>foobar\<CR>", 'xt')
40  call assert_equal(text, getline(1, 3))
41  set key= cryptmethod&
42  bwipe!
43  call delete('Xtest.txt')
44endfunc
45
46func Test_crypt_zip()
47  call Crypt_uncrypt('zip')
48endfunc
49
50func Test_crypt_blowfish()
51  call Crypt_uncrypt('blowfish')
52endfunc
53
54func Test_crypt_blowfish2()
55  call Crypt_uncrypt('blowfish2')
56endfunc
57
58func Uncrypt_stable(method, crypted_text, key, uncrypted_text)
59  split Xtest.txt
60  set bin noeol key= fenc=latin1
61  exe "set cryptmethod=" . a:method
62  call setline(1, a:crypted_text)
63  w!
64  bwipe!
65  set nobin
66  call feedkeys(":split Xtest.txt\<CR>" . a:key . "\<CR>", 'xt')
67  call assert_equal(a:uncrypted_text, getline(1, len(a:uncrypted_text)))
68  bwipe!
69  call delete('Xtest.txt')
70  set key=
71endfunc
72
73func Test_uncrypt_zip()
74  call Uncrypt_stable('zip', "VimCrypt~01!\u0006\u001clV'\u00de}Mg\u00a0\u00ea\u00a3V\u00a9\u00e7\u0007E#3\u008e2U\u00e9\u0097", "foofoo", ["1234567890", "aábbccddeëff"])
75endfunc
76
77func Test_uncrypt_blowfish()
78  call Uncrypt_stable('blowfish', "VimCrypt~02!k)\u00be\u0017\u0097#\u0016\u00ddS\u009c\u00f5=\u00ba\u00e0\u00c8#\u00a5M\u00b4\u0086J\u00c3A\u00cd\u00a5M\u00b4\u0086!\u0080\u0015\u009b\u00f5\u000f\u00e1\u00d2\u0019\u0082\u0016\u0098\u00f7\u000d\u00da", "barbar", ["asdfasdfasdf", "0001112223333"])
79endfunc
80
81func Test_uncrypt_blowfish2()
82  call Uncrypt_stable('blowfish', "VimCrypt~03!\u001e\u00d1N\u00e3;\u00d3\u00c0\u00a0^C)\u0004\u00f7\u007f.\u00b6\u00abF\u000eS\u0019\u00e0\u008b6\u00d2[T\u00cb\u00a7\u0085\u00d8\u00be9\u000b\u00812\u000bQ\u00b3\u00cc@\u0097\u000f\u00df\u009a\u00adIv\u00aa.\u00d8\u00c9\u00ee\u009e`\u00bd$\u00af%\u00d0", "barburp", ["abcdefghijklmnopqrstuvwxyz", "!@#$%^&*()_+=-`~"])
83endfunc
84