robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
50c50ab119
master
1local t =require ( 'test.testutil' ) 2local parser =require ( 'vim.net._ssh' ) 3local describe , it =t . describe , t . it 4local eq =t . eq 5 6describe ( 'SSH parser' , function () 7it ( 'parses SSH configuration strings' , function () 8local config =[[ 9Host * 10ConnectTimeout 10 11ServerAliveInterval 60 12ServerAliveCountMax 3 13# Use a specific key for any host not otherwise specified 14# IdentityFile ~/.ssh/id_rsa 15 16Host=dev 17HostName=dev.example.com 18User=devuser 19Port=2222 20IdentityFile=~/.ssh/id_rsa_dev 21 22Host prod test 23HostName 198.51.100.10 24User admin 25Port 22 26IdentityFile ~/.ssh/id_rsa_prod 27ForwardAgent yes 28 29Host test 30IdentitiesOnly yes 31 32Host "quoted string" 33User quote 34Port 22 35 36Match host foo host gh 37HostName github.com 38User git 39IdentityFile ~/.ssh/id_rsa_github 40IdentitiesOnly yes 41]] 42 43eq ( { 44'dev' , 45'prod' , 46'test' , 47'quoted string' , 48'gh' , 49} , parser . parse_ssh_config ( config )) 50end ) 51 52it ( 'ignores repeated and trailing separators' , function () 53-- Runs of separators between values, and trailing whitespace before the 54-- line break, must not yield empty hostnames. 55local config =table . concat ( { 56'Host alpha beta ' , 57' HostName example.com' , 58'' , 59} , '\n' ) 60 61eq ( { 'alpha' , 'beta' } , parser . parse_ssh_config ( config )) 62end ) 63 64it ( 'fails when a quote is not closed' , function () 65local config =[[ 66Host prod dev "test prod my 67HostName 198.51.100.10 68User admin 69Port 22 70IdentityFile ~/.ssh/id_rsa_prod 71ForwardAgent yes 72]] 73 74local ok , _ =pcall ( parser . parse_ssh_config , config ) 75eq ( false , ok ) 76end ) 77 78it ( 'fails when the line ends with a single backslash' , function () 79local config =[[ 80Host prod test 81HostName 198.51.100.10 82User admin\ 83Port 22 84IdentityFile ~/.ssh/id_rsa_prod 85ForwardAgent yes 86]] 87 88local ok , _ =pcall ( parser . parse_ssh_config , config ) 89eq ( false , ok ) 90end ) 91end )