Skip to content

Commit cd97c79

Browse files
authored
Merge pull request Azure#5094 from darshanhs90/preview1
Update Get role assignment calls to be scoped
2 parents e664dad + 2ecc7ff commit cd97c79

File tree

18 files changed

+9048
-4313
lines changed

18 files changed

+9048
-4313
lines changed

src/ResourceManager/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- Users can now use Set-AzureRMRoleRoleDefinition with assignable scopes including new scopes irrespective of the position of the scope
2727
* Allow scopes to end with "/"
2828
- Users can now use RoleDefinition and RoleAssignment commandlets with scopes ending with "/" ,consistent with API and CLI
29+
* Fix RoleAssignment get to respect the scope parameter
2930

3031
## Version 5.0.0
3132
* 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
@@ -712,6 +712,9 @@
712712
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaPropertiesValidation.json">
713713
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
714714
</None>
715+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleAssignmentTests\RaGetByScope.json">
716+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
717+
</None>
715718
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleDefinitionTests\RdNegativeScenarios.json">
716719
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
717720
</None>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ public void RaByUpn()
123123
ResourcesController.NewInstance.RunPsTest("Test-RaByUpn");
124124
}
125125

126+
[Fact]
127+
[Trait(Category.AcceptanceType, Category.CheckIn)]
128+
public void RaGetByScope()
129+
{
130+
ResourcesController.NewInstance.RunPsTest("Test-RaGetByScope");
131+
}
132+
126133
[Fact(Skip = "Fix the flaky test and token error and then re-record the test. Token from admin user is being used even when trying to use newly created user.")]
127134
public void RaUserPermissions()
128135
{

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,56 @@ function Test-RaPropertiesValidation
430430
VerifyRoleAssignmentDeleted $newAssignment
431431
}
432432

433+
<#
434+
.SYNOPSIS
435+
Tests verifies get of RoleAssignment by Scope
436+
#>
437+
function Test-RaGetByScope
438+
{
439+
# Setup
440+
$definitionName = 'Reader'
441+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
442+
$subscription = Get-AzureRmSubscription
443+
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 2 -Wait
444+
$scope1 = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
445+
$scope2 = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[1].ResourceGroupName
446+
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
447+
448+
# Test
449+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f747531e-da33-43b9-b726-04675abf1939")
450+
$newAssignment1 = New-AzureRmRoleAssignment `
451+
-ObjectId $users[0].Id.Guid `
452+
-RoleDefinitionName $definitionName `
453+
-Scope $scope1
454+
455+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
456+
$newAssignment2 = New-AzureRmRoleAssignment `
457+
-ObjectId $users[0].Id.Guid `
458+
-RoleDefinitionName $definitionName `
459+
-Scope $scope2
460+
461+
$ras = Get-AzureRmRoleAssignment -ObjectId $users[0].Id.Guid `
462+
-RoleDefinitionName $definitionName `
463+
-Scope $scope1
464+
465+
foreach ($assignment in $ras){
466+
Assert-NotNull $assignment
467+
Assert-NotNull $assignment.Scope
468+
Assert-AreNotEqual $assignment.Scope $scope2
469+
}
470+
# cleanup
471+
DeleteRoleAssignment $newAssignment1
472+
DeleteRoleAssignment $newAssignment2
473+
474+
# Assert
475+
Assert-NotNull $newAssignment1
476+
Assert-AreEqual $definitionName $newAssignment1.RoleDefinitionName
477+
Assert-AreEqual $scope1 $newAssignment1.Scope
478+
Assert-AreEqual $users[0].DisplayName $newAssignment1.DisplayName
479+
480+
VerifyRoleAssignmentDeleted $newAssignment1
481+
}
482+
433483
<#
434484
.SYNOPSIS
435485
Creates role assignment

0 commit comments

Comments
 (0)