TestLocalUnixForwarding tests direct-streamlocal@openssh.com, which is what podman remote (issue #12409) and VSCode Remote (issue #5295) use to reach Unix domain sockets on the remote host through SSH. The client opens a channel to a Unix socket path on the server, and data is proxied through.
(t *testing.T)
| 425 | // Unix domain sockets on the remote host through SSH. The client opens a |
| 426 | // channel to a Unix socket path on the server, and data is proxied through. |
| 427 | func TestLocalUnixForwarding(t *testing.T) { |
| 428 | debugTest.Store(true) |
| 429 | t.Cleanup(func() { |
| 430 | debugTest.Store(false) |
| 431 | }) |
| 432 | |
| 433 | // Create a Unix socket server in /tmp that simulates a service like |
| 434 | // podman's API socket at /run/user/<uid>/podman/podman.sock. |
| 435 | socketDir, err := os.MkdirTemp("", "tailssh-test-") |
| 436 | if err != nil { |
| 437 | t.Fatal(err) |
| 438 | } |
| 439 | t.Cleanup(func() { os.RemoveAll(socketDir) }) |
| 440 | socketPath := filepath.Join(socketDir, "test-service.sock") |
| 441 | |
| 442 | ul, err := net.Listen("unix", socketPath) |
| 443 | if err != nil { |
| 444 | t.Fatal(err) |
| 445 | } |
| 446 | t.Cleanup(func() { ul.Close() }) |
| 447 | |
| 448 | // The service echoes back whatever it receives, like an API server would. |
| 449 | go func() { |
| 450 | for { |
| 451 | conn, err := ul.Accept() |
| 452 | if err != nil { |
| 453 | return |
| 454 | } |
| 455 | go func() { |
| 456 | defer conn.Close() |
| 457 | io.Copy(conn, conn) |
| 458 | }() |
| 459 | } |
| 460 | }() |
| 461 | |
| 462 | // Start Tailscale SSH server with local port forwarding enabled. |
| 463 | addr := testServerWithOpts(t, testServerOpts{ |
| 464 | username: "testuser", |
| 465 | allowLocalPortForwarding: true, |
| 466 | }) |
| 467 | |
| 468 | // Connect to the Tailscale SSH server. |
| 469 | cl, err := ssh.Dial("tcp", addr, &ssh.ClientConfig{ |
| 470 | HostKeyCallback: ssh.InsecureIgnoreHostKey(), |
| 471 | }) |
| 472 | if err != nil { |
| 473 | t.Fatal(err) |
| 474 | } |
| 475 | t.Cleanup(func() { cl.Close() }) |
| 476 | |
| 477 | // Open a direct-streamlocal@openssh.com channel to the Unix socket, |
| 478 | // exactly as podman remote does. |
| 479 | conn, err := cl.Dial("unix", socketPath) |
| 480 | if err != nil { |
| 481 | t.Fatalf("failed to dial unix socket through SSH: %s", err) |
| 482 | } |
| 483 | defer conn.Close() |
| 484 |
nothing calls this directly
no test coverage detected
searching dependent graphs…