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

Function TestGitSSH

cli/gitssh_test.go:114–242  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestGitSSH(t *testing.T) {
115 t.Parallel()
116 t.Run("Dial", func(t *testing.T) {
117 t.Parallel()
118
119 setupCtx := testutil.Context(t, testutil.WaitLong)
120 client, token, pubkey := prepareTestGitSSH(setupCtx, t)
121 var inc atomic.Int64
122 errC := make(chan error, 1)
123 addr := serveSSHForGitSSH(t, func(s ssh.Session) {
124 inc.Add(1)
125 t.Log("got authenticated session")
126 select {
127 case errC <- s.Exit(0):
128 default:
129 t.Error("error channel is full")
130 }
131 }, pubkey)
132
133 // set to agent config dir
134 inv, _ := clitest.New(t,
135 "gitssh",
136 "--agent-url", client.SDK.URL.String(),
137 "--agent-token", token,
138 "--",
139 fmt.Sprintf("-p%d", addr.Port),
140 "-o", "StrictHostKeyChecking=no",
141 "-o", "IdentitiesOnly=yes",
142 "127.0.0.1",
143 )
144 // This occasionally times out at 15s on Windows CI runners. Use a
145 // longer timeout to reduce flakes.
146 ctx := testutil.Context(t, testutil.WaitSuperLong)
147 err := inv.WithContext(ctx).Run()
148 require.NoError(t, err)
149 require.EqualValues(t, 1, inc.Load())
150
151 err = <-errC
152 require.NoError(t, err, "error in agent execute")
153 })
154
155 t.Run("Local SSH Keys", func(t *testing.T) {
156 t.Parallel()
157
158 home := t.TempDir()
159 sshdir := filepath.Join(home, ".ssh")
160 err := os.MkdirAll(sshdir, 0o700)
161 require.NoError(t, err)
162
163 idFile := filepath.Join(sshdir, "id_ed25519")
164 privkey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
165 require.NoError(t, err)
166 localPubkey, err := gossh.NewPublicKey(&privkey.PublicKey)
167 require.NoError(t, err)
168 writePrivateKeyToFile(t, idFile, privkey)
169
170 setupCtx := testutil.Context(t, testutil.WaitSuperLong)
171 client, token, coderPubkey := prepareTestGitSSH(setupCtx, t)

Callers

nothing calls this directly

Calls 15

ContextFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
prepareTestGitSSHFunction · 0.85
serveSSHForGitSSHFunction · 0.85
writePrivateKeyToFileFunction · 0.85
LogMethod · 0.80
ExitMethod · 0.80
WithContextMethod · 0.80
MkdirAllMethod · 0.80
FatalMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected