Skip to content

Commit 1898f67

Browse files
authored
fix: Ensure the session token is properly passed to instance identity (#4923)
Fixes #4921.
1 parent 5be6c70 commit 1898f67

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cli/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func workspaceAgent() *cobra.Command {
165165
return "", err
166166
}
167167
client.SessionToken = resp.SessionToken
168-
return "", nil
168+
return resp.SessionToken, nil
169169
},
170170
EnvironmentVariables: map[string]string{
171171
"GIT_ASKPASS": executablePath,

cli/agent_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package cli_test
22

33
import (
44
"context"
5+
"runtime"
6+
"strings"
57
"testing"
68

9+
"github.com/google/uuid"
710
"github.com/stretchr/testify/assert"
811
"github.com/stretchr/testify/require"
912

@@ -194,6 +197,23 @@ func TestWorkspaceAgent(t *testing.T) {
194197
_, err := dialer.Ping(ctx)
195198
return err == nil
196199
}, testutil.WaitMedium, testutil.IntervalFast)
200+
201+
sshClient, err := dialer.SSHClient()
202+
require.NoError(t, err)
203+
defer sshClient.Close()
204+
session, err := sshClient.NewSession()
205+
require.NoError(t, err)
206+
defer session.Close()
207+
key := "CODER_AGENT_TOKEN"
208+
command := "sh -c 'echo $" + key + "'"
209+
if runtime.GOOS == "windows" {
210+
command = "cmd.exe /c echo %" + key + "%"
211+
}
212+
token, err := session.CombinedOutput(command)
213+
require.NoError(t, err)
214+
_, err = uuid.Parse(strings.TrimSpace(string(token)))
215+
require.NoError(t, err)
216+
197217
cancelFunc()
198218
err = <-errC
199219
require.NoError(t, err)

0 commit comments

Comments
 (0)