Skip to content

Commit

Permalink
Ensure read-only fields are not overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
haoming29 committed Dec 19, 2023
1 parent 483100b commit aa7efaa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions registry/registry_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,14 @@ func updateNamespace(ns *Namespace) error {
return errors.Wrap(err, "Fail to marshall AdminMetadata")
}

query := `UPDATE namespace SET pubkey = ?, identity = ?, admin_metadata = ? WHERE id = ?`
// We intentionally exclude updating "identity" as this should only be updated
// when user registered through Pelican client with identity
query := `UPDATE namespace SET pubkey = ?, admin_metadata = ? WHERE id = ?`
tx, err := db.Begin()
if err != nil {
return err
}
_, err = tx.Exec(query, ns.Pubkey, ns.Identity, strAdminMetadata, ns.ID)
_, err = tx.Exec(query, ns.Pubkey, strAdminMetadata, ns.ID)
if err != nil {
if errRoll := tx.Rollback(); errRoll != nil {
log.Errorln("Failed to rollback transaction:", errRoll)
Expand Down
3 changes: 3 additions & 0 deletions registry/registry_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func TestGetNamespacesByUserID(t *testing.T) {
})

t.Run("return-user-namespace-with-valid-userID", func(t *testing.T) {
defer resetNamespaceDB(t)
err := insertMockDBData(mockNssWithMixed)
require.NoError(t, err)
err = insertMockDBData([]Namespace{mockNamespace("/user1", "", "user1", AdminMetadata{UserID: "user1"})})
Expand All @@ -215,6 +216,7 @@ func TestGetNamespacesByUserID(t *testing.T) {
})

t.Run("return-multiple-user-namespaces-with-valid-userID", func(t *testing.T) {
defer resetNamespaceDB(t)
err := insertMockDBData(mockNssWithMixed)
require.NoError(t, err)
err = insertMockDBData([]Namespace{mockNamespace("/user1", "", "user1", AdminMetadata{UserID: "user1"})})
Expand Down Expand Up @@ -295,6 +297,7 @@ func TestUpdateNamespace(t *testing.T) {
defer teardownMockNamespaceDB(t)

t.Run("update-on-dne-entry-returns-error", func(t *testing.T) {
defer resetNamespaceDB(t)
mockNs := mockNamespace("/test", "", "", AdminMetadata{})
err := updateNamespace(&mockNs)
assert.Error(t, err)
Expand Down

0 comments on commit aa7efaa

Please sign in to comment.