Skip to content

Commit 685ceb0

Browse files
authored
Merge pull request Azure#4906 from darshanhs90/preview
Fix roleassignment properties issue
2 parents 7ff96d9 + 22cff07 commit 685ceb0

File tree

9 files changed

+3816
-333
lines changed

9 files changed

+3816
-333
lines changed

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Fixed issue where Get-AzureRMRoleAssignment would result in a assignments without roledefiniton name for custom roles
22+
- Users can now use Get-AzureRMRoleAssignment with assignments having roledefinition names irrespective of the type of role
2123

2224
## Version 5.0.0
2325
* Add support for online help

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@
709709
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaDeletionByScope.json">
710710
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
711711
</None>
712+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaPropertiesValidation.json">
713+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
714+
</None>
712715
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleDefinitionTests\RdNegativeScenarios.json">
713716
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
714717
</None>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public void RaClassicAdmins()
4444
ResourcesController.NewInstance.RunPsTest("Test-RaClassicAdmins");
4545
}
4646

47+
[Fact]
48+
[Trait(Category.AcceptanceType, Category.CheckIn)]
49+
public void RaPropertiesValidation() {
50+
ResourcesController.NewInstance.RunPsTest("Test-RaPropertiesValidation");
51+
}
52+
4753
[Fact]
4854
[Trait(Category.AcceptanceType, Category.CheckIn)]
4955
public void RaNegativeScenarios()

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,55 @@ function Test-RaDeletionByScopeAtRootScope
379379
VerifyRoleAssignmentDeleted $newAssignment
380380
}
381381

382+
<#
383+
.SYNOPSIS
384+
Tests verifies creation and validation of RoleAssignment properties for not null
385+
#>
386+
function Test-RaPropertiesValidation
387+
{
388+
# Setup
389+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
390+
$subscription = Get-AzureRmSubscription
391+
$scope = '/subscriptions/'+$subscription[0].Id
392+
$roleDef = Get-AzureRmRoleDefinition -Name "Reader"
393+
$roleDef.Id = $null
394+
$roleDef.Name = "Custom Reader Test"
395+
$roleDef.Actions.Add("Microsoft.ClassicCompute/virtualMachines/restart/action")
396+
$roleDef.Description = "Read, monitor and restart virtual machines"
397+
$roleDef.AssignableScopes[0] = "/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f"
398+
399+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleDefinitionNames.Enqueue("032F61D2-ED09-40C9-8657-26A273DA7BAE")
400+
New-AzureRmRoleDefinition -Role $roleDef
401+
$rd = Get-AzureRmRoleDefinition -Name "Custom Reader Test"
402+
403+
# Test
404+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
405+
$newAssignment = New-AzureRmRoleAssignment `
406+
-ObjectId $users[0].Id.Guid `
407+
-RoleDefinitionName $roleDef.Name `
408+
-Scope $scope
409+
$newAssignment.Scope = $scope.toUpper()
410+
411+
$assignments = Get-AzureRmRoleAssignment
412+
Assert-NotNull $assignments
413+
foreach ($assignment in $assignments){
414+
Assert-NotNull $assignment
415+
Assert-NotNull $assignment.RoleDefinitionName
416+
Assert-AreNotEqual $assignment.RoleDefinitionName ""
417+
}
418+
419+
# cleanup
420+
DeleteRoleAssignment $newAssignment
421+
Remove-AzureRmRoleDefinition -Id $rd.Id -Force
422+
423+
# Assert
424+
Assert-NotNull $newAssignment
425+
Assert-AreEqual $roleDef.Name $newAssignment.RoleDefinitionName
426+
Assert-AreEqual $scope $newAssignment.Scope
427+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
428+
429+
VerifyRoleAssignmentDeleted $newAssignment
430+
}
382431

383432
<#
384433
.SYNOPSIS

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

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

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

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

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

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

0 commit comments

Comments
 (0)