mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
fix: Protect codersdk.Client SessionToken so it can be updated (#4965)
This feature is used by the coder agent to exchange a new token. By protecting the SessionToken via mutex we ensure there are no data races when accessing it.
This commit is contained in:
committed by
GitHub
parent
8cadb33396
commit
26ab0d37c1
@ -280,7 +280,7 @@ func TestPostLogin(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
split := strings.Split(client.SessionToken, "-")
|
||||
split := strings.Split(client.SessionToken(), "-")
|
||||
key, err := client.GetAPIKey(ctx, admin.UserID.String(), split[0])
|
||||
require.NoError(t, err, "fetch login key")
|
||||
require.Equal(t, int64(86400), key.LifetimeSeconds, "default should be 86400")
|
||||
@ -356,7 +356,7 @@ func TestPostLogout(t *testing.T) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
keyID := strings.Split(client.SessionToken, "-")[0]
|
||||
keyID := strings.Split(client.SessionToken(), "-")[0]
|
||||
apiKey, err := client.GetAPIKey(ctx, admin.UserID.String(), keyID)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, keyID, apiKey.ID, "API key should exist in the database")
|
||||
@ -676,7 +676,7 @@ func TestUpdateUserPassword(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
client.SessionToken = resp.SessionToken
|
||||
client.SetSessionToken(resp.SessionToken)
|
||||
|
||||
// Trying to get an API key should fail since all keys are deleted
|
||||
// on password change.
|
||||
@ -1359,7 +1359,7 @@ func TestWorkspacesByUser(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
newUserClient := codersdk.New(client.URL)
|
||||
newUserClient.SessionToken = auth.SessionToken
|
||||
newUserClient.SetSessionToken(auth.SessionToken)
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
|
||||
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
|
||||
|
Reference in New Issue
Block a user