Skip to content

Commit

Permalink
Also update username when credentials are updated (#225)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
diogomatsubara committed Aug 8, 2023
1 parent 94b3a8b commit 87a0c2b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pkg/api/v1/router_server_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/api/v1/router_server_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 87a0c2b

Please sign in to comment.