8000 fix: do not query user_link for deleted accounts by Emyrk · Pull Request #12112 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: do not query user_link for deleted accounts #12112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Feb 13, 2024
Prev Previous commit
Next Next commit
chore: creaet unit test to exercise failed email change bug
Changing emails on github fails if another deleted user exists
with the same link.
  • Loading branch information
Emyrk committed Feb 13, 2024
commit 5ee1017039d5a8fa6b3c93218d4e2fd03e906d6f
24 changes: 19 additions & 5 deletions coderd/userauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,8 @@ func TestUserOAuth2Github(t *testing.T) {

require.Equal(t, http.StatusUnauthorized, resp.StatusCode)
})

// The bug only is exercised when a deleted user with the same linked_id exists.
t.Run("ChangedEmail", func(t *testing.T) {
t.Parallel()

Expand All @@ -627,7 +629,7 @@ func TestUserOAuth2Github(t *testing.T) {
coderEmail,
}

client := coderdtest.New(t, &coderdtest.Options{
owner := coderdtest.New(t, &coderdtest.Options{
Auditor: auditor,
GithubOAuth2Config: &coderd.GithubOAuth2Config{
AllowSignups: true,
Expand All @@ -650,9 +652,19 @@ func TestUserOAuth2Github(t *testing.T) {
},
},
})
coderdtest.CreateFirstUser(t, owner)

ctx := testutil.Context(t, testutil.WaitLong)
// Create the user, then delete the user, then create again.
// This causes the email change to fail.
client := codersdk.New(owner.URL)

ctx := testutil.Context(t, testutil.WaitMedium)
// This should register the user
client, _ = fake.Login(t, client, jwt.MapClaims{})
deleted, err := client.User(ctx, "me")
err = owner.DeleteUser(ctx, deleted.ID)
require.NoError(t, err)

// Create the user again.
client, _ = fake.Login(t, client, jwt.MapClaims{})
user, err := client.User(ctx, "me")
require.NoError(t, err)
Expand All @@ -666,7 +678,8 @@ func TestUserOAuth2Github(t *testing.T) {
client, _ = fake.Login(t, client, jwt.MapClaims{})
user, err = client.User(ctx, "me")
require.NoError(t, err)
require.Equal(t, user.ID, userID)

require.Equal(t, user.ID, userID, "user_id is different, a new user was likely created")
require.Equal(t, user.Email, *gmailEmail.Email)

// Entirely change emails.
Expand All @@ -681,7 +694,8 @@ func TestUserOAuth2Github(t *testing.T) {
client, _ = fake.Login(t, client, jwt.MapClaims{})
user, err = client.User(ctx, "me")
require.NoError(t, err)
require.Equal(t, user.ID, userID)

require.Equal(t, user.ID, userID, "user_id is different, a new user was likely created")
require.Equal(t, user.Email, newEmail)
})
}
Expand Down
0