Skip to content

Commit

Permalink
Merge pull request Azure#4346 from darshanhs90/preview
Browse files Browse the repository at this point in the history
update removeroleassignment comparison to case insensitive
  • Loading branch information
cormacpayne authored Aug 3, 2017
2 parents 342f0f4 + fdddee6 commit dd1009a
Show file tree
Hide file tree
Showing 5 changed files with 2,453 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaValidateInputParameters.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaDeletionByScope.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleDefinitionTests\RdNegativeScenarios.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public void RaByServicePrincipal()
ResourcesController.NewInstance.RunPsTest("Test-RaByServicePrincipal");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaDeletionByScope()
{
ResourcesController.NewInstance.RunPsTest("Test-RaDeletionByScope");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void RaByUpn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,41 @@ function Test-RaAuthorizationChangeLog
Assert-True { $log1.Count -ge 1 } "At least one record should be returned for the user"
}

<#
.SYNOPSIS
Tests verifies creation and deletion of a RoleAssignments by Scope irrespective of the case
#>
function Test-RaDeletionByScope
{
# Setup
Add-Type -Path ".\\Microsoft.Azure.Commands.Resources.dll"

$definitionName = 'Reader'
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
$subscription = Get-AzureRmSubscription
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
$scope = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."

# Test
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
$newAssignment = New-AzureRmRoleAssignment `
-ObjectId $users[0].Id.Guid `
-RoleDefinitionName $definitionName `
-Scope $scope
$newAssignment.Scope = $scope.toUpper()

# cleanup
DeleteRoleAssignment $newAssignment

# Assert
Assert-NotNull $newAssignment
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
Assert-AreEqual $scope $newAssignment.Scope
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName

VerifyRoleAssignmentDeleted $newAssignment
}

<#
.SYNOPSIS
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public IEnumerable<PSRoleAssignment> RemoveRoleAssignment(FilterRoleAssignmentsO
// but an edge case can have multiple role assignments to the same role or multiple role assignments to different roles, with same name.
// The FilterRoleAssignments takes care of paging internally
IEnumerable<PSRoleAssignment> roleAssignments = FilterRoleAssignments(options, currentSubscription: subscriptionId)
.Where(ra => ra.Scope == options.Scope.TrimEnd('/'));
.Where(ra => ra.Scope.Equals(options.Scope.TrimEnd('/'), StringComparison.OrdinalIgnoreCase));

if (roleAssignments == null || !roleAssignments.Any())
{
Expand Down

0 comments on commit dd1009a

Please sign in to comment.