@@ -18,15 +18,15 @@ Tests retrieval of classic administrators
18
18
#>
19
19
function Test-RaClassicAdmins
20
20
{
21
- # Setup
22
- $subscription = Get-AzureRmSubscription
23
-
24
- # Test
25
- $classic = Get-AzureRmRoleAssignment - IncludeClassicAdministrators | Where-Object { $_.Scope -ieq (' /subscriptions/' + $subscription [0 ].Id) -and $_.RoleDefinitionName.ToLower ().Contains(' administrator' )}
26
-
27
- # Assert
28
- Assert-NotNull $classic
29
- Assert-True { $classic.Length -ge 1 }
21
+ # Setup
22
+ $subscription = Get-AzureRmSubscription
23
+
24
+ # Test
25
+ $classic = Get-AzureRmRoleAssignment - IncludeClassicAdministrators | Where-Object { $_.Scope -ieq (' /subscriptions/' + $subscription [0 ].Id) -and $_.RoleDefinitionName.ToLower ().Contains(' administrator' )}
26
+
27
+ # Assert
28
+ Assert-NotNull $classic
29
+ Assert-True { $classic.Length -ge 1 }
30
30
}
31
31
32
32
<#
@@ -41,11 +41,11 @@ function Test-RaNegativeScenarios
41
41
# Bad OID returns zero role assignments
42
42
$badOid = ' aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
43
43
$badObjectResult = " Cannot find principal using the specified options"
44
- $assignments = Get-AzureRmRoleAssignment - ObjectId $badOid
44
+ $assignments = Get-AzureRmRoleAssignment - ObjectId $badOid
45
45
Assert-AreEqual 0 $assignments.Count
46
46
47
- # Bad OID throws if Expand Principal Groups included
48
- Assert-Throws { Get-AzureRmRoleAssignment - ObjectId $badOid - ExpandPrincipalGroups } $badObjectResult
47
+ # Bad OID throws if Expand Principal Groups included
48
+ Assert-Throws { Get-AzureRmRoleAssignment - ObjectId $badOid - ExpandPrincipalGroups } $badObjectResult
49
49
50
50
# Bad UPN
51
51
@@ -110,9 +110,9 @@ function Test-RaByScope
110
110
111
111
# Assert
112
112
Assert-NotNull $newAssignment
113
- Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
114
- Assert-AreEqual $scope $newAssignment.Scope
115
- Assert-AreEqual $users [0 ].DisplayName $newAssignment.DisplayName
113
+ Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
114
+ Assert-AreEqual $scope $newAssignment.Scope
115
+ Assert-AreEqual $users [0 ].DisplayName $newAssignment.DisplayName
116
116
117
117
VerifyRoleAssignmentDeleted $newAssignment
118
118
}
@@ -142,8 +142,8 @@ function Test-RaByResourceGroup
142
142
143
143
# Assert
144
144
Assert-NotNull $newAssignment
145
- Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
146
- Assert-AreEqual $users [0 ].DisplayName $newAssignment.DisplayName
145
+ Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
146
+ Assert-AreEqual $users [0 ].DisplayName $newAssignment.DisplayName
147
147
148
148
VerifyRoleAssignmentDeleted $newAssignment
149
149
}
@@ -177,8 +177,8 @@ function Test-RaByResource
177
177
178
178
# Assert
179
179
Assert-NotNull $newAssignment
180
- Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
181
- Assert-AreEqual $groups [0 ].DisplayName $newAssignment.DisplayName
180
+ Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
181
+ Assert-AreEqual $groups [0 ].DisplayName $newAssignment.DisplayName
182
182
183
183
VerifyRoleAssignmentDeleted $newAssignment
184
184
}
@@ -261,9 +261,9 @@ function Test-RaByServicePrincipal
261
261
262
262
# Assert
263
263
Assert-NotNull $newAssignment
264
- Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
265
- Assert-AreEqual $scope $newAssignment.Scope
266
- Assert-AreEqual $servicePrincipals [0 ].DisplayName $newAssignment.DisplayName
264
+ Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
265
+ Assert-AreEqual $scope $newAssignment.Scope
266
+ Assert-AreEqual $servicePrincipals [0 ].DisplayName $newAssignment.DisplayName
267
267
268
268
VerifyRoleAssignmentDeleted $newAssignment
269
269
}
@@ -282,7 +282,7 @@ function Test-RaByUpn
282
282
Assert-AreEqual 1 $resourceGroups.Count " No resource group found. Unable to run the test."
283
283
284
284
# Test
285
- [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleAssignmentNames.Enqueue(" f8dac632-b879-42f9-b4ab-df2aab22a149" )
285
+ [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleAssignmentNames.Enqueue(" f8dac632-b879-42f9-b4ab-df2aab22a149" )
286
286
$newAssignment = New-AzureRmRoleAssignment `
287
287
- SignInName $users [0 ].UserPrincipalName `
288
288
- RoleDefinitionName $definitionName `
@@ -293,8 +293,8 @@ function Test-RaByUpn
293
293
294
294
# Assert
295
295
Assert-NotNull $newAssignment
296
- Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
297
- Assert-AreEqual $users [0 ].DisplayName $newAssignment.DisplayName
296
+ Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
297
+ Assert-AreEqual $users [0 ].DisplayName $newAssignment.DisplayName
298
298
299
299
VerifyRoleAssignmentDeleted $newAssignment
300
300
}
@@ -305,11 +305,11 @@ function Test-RaUserPermissions
305
305
param ([string ]$rgName , [string ]$action )
306
306
# Test
307
307
$rg = Get-AzureRmResourceGroup
308
- $errorMsg = " User should have access to only 1 RG. Found: {0}" -f $rg.Count
309
- Assert-AreEqual 1 $rg.Count $errorMsg
308
+ $errorMsg = " User should have access to only 1 RG. Found: {0}" -f $rg.Count
309
+ Assert-AreEqual 1 $rg.Count $errorMsg
310
310
311
- # User should not be able to create another RG as he doesnt have access to the subscription.
312
- Assert-Throws { New-AzureRmResourceGroup - Name ' NewGroupFromTest' - Location ' WestUS' }
311
+ # User should not be able to create another RG as he doesnt have access to the subscription.
312
+ Assert-Throws { New-AzureRmResourceGroup - Name ' NewGroupFromTest' - Location ' WestUS' }
313
313
}
314
314
315
315
<#
@@ -430,6 +430,42 @@ function Test-RaPropertiesValidation
430
430
VerifyRoleAssignmentDeleted $newAssignment
431
431
}
432
432
433
+ <#
434
+ . SYNOPSIS
435
+ Tests verifies creation and retrieval of a RoleAssignments using delegation flag
436
+ #>
437
+ function Test-RaDelegation
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 1 - Wait
444
+ $scope = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
445
+ $assignmentScope = $scope + " /"
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
+ $newAssignment = New-AzureRmRoleAssignment `
451
+ - ObjectId $users [0 ].Id.Guid `
452
+ - RoleDefinitionName $definitionName `
453
+ - Scope $assignmentScope `
454
+ - AllowDelegation
455
+
456
+ # Assert
457
+ Assert-NotNull $newAssignment
458
+ Assert-AreEqual $definitionName $newAssignment.RoleDefinitionName
459
+ Assert-AreEqual $scope $newAssignment.Scope
460
+ Assert-AreEqual $users [0 ].DisplayName $newAssignment.DisplayName
461
+ Assert-AreEqual $true $newAssignment.CanDelegate
462
+
463
+ # cleanup
464
+ DeleteRoleAssignment $newAssignment
465
+
466
+ VerifyRoleAssignmentDeleted $newAssignment
467
+ }
468
+
433
469
<#
434
470
. SYNOPSIS
435
471
Tests verifies get of RoleAssignment by Scope
0 commit comments