aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ex_cmds/trust_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-01-14 23:13:48 -0700
committerJosh Rahm <joshuarahm@gmail.com>2023-01-14 23:13:48 -0700
commit7a6e249a32f79331bfb5e29bc0cabcf89a026081 (patch)
tree27a7354ec18448e4090ac91581534baa7b537254 /test/functional/ex_cmds/trust_spec.lua
parent442d4e54c30b8e193e3f6e4d32b43e96815bccd7 (diff)
parent6134c1e8a39a5e61d0593613343a5923a86e3545 (diff)
downloadrneovim-7a6e249a32f79331bfb5e29bc0cabcf89a026081.tar.gz
rneovim-7a6e249a32f79331bfb5e29bc0cabcf89a026081.tar.bz2
rneovim-7a6e249a32f79331bfb5e29bc0cabcf89a026081.zip
Merge remote-tracking branch 'upstream/master' into usermarks
Diffstat (limited to 'test/functional/ex_cmds/trust_spec.lua')
-rw-r--r--test/functional/ex_cmds/trust_spec.lua176
1 files changed, 176 insertions, 0 deletions
diff --git a/test/functional/ex_cmds/trust_spec.lua b/test/functional/ex_cmds/trust_spec.lua
new file mode 100644
index 0000000000..10ee02a790
--- /dev/null
+++ b/test/functional/ex_cmds/trust_spec.lua
@@ -0,0 +1,176 @@
+local helpers = require('test.functional.helpers')(after_each)
+local Screen = require('test.functional.ui.screen')
+
+local eq = helpers.eq
+local clear = helpers.clear
+local command = helpers.command
+local pathsep = helpers.get_pathsep()
+local is_os = helpers.is_os
+local funcs = helpers.funcs
+
+describe(':trust', function()
+ local xstate = 'Xstate'
+
+ setup(function()
+ helpers.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
+ end)
+
+ teardown(function()
+ helpers.rmdir(xstate)
+ end)
+
+ before_each(function()
+ helpers.write_file('test_file', 'test')
+ clear{env={XDG_STATE_HOME=xstate}}
+ end)
+
+ after_each(function()
+ os.remove('test_file')
+ end)
+
+ it('trust then deny then remove a file using current buffer', function()
+ local screen = Screen.new(80, 8)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue1},
+ })
+
+ local cwd = funcs.getcwd()
+ local hash = funcs.sha256(helpers.read_file('test_file'))
+
+ command('edit test_file')
+ command('trust')
+ screen:expect([[
+ ^test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}|
+ ]])
+ local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
+
+ command('trust ++deny')
+ screen:expect([[
+ ^test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}|
+ ]])
+ trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
+
+ command('trust ++remove')
+ screen:expect([[
+ ^test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}|
+ ]])
+ trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format(''), vim.trim(trust))
+ end)
+
+ it('deny then trust then remove a file using current buffer', function()
+ local screen = Screen.new(80, 8)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue1},
+ })
+
+ local cwd = funcs.getcwd()
+ local hash = funcs.sha256(helpers.read_file('test_file'))
+
+ command('edit test_file')
+ command('trust ++deny')
+ screen:expect([[
+ ^test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}|
+ ]])
+ local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
+
+ command('trust')
+ screen:expect([[
+ ^test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" trusted.{MATCH:%s+}|
+ ]])
+ trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
+
+ command('trust ++remove')
+ screen:expect([[
+ ^test |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}|
+ ]])
+ trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format(''), vim.trim(trust))
+ end)
+
+ it('deny then remove a file using file path', function()
+ local screen = Screen.new(80, 8)
+ screen:attach()
+ screen:set_default_attr_ids({
+ [1] = {bold = true, foreground = Screen.colors.Blue1},
+ })
+
+ local cwd = funcs.getcwd()
+
+ command('trust ++deny test_file')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" denied.{MATCH:%s+}|
+ ]])
+ local trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
+
+ command('trust ++remove test_file')
+ screen:expect([[
+ ^ |
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ {1:~ }|
+ "]] .. cwd .. pathsep .. [[test_file" removed.{MATCH:%s+}|
+ ]])
+ trust = helpers.read_file(funcs.stdpath('state') .. pathsep .. 'trust')
+ eq(string.format(''), vim.trim(trust))
+ end)
+end)