trust_spec.lua 3.0 KB

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