trust_spec.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local eq = t.eq
  4. local clear = n.clear
  5. local command = n.command
  6. local exec_capture = n.exec_capture
  7. local matches = t.matches
  8. local pathsep = n.get_pathsep()
  9. local is_os = t.is_os
  10. local fn = n.fn
  11. describe(':trust', function()
  12. local xstate = 'Xstate'
  13. setup(function()
  14. n.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
  15. end)
  16. teardown(function()
  17. n.rmdir(xstate)
  18. end)
  19. before_each(function()
  20. t.write_file('test_file', 'test')
  21. clear { env = { XDG_STATE_HOME = xstate } }
  22. end)
  23. after_each(function()
  24. os.remove('test_file')
  25. end)
  26. it('trust then deny then remove a file using current buffer', function()
  27. local cwd = fn.getcwd()
  28. local hash = fn.sha256(t.read_file('test_file'))
  29. command('edit test_file')
  30. matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust'))
  31. local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  32. eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
  33. matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny'))
  34. trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  35. eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
  36. matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove'))
  37. trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  38. eq(string.format(''), vim.trim(trust))
  39. end)
  40. it('deny then trust then remove a file using current buffer', function()
  41. local cwd = fn.getcwd()
  42. local hash = fn.sha256(t.read_file('test_file'))
  43. command('edit test_file')
  44. matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny'))
  45. local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  46. eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
  47. matches('^Allowed ".*test_file" in trust database%.$', exec_capture('trust'))
  48. trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  49. eq(string.format('%s %s', hash, cwd .. pathsep .. 'test_file'), vim.trim(trust))
  50. matches('^Removed ".*test_file" from trust database%.$', exec_capture('trust ++remove'))
  51. trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  52. eq(string.format(''), vim.trim(trust))
  53. end)
  54. it('deny then remove a file using file path', function()
  55. local cwd = fn.getcwd()
  56. matches('^Denied ".*test_file" in trust database%.$', exec_capture('trust ++deny test_file'))
  57. local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  58. eq(string.format('! %s', cwd .. pathsep .. 'test_file'), vim.trim(trust))
  59. matches(
  60. '^Removed ".*test_file" from trust database%.$',
  61. exec_capture('trust ++remove test_file')
  62. )
  63. trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
  64. eq(string.format(''), vim.trim(trust))
  65. end)
  66. end)