Skip to content

Commit dd1009a

Browse files
authored
Merge pull request #4346 from darshanhs90/preview
update removeroleassignment comparison to case insensitive
2 parents 342f0f4 + fdddee6 commit dd1009a

File tree

5 files changed

+2453
-1
lines changed

5 files changed

+2453
-1
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@
678678
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaValidateInputParameters.json">
679679
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
680680
</None>
681+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaDeletionByScope.json">
682+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
683+
</None>
681684
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleDefinitionTests\RdNegativeScenarios.json">
682685
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
683686
</None>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ public void RaByServicePrincipal()
9696
ResourcesController.NewInstance.RunPsTest("Test-RaByServicePrincipal");
9797
}
9898

99+
[Fact]
100+
[Trait(Category.AcceptanceType, Category.CheckIn)]
101+
public void RaDeletionByScope()
102+
{
103+
ResourcesController.NewInstance.RunPsTest("Test-RaDeletionByScope");
104+
}
105+
99106
[Fact]
100107
[Trait(Category.AcceptanceType, Category.CheckIn)]
101108
public void RaByUpn()

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,41 @@ function Test-RaAuthorizationChangeLog
314314
Assert-True { $log1.Count -ge 1 } "At least one record should be returned for the user"
315315
}
316316

317+
<#
318+
.SYNOPSIS
319+
Tests verifies creation and deletion of a RoleAssignments by Scope irrespective of the case
320+
#>
321+
function Test-RaDeletionByScope
322+
{
323+
# Setup
324+
Add-Type -Path ".\\Microsoft.Azure.Commands.Resources.dll"
317325

326+
$definitionName = 'Reader'
327+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
328+
$subscription = Get-AzureRmSubscription
329+
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
330+
$scope = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
331+
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
332+
333+
# Test
334+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
335+
$newAssignment = New-AzureRmRoleAssignment `
336+
-ObjectId $users[0].Id.Guid `
337+
-RoleDefinitionName $definitionName `
338+
-Scope $scope
339+
$newAssignment.Scope = $scope.toUpper()
340+
341+
# cleanup
342+
DeleteRoleAssignment $newAssignment
343+
344+
# Assert
345+
Assert-NotNull $newAssignment
346+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
347+
Assert-AreEqual $scope $newAssignment.Scope
348+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
349+
350+
VerifyRoleAssignmentDeleted $newAssignment
351+
}
318352

319353
<#
320354
.SYNOPSIS

src/ResourceManager/Resources/Commands.Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests/RaDeletionByScope.json

Lines changed: 2408 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Resources/Commands.Resources/Models.Authorization/AuthorizationClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public IEnumerable<PSRoleAssignment> RemoveRoleAssignment(FilterRoleAssignmentsO
317317
// but an edge case can have multiple role assignments to the same role or multiple role assignments to different roles, with same name.
318318
// The FilterRoleAssignments takes care of paging internally
319319
IEnumerable<PSRoleAssignment> roleAssignments = FilterRoleAssignments(options, currentSubscription: subscriptionId)
320-
.Where(ra => ra.Scope == options.Scope.TrimEnd('/'));
320+
.Where(ra => ra.Scope.Equals(options.Scope.TrimEnd('/'), StringComparison.OrdinalIgnoreCase));
321321

322322
if (roleAssignments == null || !roleAssignments.Any())
323323
{

0 commit comments

Comments
 (0)