fix: Ensure the session token is properly passed to instance identity (#4923)

Fixes #4921.
This commit is contained in:
Kyle Carberry
2022-11-06 16:46:51 -06:00
committed by GitHub
parent 5be6c7071e
commit 1898f67fe0
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -165,7 +165,7 @@ func workspaceAgent() *cobra.Command {
return "", err
}
client.SessionToken = resp.SessionToken
return "", nil
return resp.SessionToken, nil
},
EnvironmentVariables: map[string]string{
"GIT_ASKPASS": executablePath,
+20
View File
@@ -2,8 +2,11 @@ package cli_test
import (
"context"
"runtime"
"strings"
"testing"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -194,6 +197,23 @@ func TestWorkspaceAgent(t *testing.T) {
_, err := dialer.Ping(ctx)
return err == nil
}, testutil.WaitMedium, testutil.IntervalFast)
sshClient, err := dialer.SSHClient()
require.NoError(t, err)
defer sshClient.Close()
session, err := sshClient.NewSession()
require.NoError(t, err)
defer session.Close()
key := "CODER_AGENT_TOKEN"
command := "sh -c 'echo $" + key + "'"
if runtime.GOOS == "windows" {
command = "cmd.exe /c echo %" + key + "%"
}
token, err := session.CombinedOutput(command)
require.NoError(t, err)
_, err = uuid.Parse(strings.TrimSpace(string(token)))
require.NoError(t, err)
cancelFunc()
err = <-errC
require.NoError(t, err)