Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,12 @@ public void CreateRAWithObjectType()
{
TestRunner.RunTestScript("Test-CreateRAWithObjectType");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RAGuidFormatHandling()
{
TestRunner.RunTestScript("Test-RAGuidFormatHandling");
}
}
}
27 changes: 27 additions & 0 deletions src/Resources/Resources.Test/ScenarioTests/RoleAssignmentTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -925,3 +925,30 @@ function Test-CreateRAWhenIdNotExist

Assert-Throws $function $ExpectedError
}

<#
.SYNOPSIS
Validates that Get-AzRoleAssignment can filter client-side the role assignments by ObjectId in different GUID formats.
#>
function Test-RAGuidFormatHandling
{
$subscription = $(Get-AzContext).Subscription
$scope = '/subscriptions/'+ $subscription[0].Id
$principalId = "35e5fdfa-e80b-49b9-abf3-4c9a54f6b7a3"

$expected = @(Get-AzRoleAssignment -ObjectId $principalId -Scope $scope -AtScope)
$expectedIds = $expected | Select-Object -ExpandProperty RoleAssignmentId | Sort-Object

$guid = [guid]::Parse($principalId)
$formats = @('N', 'D', 'B', 'P', 'X')
foreach ($format in $formats) {
$principalIdFormat = $guid.ToString($format)
$actual = @(Get-AzRoleAssignment -ObjectId $principalIdFormat -Scope $scope -AtScope)
Assert-AreEqual $expected.Count $actual.Count

if ($actual) {
$actualIds = $actual | Select-Object -ExpandProperty RoleAssignmentId | Sort-Object
Assert-AreEqual (@($expectedIds) -join ',') (@($actualIds) -join ',')
}
}
}
Loading