17
17
Tests retrieval of classic administrators
18
18
#>
19
19
function Test-RaClassicAdmins
20
+ {
21
+ # Setup
22
+ $subscription = $ (Get-AzureRmContext ).Subscription
23
+
24
+ # Test
25
+ $classic = Get-AzureRmRoleAssignment - IncludeClassicAdministrators | Where-Object { $_.Scope -ieq (' /subscriptions/' + $subscription [0 ].Id) -and $_.RoleDefinitionName -ieq ' ServiceAdministrator;AccountAdministrator' }
26
+
27
+ # Assert
28
+ Assert-NotNull $classic
29
+ Assert-True { $classic.Length -ge 1 }
30
+ }
31
+
32
+ <#
33
+ . SYNOPSIS
34
+ Tests retrieval of classic administrators with subscription scope
35
+ #>
36
+ function Test-RaClassicAdminsWithScope
20
37
{
21
38
# Setup
22
39
$subscription = Get-AzureRmSubscription
23
40
24
41
# Test
25
- $classic = Get-AzureRmRoleAssignment - IncludeClassicAdministrators | Where-Object { $_.Scope -ieq (' /subscriptions/' + $subscription [0 ].Id) -and $_.RoleDefinitionName.ToLower ().Contains(' administrator' )}
42
+ $classic = Get-AzureRmRoleAssignment - Scope (" /subscriptions/" + $subscription [0 ].Id) - IncludeClassicAdministrators | Where-Object { $_.Scope.ToLower ().Contains(" /subscriptions/" + $subscription [0 ].Id) -and $_.RoleDefinitionName -ieq ' ServiceAdministrator;AccountAdministrator' }
43
+
44
+ # Assert
45
+ Assert-NotNull $classic
46
+ Assert-True { $classic.Length -ge 1 }
47
+
48
+ # Test
49
+ $classic = Get-AzureRmRoleAssignment - Scope (" /subscriptions/" + $subscription [1 ].Id) - IncludeClassicAdministrators | Where-Object { $_.Scope.ToLower ().Contains(" /subscriptions/" + $subscription [1 ].Id) -and $_.RoleDefinitionName -ieq ' ServiceAdministrator;AccountAdministrator' }
26
50
27
51
# Assert
28
52
Assert-NotNull $classic
@@ -36,7 +60,7 @@ This test will fail if the objectId is changed or the role assignment deleted
36
60
#>
37
61
function Test-RaDeletedPrincipals
38
62
{
39
- $objectId = " 012968d8-c7a3-49b4-a00e-f3e24fec95cb "
63
+ $objectId = " 6f58a770-c06e-4012-b9f9-e5479c03d43f "
40
64
$assignment = Get-AzureRmRoleAssignment - ObjectId $objectId
41
65
Assert-NotNull $assignment
42
66
Assert-NotNull $assignment.ObjectType
@@ -52,7 +76,7 @@ Tests verifies negative scenarios for RoleAssignments
52
76
function Test-RaNegativeScenarios
53
77
{
54
78
# Setup
55
- $subscription = Get-AzureRmSubscription
79
+ $subscription = $ ( Get-AzureRmContext ).Subscription
56
80
57
81
# Bad OID returns zero role assignments
58
82
$badOid = ' aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
@@ -81,7 +105,7 @@ function Test-RaDeleteByPSRoleAssignment
81
105
# Setup
82
106
$definitionName = ' Backup Contributor'
83
107
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
84
- $subscription = Get-AzureRmSubscription
108
+ $subscription = $ ( Get-AzureRmContext ).Subscription
85
109
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
86
110
$scope = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
87
111
Assert-AreEqual 1 $users.Count " There should be at least one user to run the test."
@@ -108,7 +132,7 @@ function Test-RaByScope
108
132
# Setup
109
133
$definitionName = ' Automation Job Operator'
110
134
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
111
- $subscription = Get-AzureRmSubscription
135
+ $subscription = $ ( Get-AzureRmContext ).Subscription
112
136
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
113
137
$scope = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
114
138
$assignmentScope = $scope + " /"
@@ -142,7 +166,7 @@ function Test-RaById
142
166
# Setup
143
167
$definitionName = ' Reader'
144
168
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
145
- $subscription = Get-AzureRmSubscription
169
+ $subscription = $ ( Get-AzureRmContext ).Subscription
146
170
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - First 1 - Wait
147
171
$scope = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
148
172
$assignmentScope = $scope + " /"
@@ -276,7 +300,7 @@ function Test-RaValidateInputParameters ($cmdName)
276
300
277
301
# Check if ResourceType is valid
278
302
Assert-AreEqual $resource.ResourceType " Microsoft.Web/sites"
279
- $subscription = Get-AzureRmSubscription | Select-Object - Last 1 - Wait
303
+ $subscription = $ ( Get-AzureRmContext ).Subscription
280
304
# Below invalid resource type should not return 'Not supported api version'.
281
305
$resource.ResourceType = " Microsoft.KeyVault/"
282
306
$invalidResourceType = " Scope '/subscriptions/" + $subscription.Id + " /resourceGroups/" + $resource.ResourceGroupName + " /providers/Microsoft.KeyVault/" + $resource.Name + " ' should have even number of parts."
@@ -297,7 +321,7 @@ function Test-RaByServicePrincipal
297
321
# Setup
298
322
$definitionName = ' Web Plan Contributor'
299
323
$servicePrincipals = Get-AzureRmADServicePrincipal | Select-Object - Last 1 - Wait
300
- $subscription = Get-AzureRmSubscription
324
+ $subscription = $ ( Get-AzureRmContext ).Subscription
301
325
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
302
326
$scope = ' /subscriptions/' + $subscription [0 ].Id
303
327
Assert-AreEqual 1 $servicePrincipals.Count " No service principals found. Unable to run the test."
@@ -424,7 +448,7 @@ function Test-RaDeletionByScope
424
448
# Setup
425
449
$definitionName = ' Backup Operator'
426
450
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
427
- $subscription = Get-AzureRmSubscription
451
+ $subscription = $ ( Get-AzureRmContext ).Subscription
428
452
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
429
453
$scope = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
430
454
Assert-AreEqual 1 $users.Count " There should be at least one user to run the test."
@@ -458,7 +482,7 @@ function Test-RaDeletionByScopeAtRootScope
458
482
# Setup
459
483
$definitionName = ' Billing Reader'
460
484
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
461
- $subscription = Get-AzureRmSubscription
485
+ $subscription = $ ( Get-AzureRmContext ).Subscription
462
486
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
463
487
$scope = ' /'
464
488
Assert-AreEqual 1 $users.Count " There should be at least one user to run the test."
@@ -491,7 +515,7 @@ function Test-RaPropertiesValidation
491
515
{
492
516
# Setup
493
517
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
494
- $subscription = Get-AzureRmSubscription
518
+ $subscription = $ ( Get-AzureRmContext ).Subscription
495
519
$scope = ' /subscriptions/' + $subscription [0 ].Id
496
520
$roleDef = Get-AzureRmRoleDefinition - Name " User Access Administrator"
497
521
$roleDef.Id = $null
@@ -538,7 +562,7 @@ function Test-RaDelegation
538
562
# Setup
539
563
$definitionName = ' Automation Runbook Operator'
540
564
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
541
- $subscription = Get-AzureRmSubscription
565
+ $subscription = $ ( Get-AzureRmContext ).Subscription
542
566
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
543
567
$scope = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
544
568
$assignmentScope = $scope + " /"
@@ -574,7 +598,7 @@ function Test-RaGetByScope
574
598
# Setup
575
599
$definitionName = ' Automation Operator'
576
600
$users = Get-AzureRmADUser | Select-Object - First 1 - Wait
577
- $subscription = Get-AzureRmSubscription
601
+ $subscription = $ ( Get-AzureRmContext ).Subscription
578
602
$resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 2 - Wait
579
603
$scope1 = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [0 ].ResourceGroupName
580
604
$scope2 = ' /subscriptions/' + $subscription [0 ].Id + ' /resourceGroups/' + $resourceGroups [1 ].ResourceGroupName
0 commit comments