@@ -10,6 +10,8 @@ import (
10
10
"fmt"
11
11
"io"
12
12
"net"
13
+ "net/http"
14
+ "net/http/httptest"
13
15
"os"
14
16
"os/exec"
15
17
"path/filepath"
@@ -408,6 +410,58 @@ func TestSSH(t *testing.T) {
408
410
<- cmdDone
409
411
})
410
412
413
+ t .Run ("RemoteForward" , func (t * testing.T ) {
414
+ if runtime .GOOS == "windows" {
415
+ t .Skip ("Test not supported on windows" )
416
+ }
417
+
418
+ t .Parallel ()
419
+
420
+ httpServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
421
+ w .Write ([]byte ("hello world" ))
422
+ }))
423
+ defer httpServer .Close ()
424
+
425
+ client , workspace , agentToken := setupWorkspaceForAgent (t , nil )
426
+
427
+ agentClient := agentsdk .New (client .URL )
428
+ agentClient .SetSessionToken (agentToken )
429
+ agentCloser := agent .New (agent.Options {
430
+ Client : agentClient ,
431
+ Logger : slogtest .Make (t , nil ).Named ("agent" ),
432
+ })
433
+ defer agentCloser .Close ()
434
+
435
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
436
+ defer cancel ()
437
+
438
+ inv , root := clitest .New (t ,
439
+ "ssh" ,
440
+ workspace .Name ,
441
+ "--remote-forward" ,
442
+ "8222:" + httpServer .Listener .Addr ().String (),
443
+ )
444
+ clitest .SetupConfig (t , client , root )
445
+ pty := ptytest .New (t ).Attach (inv )
446
+ inv .Stderr = pty .Output ()
447
+ cmdDone := tGo (t , func () {
448
+ err := inv .WithContext (ctx ).Run ()
449
+ assert .NoError (t , err , "ssh command failed" )
450
+ })
451
+
452
+ // Wait for the prompt or any output really to indicate the command has
453
+ // started and accepting input on stdin.
454
+ _ = pty .Peek (ctx , 1 )
455
+
456
+ // Download the test page
457
+ pty .WriteLine ("curl localhost:8222" )
458
+ pty .ExpectMatch ("hello world" )
459
+
460
+ // And we're done.
461
+ pty .WriteLine ("exit" )
462
+ <- cmdDone
463
+ })
464
+
411
465
t .Run ("FileLogging" , func (t * testing.T ) {
412
466
t .Parallel ()
413
467
0 commit comments