MCPcopy
hub / github.com/tailscale/tailscale / TestMultipleRecorders

Function TestMultipleRecorders

ssh/tailssh/tailssh_test.go:601–688  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

599}
600
601func TestMultipleRecorders(t *testing.T) {
602 if runtime.GOOS != "linux" && runtime.GOOS != "darwin" {
603 t.Skipf("skipping on %q; only runs on linux and darwin", runtime.GOOS)
604 }
605 done := make(chan struct{})
606 recordingServer := mockRecordingServer(t, func(w http.ResponseWriter, r *http.Request) {
607 defer close(done)
608 w.WriteHeader(http.StatusOK)
609 w.(http.Flusher).Flush()
610 io.ReadAll(r.Body)
611 })
612 badRecorder, err := net.Listen("tcp", ":0")
613 if err != nil {
614 t.Fatal(err)
615 }
616 badRecorderAddr := badRecorder.Addr().String()
617 badRecorder.Close()
618
619 badRecordingServer500 := mockRecordingServer(t, func(w http.ResponseWriter, r *http.Request) {
620 w.WriteHeader(http.StatusInternalServerError)
621 })
622
623 s := &server{
624 logf: tstest.WhileTestRunningLogger(t),
625 lb: &localState{
626 sshEnabled: true,
627 varRoot: t.TempDir(),
628 matchingRule: newSSHRule(
629 &tailcfg.SSHAction{
630 Accept: true,
631 Recorders: []netip.AddrPort{
632 netip.MustParseAddrPort(badRecorderAddr),
633 netip.MustParseAddrPort(badRecordingServer500.Listener.Addr().String()),
634 netip.MustParseAddrPort(recordingServer.Listener.Addr().String()),
635 },
636 OnRecordingFailure: &tailcfg.SSHRecorderFailureAction{
637 RejectSessionWithMessage: "session rejected",
638 TerminateSessionWithMessage: "session terminated",
639 },
640 },
641 ),
642 },
643 }
644 defer s.Shutdown()
645
646 src, dst := must.Get(netip.ParseAddrPort("100.100.100.101:2231")), must.Get(netip.ParseAddrPort("100.100.100.102:22"))
647 sc, dc := memnet.NewTCPConn(src, dst, 1024)
648
649 const sshUser = "alice"
650 cfg := &testssh.ClientConfig{
651 User: sshUser,
652 HostKeyCallback: testssh.InsecureIgnoreHostKey(),
653 }
654
655 var wg sync.WaitGroup
656 wg.Go(func() {
657 c, chans, reqs, err := testssh.NewClientConn(sc, sc.RemoteAddr().String(), cfg)
658 if err != nil {

Callers

nothing calls this directly

Calls 15

ShutdownMethod · 0.95
CloseMethod · 0.95
NewSessionMethod · 0.95
CloseMethod · 0.95
CombinedOutputMethod · 0.95
HandleSSHConnMethod · 0.95
WhileTestRunningLoggerFunction · 0.92
GetFunction · 0.92
NewTCPConnFunction · 0.92
mockRecordingServerFunction · 0.85
newSSHRuleFunction · 0.85
GoMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…