Skip to content

Commit d0c0544

Browse files
committed
fix roleassignment issues
1 parent 9b7411a commit d0c0544

File tree

6 files changed

+3459
-166
lines changed

6 files changed

+3459
-166
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
@@ -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: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,51 @@ 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+
$definitionName = 'CustomRole Tests Role'
390+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleDefinitionNames.Enqueue("8D7DD69E-9AE2-44A1-94D8-F7BC8E12645E")
391+
New-AzureRmRoleDefinition -InputFile .\Resources\NewRoleDefinition.json
392+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
393+
$subscription = Get-AzureRmSubscription
394+
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
395+
$scope = '/subscriptions/'+$subscription[0].Id
396+
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
397+
$rd = Get-AzureRmRoleDefinition -Name $definitionName
398+
399+
# Test
400+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
401+
$newAssignment = New-AzureRmRoleAssignment `
402+
-ObjectId $users[0].Id.Guid `
403+
-RoleDefinitionName $definitionName `
404+
-Scope $scope
405+
$newAssignment.Scope = $scope.toUpper()
406+
407+
$assignments = Get-AzureRmRoleAssignment
408+
Assert-NotNull $assignments
409+
foreach ($assignment in $assignments){
410+
Assert-NotNull $assignment
411+
Assert-NotNull $assignment.RoleDefinitionName
412+
Assert-AreNotEqual $assignment.RoleDefinitionName ""
413+
}
414+
415+
# cleanup
416+
DeleteRoleAssignment $newAssignment
417+
Remove-AzureRmRoleDefinition -Id $rd.Id -Force
418+
419+
# Assert
420+
Assert-NotNull $newAssignment
421+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
422+
Assert-AreEqual $scope $newAssignment.Scope
423+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
424+
425+
VerifyRoleAssignmentDeleted $newAssignment
426+
}
382427

383428
<#
384429
.SYNOPSIS

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

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

0 commit comments

Comments
 (0)