Skip to content

Commit 729b32f

Browse files
committed
add new test for scope comparision irrespective of case
1 parent 9007c2d commit 729b32f

File tree

3 files changed

+2449
-0
lines changed

3 files changed

+2449
-0
lines changed

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

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

96+
[Fact]
97+
[Trait(Category.AcceptanceType, Category.CheckIn)]
98+
public void RaDeletionByScope()
99+
{
100+
ResourcesController.NewInstance.RunPsTest("Test-RaDeletionByScope");
101+
}
102+
96103
[Fact]
97104
[Trait(Category.AcceptanceType, Category.CheckIn)]
98105
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
@@ -320,7 +320,41 @@ function Test-RaAuthorizationChangeLog
320320
Assert-True { $log1.Count -ge 1 } "At least one record should be returned for the user"
321321
}
322322

323+
<#
324+
.SYNOPSIS
325+
Tests verifies creation and deletion of a RoleAssignments by Scope irrespective of the case
326+
#>
327+
function Test-RaDeletionByScope
328+
{
329+
# Setup
330+
Add-Type -Path ".\\Microsoft.Azure.Commands.Resources.dll"
331+
332+
$definitionName = 'Reader'
333+
$users = Get-AzureRmADUser | Select-Object -First 1 -Wait
334+
$subscription = Get-AzureRmSubscription
335+
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
336+
$scope = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
337+
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."
338+
339+
# Test
340+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
341+
$newAssignment = New-AzureRmRoleAssignment `
342+
-ObjectId $users[0].Id.Guid `
343+
-RoleDefinitionName $definitionName `
344+
-Scope $scope
345+
$newAssignment.Scope = $scope.toUpper()
346+
347+
# cleanup
348+
DeleteRoleAssignment $newAssignment
323349

350+
# Assert
351+
Assert-NotNull $newAssignment
352+
Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
353+
Assert-AreEqual $scope $newAssignment.Scope
354+
Assert-AreEqual $users[0].DisplayName $newAssignment.DisplayName
355+
356+
VerifyRoleAssignmentDeleted $newAssignment
357+
}
324358

325359
<#
326360
.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.

0 commit comments

Comments
 (0)