Skip to content

Commit bd61a36

Browse files
atomassiAndrea Tomassilli
andauthored
Fix Guid handling for principal in Get-AzRoleAssignment (#28639)
Co-authored-by: Andrea Tomassilli <[email protected]>
1 parent 84c3717 commit bd61a36

File tree

5 files changed

+1361
-3
lines changed

5 files changed

+1361
-3
lines changed

src/Resources/Resources.Test/ScenarioTests/RoleAssignmentTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,12 @@ public void CreateRAWithObjectType()
245245
{
246246
TestRunner.RunTestScript("Test-CreateRAWithObjectType");
247247
}
248+
249+
[Fact]
250+
[Trait(Category.AcceptanceType, Category.CheckIn)]
251+
public void RAGuidFormatHandling()
252+
{
253+
TestRunner.RunTestScript("Test-RAGuidFormatHandling");
254+
}
248255
}
249256
}

src/Resources/Resources.Test/ScenarioTests/RoleAssignmentTests.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,34 @@ function Test-CreateRAWhenIdNotExist
925925

926926
Assert-Throws $function $ExpectedError
927927
}
928+
929+
<#
930+
.SYNOPSIS
931+
Validates that Get-AzRoleAssignment can filter client-side the role assignments by ObjectId in different GUID formats.
932+
#>
933+
function Test-RAGuidFormatHandling
934+
{
935+
$subscription = $(Get-AzContext).Subscription
936+
$scope = '/subscriptions/'+ $subscription[0].Id
937+
$principalId = "35e5fdfa-e80b-49b9-abf3-4c9a54f6b7a3"
938+
939+
$expected = @(Get-AzRoleAssignment -ObjectId $principalId -Scope $scope -AtScope)
940+
$expectedIds = $expected | Select-Object -ExpandProperty RoleAssignmentId | Sort-Object
941+
942+
# when non-Guid result should be empty
943+
$res = @(Get-AzRoleAssignment -ObjectId "abc" -Scope $scope -AtScope)
944+
Assert-AreEqual ($res.Count) 0
945+
946+
$guid = [guid]::Parse($principalId)
947+
$formats = @('N', 'D', 'B', 'P', 'X')
948+
foreach ($format in $formats) {
949+
$principalIdFormat = $guid.ToString($format)
950+
$actual = @(Get-AzRoleAssignment -ObjectId $principalIdFormat -Scope $scope -AtScope)
951+
Assert-AreEqual $expected.Count $actual.Count
952+
953+
if ($actual) {
954+
$actualIds = $actual | Select-Object -ExpandProperty RoleAssignmentId | Sort-Object
955+
Assert-AreEqual (@($expectedIds) -join ',') (@($actualIds) -join ',')
956+
}
957+
}
958+
}

0 commit comments

Comments
 (0)