From 87a0c2ba9af2826173a289ca37c6120d6d88a5a4 Mon Sep 17 00:00:00 2001 From: Diogo Matsubara Date: Tue, 8 Aug 2023 16:25:53 +0200 Subject: [PATCH] Also update username when credentials are updated (#225) * Also update username when credentials are updated During an upsert of server credentials, if the username changed, it needs to be updated as well. * Update test --- pkg/api/v1/router_server_secrets.go | 5 ++++- pkg/api/v1/router_server_secrets_test.go | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/api/v1/router_server_secrets.go b/pkg/api/v1/router_server_secrets.go index 40d7fde3..5408766c 100644 --- a/pkg/api/v1/router_server_secrets.go +++ b/pkg/api/v1/router_server_secrets.go @@ -133,7 +133,10 @@ func (r *Router) serverCredentialUpsert(c *gin.Context) { // search for records by server id and type id to see if we need to update or insert []string{models.ServerCredentialColumns.ServerID, models.ServerCredentialColumns.ServerCredentialTypeID}, // For updates only set the new value and updated at - boil.Whitelist(models.ServerCredentialColumns.Password, models.ServerCredentialColumns.UpdatedAt), + boil.Whitelist( + models.ServerCredentialColumns.Username, + models.ServerCredentialColumns.Password, + models.ServerCredentialColumns.UpdatedAt), // For inserts set server id, type id and value boil.Whitelist( models.ServerCredentialColumns.ServerID, diff --git a/pkg/api/v1/router_server_secrets_test.go b/pkg/api/v1/router_server_secrets_test.go index dcdf5d62..45d6d2c8 100644 --- a/pkg/api/v1/router_server_secrets_test.go +++ b/pkg/api/v1/router_server_secrets_test.go @@ -67,13 +67,14 @@ func TestIntegrationServerCredentialsUpsert(t *testing.T) { assert.NotEqual(t, "mynewSecret!", secret.Password) // Update the secret - _, err = s.Client.SetCredential(ctx, uuid, slug, "postgre", "mynewSecret!") + _, err = s.Client.SetCredential(ctx, uuid, slug, "foobar", "mynewSecret!") assert.NoError(t, err) // Get the new secret newSecret, _, err := s.Client.GetCredential(ctx, uuid, slug) assert.NoError(t, err) assert.Equal(t, "mynewSecret!", newSecret.Password) + assert.Equal(t, "foobar", newSecret.Username) // ensure timestamps were updated correctly assert.Equal(t, secret.CreatedAt, newSecret.CreatedAt) assert.NotEqual(t, newSecret.UpdatedAt, secret.UpdatedAt)