MCPcopy Index your code
hub / github.com/coder/coder / serveSSHForGitSSH

Function serveSSHForGitSSH

cli/gitssh_test.go:65–98  ·  view source on GitHub ↗
(t *testing.T, handler func(ssh.Session), pubkeys ...gossh.PublicKey)

Source from the content-addressed store, hash-verified

63}
64
65func serveSSHForGitSSH(t *testing.T, handler func(ssh.Session), pubkeys ...gossh.PublicKey) *net.TCPAddr {
66 t.Helper()
67
68 // start ssh server
69 l, err := net.Listen("tcp", "localhost:0")
70 require.NoError(t, err)
71 t.Cleanup(func() { _ = l.Close() })
72
73 serveOpts := []ssh.Option{
74 ssh.PublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
75 for _, pubkey := range pubkeys {
76 if ssh.KeysEqual(pubkey, key) {
77 return true
78 }
79 }
80 return false
81 }),
82 }
83 errC := make(chan error, 1)
84 go func() {
85 // as long as we get a successful session we don't care if the server errors
86 errC <- ssh.Serve(l, handler, serveOpts...)
87 }()
88 t.Cleanup(func() {
89 _ = l.Close() // Ensure server shutdown.
90 <-errC
91 })
92
93 // start ssh session
94 addr, ok := l.Addr().(*net.TCPAddr)
95 require.True(t, ok)
96
97 return addr
98}
99
100func writePrivateKeyToFile(t *testing.T, name string, key *ecdsa.PrivateKey) {
101 t.Helper()

Callers 1

TestGitSSHFunction · 0.85

Calls 6

HelperMethod · 0.65
ListenMethod · 0.65
CleanupMethod · 0.65
CloseMethod · 0.65
ServeMethod · 0.45
AddrMethod · 0.45

Tested by

no test coverage detected