From aa7efaa69cd231a2df61c4026554e216f3397d46 Mon Sep 17 00:00:00 2001 From: Haoming Meng Date: Tue, 19 Dec 2023 23:41:26 +0000 Subject: [PATCH] Ensure read-only fields are not overwritten --- registry/registry_db.go | 6 ++++-- registry/registry_db_test.go | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/registry/registry_db.go b/registry/registry_db.go index 740f9c5ee..64411722c 100644 --- a/registry/registry_db.go +++ b/registry/registry_db.go @@ -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) diff --git a/registry/registry_db_test.go b/registry/registry_db_test.go index 54f7e676c..e751a8cbd 100644 --- a/registry/registry_db_test.go +++ b/registry/registry_db_test.go @@ -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"})}) @@ -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"})}) @@ -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)