Skip to content

Commit

Permalink
Use curl and ssh from Yggdrasil in the tests
Browse files Browse the repository at this point in the history
This makes them slightly more portable, though we still need to lose the
dependency on sshpass to make them truly portable.
  • Loading branch information
JamesWrigley committed Jan 9, 2024
1 parent 94bda77 commit 5f49cdb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/LibSSHTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Sockets

import Aqua
import Literate
import Documenter
import Documenter: DocMeta
import CURL_jll: curl
import OpenSSH_jll
import ReTest: @testset, @test, @test_throws, @test_nowarn, @test_logs

import LibSSH
Expand Down Expand Up @@ -83,8 +83,12 @@ end
@test server.ptr == nothing
end

# Helper function to set up an `ssh` command
ssh_cmd(cmd::Cmd) = ignorestatus(`sshpass -p bar ssh -o NoHostAuthenticationForLocalhost=yes $cmd`)
# Helper function to set up an `ssh` command. Slightly ugly workaround to
# set the necessary environment variables comes from:
# https://github.com/JuliaLang/julia/issues/39282
# Also note that we set `-F none` to disabling reading user config files.
openssh_cmd = OpenSSH_jll.ssh()
ssh_cmd(cmd::Cmd) = ignorestatus(Cmd(`sshpass -p bar $(openssh_cmd.exec) -F none -o NoHostAuthenticationForLocalhost=yes $cmd`; env=openssh_cmd.env))

@testset "Password authentication and session channels" begin
# More complicated test, where we run a command and check the output
Expand Down Expand Up @@ -118,7 +122,7 @@ end
@testset "Direct port forwarding" begin
# Test the dummy HTTP server we'll use later
http_server(9090) do
@test run(`curl localhost:9090`).exitcode == 0
@test run(`$(curl()) localhost:9090`).exitcode == 0
end

# Test direct port forwarding
Expand All @@ -139,7 +143,7 @@ end
# on the listening port, so we only need the HTTP server running
# while we're making the request.
http_server(9090) do
curl_process = run(ignorestatus(`curl localhost:8080`))
curl_process = run(ignorestatus(`$(curl()) localhost:8080`))
@test curl_process.exitcode == 0
end

Expand Down Expand Up @@ -319,7 +323,7 @@ end
demo_server_with_session(2222) do session
ssh.Forwarder(session, 8080, "localhost", 9090) do forwarder
http_server(9090) do
curl_proc = run(ignorestatus(`curl localhost:8080`); wait=false)
curl_proc = run(ignorestatus(`$(curl()) localhost:8080`); wait=false)
try
wait(curl_proc)
finally
Expand Down
2 changes: 2 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
CURL_jll = "b21e61f3-bafc-59ac-ab14-4c5c62d6588d"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
OpenSSH_jll = "9bd350c2-7e96-507f-8002-3f2e150b4e1b"
ReTest = "e0db7c4e-2690-44b9-bad6-7687da720f89"
Sockets = "6462fe0b-24de-5631-8697-dd941f90decc"

0 comments on commit 5f49cdb

Please sign in to comment.