ssh_spec.lua (1742B)
1 local t = require('test.testutil') 2 local parser = require('vim.net._ssh') 3 local eq = t.eq 4 5 describe('SSH parser', function() 6 it('parses SSH configuration strings', function() 7 local config = [[ 8 Host * 9 ConnectTimeout 10 10 ServerAliveInterval 60 11 ServerAliveCountMax 3 12 # Use a specific key for any host not otherwise specified 13 # IdentityFile ~/.ssh/id_rsa 14 15 Host=dev 16 HostName=dev.example.com 17 User=devuser 18 Port=2222 19 IdentityFile=~/.ssh/id_rsa_dev 20 21 Host prod test 22 HostName 198.51.100.10 23 User admin 24 Port 22 25 IdentityFile ~/.ssh/id_rsa_prod 26 ForwardAgent yes 27 28 Host test 29 IdentitiesOnly yes 30 31 Host "quoted string" 32 User quote 33 Port 22 34 35 Match host foo host gh 36 HostName github.com 37 User git 38 IdentityFile ~/.ssh/id_rsa_github 39 IdentitiesOnly yes 40 ]] 41 42 eq({ 43 'dev', 44 'prod', 45 'test', 46 'quoted string', 47 'gh', 48 }, parser.parse_ssh_config(config)) 49 end) 50 51 it('fails when a quote is not closed', function() 52 local config = [[ 53 Host prod dev "test prod my 54 HostName 198.51.100.10 55 User admin 56 Port 22 57 IdentityFile ~/.ssh/id_rsa_prod 58 ForwardAgent yes 59 ]] 60 61 local ok, _ = pcall(parser.parse_ssh_config, config) 62 eq(false, ok) 63 end) 64 65 it('fails when the line ends with a single backslash', function() 66 local config = [[ 67 Host prod test 68 HostName 198.51.100.10 69 User admin\ 70 Port 22 71 IdentityFile ~/.ssh/id_rsa_prod 72 ForwardAgent yes 73 ]] 74 75 local ok, _ = pcall(parser.parse_ssh_config, config) 76 eq(false, ok) 77 end) 78 end)