feat: delete metadata on SetOrganizationMetadata api (#11790)

# Which Problems Are Solved

Currently, to delete an Organization metadata key, callers must use a
separate
[DeleteMetadata](https://zitadel.com/docs/reference/api/org/zitadel.org.v2.OrganizationService.DeleteOrganizationMetadata)
API. This increases the complexity on client-side for operations where
metadata need to be synchronized.

# How the Problems Are Solved

Introduce deletion behavior to
[SetOrganizationMetadata](https://zitadel.com/docs/reference/api/org/zitadel.org.v2.OrganizationService.SetOrganizationMetadata):

When a metadata entry is passed with an empty value ("" / empty bytes):

- If the key exists → delete the key
- If the key does not exist → no-op (idempotent, no error)

# Additional Changes

n/a

# Additional Context

Relates to #11776

---------

Co-authored-by: Gayathri Vijayan <[email protected]>
Co-authored-by: Gayathri Vijayan <[email protected]>
This commit is contained in:
Vitor Bari Buccianti
2026-03-10 10:09:51 +00:00
committed by GitHub
co-authored by Gayathri Vijayan Gayathri Vijayan
parent 8b90ddb0b5
commit 62cb5bbb83
9 changed files with 267 additions and 142 deletions
@@ -54,7 +54,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
expectedMetadata := []*metadata.Metadata{
{Key: "key1", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value1")))},
}
assertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
},
},
{
@@ -78,7 +78,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
{Key: "key2", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value2")))},
{Key: "key3", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value3")))},
}
assertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
},
},
{
@@ -106,7 +106,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
expectedMetadata := []*metadata.Metadata{
{Key: "key1", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value2")))},
}
assertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
},
},
{
@@ -126,7 +126,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
expectedMetadata := []*metadata.Metadata{
{Key: "key1", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value1")))},
}
assertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
},
},
{
@@ -164,7 +164,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
expectedMetadata := []*metadata.Metadata{
{Key: "key1", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value1")))},
}
assertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
},
},
{
@@ -187,7 +187,7 @@ func TestServer_SetUserMetadata(t *testing.T) {
expectedMetadata := []*metadata.Metadata{
{Key: "key2", Value: []byte(base64.StdEncoding.EncodeToString([]byte("updated")))},
}
assertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getResponse.GetMetadata())
},
},
}
@@ -3590,7 +3590,7 @@ func TestServer_CreateUser_And_Compare(t *testing.T) {
{Key: "key1", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value1")))},
{Key: "key2", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value2")))},
}
assertMetadataEquals(t, expectedMetadata, getMetadataResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getMetadataResponse.GetMetadata())
},
}
},
@@ -3627,7 +3627,7 @@ func TestServer_CreateUser_And_Compare(t *testing.T) {
expectedMetadata := []*metadata.Metadata{
{Key: "key1", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value1")))},
}
assertMetadataEquals(t, expectedMetadata, getMetadataResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getMetadataResponse.GetMetadata())
},
}
},
@@ -3712,7 +3712,7 @@ func TestServer_CreateUser_And_Compare(t *testing.T) {
{Key: "key1", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value1")))},
{Key: "key2", Value: []byte(base64.StdEncoding.EncodeToString([]byte("value2")))},
}
assertMetadataEquals(t, expectedMetadata, getMetadataResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, getMetadataResponse.GetMetadata())
},
}
},
@@ -3805,19 +3805,6 @@ func TestServer_CreateUser_And_Compare(t *testing.T) {
}
}
func getMetadataMap(metadata []*metadata.Metadata) map[string][]byte {
metadataByKey := make(map[string][]byte, len(metadata))
for _, md := range metadata {
metadataByKey[md.Key] = md.Value
}
return metadataByKey
}
func assertMetadataEquals(t *testing.T, expected []*metadata.Metadata, actual []*metadata.Metadata) {
assert.Equal(t, len(expected), len(actual))
assert.Equal(t, getMetadataMap(expected), getMetadataMap(actual))
}
func TestServer_CreateUser_Permission(t *testing.T) {
newOrgOwnerEmail := integration.Email()
newOrg := Instance.CreateOrganization(IamCTX, integration.OrganizationName(), newOrgOwnerEmail)
@@ -4615,7 +4602,7 @@ func TestServer_UpdateUser_And_Compare(t *testing.T) {
{Key: "key2", Value: []byte("value2")},
{Key: "key3", Value: []byte("value3")},
}
assertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
},
}
},
@@ -4683,7 +4670,7 @@ func TestServer_UpdateUser_And_Compare(t *testing.T) {
{Key: "key1", Value: []byte("updated_value1")},
{Key: "key4", Value: []byte("value4")},
}
assertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
},
}
},
@@ -4740,7 +4727,7 @@ func TestServer_UpdateUser_And_Compare(t *testing.T) {
{Key: "key2", Value: []byte("value2")},
{Key: "key3", Value: []byte("value3")},
}
assertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
},
}
},
@@ -4802,7 +4789,7 @@ func TestServer_UpdateUser_And_Compare(t *testing.T) {
{Key: "key1", Value: []byte("updated_value1")},
{Key: "key4", Value: []byte("value4")},
}
assertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
integration.AssertMetadataEquals(t, expectedMetadata, listMetadataResponse.GetMetadata())
},
}
},