Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed `ManagedServiceIdentity` deserialization when services return empty string for `principalId` or `tenantId`.

### Other Changes

## 1.4.0 (2023-02-10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static void Write(Utf8JsonWriter writer, ManagedServiceIdentity model,
JsonSerializer.Serialize(writer, model.ManagedServiceIdentityType, options);
if (Optional.IsCollectionDefined(model.UserAssignedIdentities))
{
writer.WritePropertyName("userAssignedIdentities");
writer.WritePropertyName("userAssignedIdentities"u8);
writer.WriteStartObject();
foreach (var item in model.UserAssignedIdentities)
{
Expand All @@ -48,32 +48,32 @@ internal static ManagedServiceIdentity DeserializeManagedServiceIdentity(JsonEle
Optional<IDictionary<ResourceIdentifier, UserAssignedIdentity>> userAssignedIdentities = default;
foreach (var property in element.EnumerateObject())
{
if (property.NameEquals("principalId"))
if (property.NameEquals("principalId"u8))
{
if (property.Value.ValueKind == JsonValueKind.Null)
if (property.Value.ValueKind == JsonValueKind.Null || property.Value.GetString().Length == 0)
{
property.ThrowNonNullablePropertyIsNull();
continue;
}
principalId = property.Value.GetGuid();
continue;
}
if (property.NameEquals("tenantId"))
if (property.NameEquals("tenantId"u8))
{
if (property.Value.ValueKind == JsonValueKind.Null)
if (property.Value.ValueKind == JsonValueKind.Null || property.Value.GetString().Length == 0)
{
property.ThrowNonNullablePropertyIsNull();
continue;
}
tenantId = property.Value.GetGuid();
continue;
}
if (property.NameEquals("type"))
if (property.NameEquals("type"u8))
{
type = JsonSerializer.Deserialize<ManagedServiceIdentityType>("{"+property.ToString()+"}", options);
continue;
}
if (property.NameEquals("userAssignedIdentities"))
if (property.NameEquals("userAssignedIdentities"u8))
{
if (property.Value.ValueKind == JsonValueKind.Null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public void TestDeserializerInvalidType()
Assert.AreEqual("77563a98-c9d9-4f7b-a7af-592d21fa2153", user.Values.First().PrincipalId.ToString());
}

[TestCase]
public void TestDeserializerNoneWithEmptyStringIds()
{
var identityJsonProperty = DeserializerHelper("NoneEmptyStringIds.json");
#if DEBUG
Assert.Throws<JsonException>(delegate { ManagedServiceIdentity.DeserializeManagedServiceIdentity(identityJsonProperty.Value); });
#else
ManagedServiceIdentity back = ManagedServiceIdentity.DeserializeManagedServiceIdentity(identityJsonProperty.Value);
Assert.AreEqual(ManagedServiceIdentityType.None, back.ManagedServiceIdentityType);
#endif
}

[TestCase]
public void TestDeserializerValidInnerExtraField()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"identity": {
"principalId": "",
"tenantId": "",
"type": "None"
}
}