neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

trust_spec.lua (3269B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local eq = t.eq
      5 local clear = n.clear
      6 local command = n.command
      7 local exec_capture = n.exec_capture
      8 local matches = t.matches
      9 local pathsep = n.get_pathsep()
     10 local is_os = t.is_os
     11 local fn = n.fn
     12 
     13 describe(':trust', function()
     14  local xstate = 'Xstate_ex_trust'
     15  local test_file = 'Xtest_functional_ex_cmds_trust'
     16 
     17  before_each(function()
     18    n.mkdir_p(xstate .. pathsep .. (is_os('win') and 'nvim-data' or 'nvim'))
     19    t.write_file(test_file, 'test')
     20    clear { env = { XDG_STATE_HOME = xstate } }
     21  end)
     22 
     23  after_each(function()
     24    os.remove(test_file)
     25    n.rmdir(xstate)
     26  end)
     27 
     28  --- @param s string
     29  local function fmt(s)
     30    return s:format(test_file)
     31  end
     32 
     33  it('is not executed when inside false condition', function()
     34    command(fmt('edit %s'))
     35    eq('', exec_capture('if 0 | trust | endif'))
     36    eq(nil, vim.uv.fs_stat(fn.stdpath('state') .. pathsep .. 'trust'))
     37  end)
     38 
     39  it('trust then deny then remove a file using current buffer', function()
     40    local cwd = fn.getcwd()
     41    local hash = fn.sha256(assert(t.read_file(test_file)))
     42 
     43    command(fmt('edit %s'))
     44    matches(fmt('^Allowed in trust database%%: ".*%s"$'), exec_capture('trust'))
     45    local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     46    eq(string.format('%s %s', hash, cwd .. pathsep .. test_file), vim.trim(trust))
     47 
     48    matches(fmt('^Denied in trust database%%: ".*%s"$'), exec_capture('trust ++deny'))
     49    trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     50    eq(string.format('! %s', cwd .. pathsep .. test_file), vim.trim(trust))
     51 
     52    matches(fmt('^Removed from trust database%%: ".*%s"$'), exec_capture('trust ++remove'))
     53    trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     54    eq(string.format(''), vim.trim(trust))
     55  end)
     56 
     57  it('deny then trust then remove a file using current buffer', function()
     58    local cwd = fn.getcwd()
     59    local hash = fn.sha256(assert(t.read_file(test_file)))
     60 
     61    command(fmt('edit %s'))
     62    matches(fmt('^Denied in trust database%%: ".*%s"$'), exec_capture('trust ++deny'))
     63    local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     64    eq(string.format('! %s', cwd .. pathsep .. test_file), vim.trim(trust))
     65 
     66    matches(fmt('^Allowed in trust database%%: ".*%s"$'), exec_capture('trust'))
     67    trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     68    eq(string.format('%s %s', hash, cwd .. pathsep .. test_file), vim.trim(trust))
     69 
     70    matches(fmt('^Removed from trust database%%: ".*%s"$'), exec_capture('trust ++remove'))
     71    trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     72    eq(string.format(''), vim.trim(trust))
     73  end)
     74 
     75  it('deny then remove a file using file path', function()
     76    local cwd = fn.getcwd()
     77 
     78    matches(fmt('^Denied in trust database%%: ".*%s"$'), exec_capture(fmt('trust ++deny %s')))
     79    local trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     80    eq(string.format('! %s', cwd .. pathsep .. test_file), vim.trim(trust))
     81 
     82    matches(fmt('^Removed from trust database%%: ".*%s"$'), exec_capture(fmt('trust ++remove %s')))
     83    trust = t.read_file(fn.stdpath('state') .. pathsep .. 'trust')
     84    eq(string.format(''), vim.trim(trust))
     85  end)
     86 end)