aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/ssh_spec.lua
diff options
context:
space:
mode:
authorSiddhant Agarwal <68201519+siddhantdev@users.noreply.github.com>2025-08-18 09:10:28 +0530
committerGitHub <noreply@github.com>2025-08-17 20:40:28 -0700
commit1d40f677760d3fbaaaac6292841f2f5426bf83bd (patch)
tree152afdc38145063213b23194cdabbcea8e4bd1fb /test/functional/lua/ssh_spec.lua
parent37119ad0d24f4fb6052a7b1bc8ae2081fed621a2 (diff)
downloadrneovim-1d40f677760d3fbaaaac6292841f2f5426bf83bd.tar.gz
rneovim-1d40f677760d3fbaaaac6292841f2f5426bf83bd.tar.bz2
rneovim-1d40f677760d3fbaaaac6292841f2f5426bf83bd.zip
feat(ssh): SSH configuration parser #35027
Diffstat (limited to 'test/functional/lua/ssh_spec.lua')
-rw-r--r--test/functional/lua/ssh_spec.lua78
1 files changed, 78 insertions, 0 deletions
diff --git a/test/functional/lua/ssh_spec.lua b/test/functional/lua/ssh_spec.lua
new file mode 100644
index 0000000000..925a902ef0
--- /dev/null
+++ b/test/functional/lua/ssh_spec.lua
@@ -0,0 +1,78 @@
+local t = require('test.testutil')
+local parser = require('vim.net._ssh')
+local eq = t.eq
+
+describe('SSH parser', function()
+ it('parses SSH configuration strings', function()
+ local config = [[
+ Host *
+ ConnectTimeout 10
+ ServerAliveInterval 60
+ ServerAliveCountMax 3
+ # Use a specific key for any host not otherwise specified
+ # IdentityFile ~/.ssh/id_rsa
+
+ Host=dev
+ HostName=dev.example.com
+ User=devuser
+ Port=2222
+ IdentityFile=~/.ssh/id_rsa_dev
+
+ Host prod test
+ HostName 198.51.100.10
+ User admin
+ Port 22
+ IdentityFile ~/.ssh/id_rsa_prod
+ ForwardAgent yes
+
+ Host test
+ IdentitiesOnly yes
+
+ Host "quoted string"
+ User quote
+ Port 22
+
+ Match host foo host gh
+ HostName github.com
+ User git
+ IdentityFile ~/.ssh/id_rsa_github
+ IdentitiesOnly yes
+ ]]
+
+ eq({
+ 'dev',
+ 'prod',
+ 'test',
+ 'quoted string',
+ 'gh',
+ }, parser.parse_ssh_config(config))
+ end)
+
+ it('fails when a quote is not closed', function()
+ local config = [[
+ Host prod dev "test prod my
+ HostName 198.51.100.10
+ User admin
+ Port 22
+ IdentityFile ~/.ssh/id_rsa_prod
+ ForwardAgent yes
+ ]]
+
+ local ok, _ = pcall(parser.parse_ssh_config, config)
+ eq(false, ok)
+ end)
+
+ it('fails when the line ends with a single backslash', function()
+ local config = [[
+ Host prod test
+ HostName 198.51.100.10
+ User admin\
+ Port 22
+ IdentityFile ~/.ssh/id_rsa_prod
+ ForwardAgent yes
+ ]]
+
+ local ok, _ = pcall(parser.parse_ssh_config, config)
+ eq(false, ok)
+ end)
+end)