@@ -23,7 +23,7 @@ function Test-RoleDefinitionCreateTests
23
23
$rdName = ' CustomRole Tests Role'
24
24
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 8D7DD69E-9AE2-44A1-94D8-F7BC8E12645E" )
25
25
New-AzureRmRoleDefinition - InputFile .\Resources\NewRoleDefinition.json
26
-
26
+
27
27
$rd = Get-AzureRmRoleDefinition - Name $rdName
28
28
Assert-AreEqual " Test role" $rd.Description
29
29
Assert-AreEqual $true $rd.IsCustom
@@ -44,10 +44,10 @@ function Test-RoleDefinitionCreateTests
44
44
New-AzureRmRoleDefinition - Role $roleDef
45
45
$addedRoleDef = Get-AzureRmRoleDefinition - Name " New Custom Reader"
46
46
47
- Assert-NotNull $addedRoleDef.Actions
48
- Assert-AreEqual $roleDef.Description $addedRoleDef.Description
49
- Assert-AreEqual $roleDef.AssignableScopes $addedRoleDef.AssignableScopes
50
- Assert-AreEqual $true $addedRoleDef.IsCustom
47
+ Assert-NotNull $addedRoleDef.Actions
48
+ Assert-AreEqual $roleDef.Description $addedRoleDef.Description
49
+ Assert-AreEqual $roleDef.AssignableScopes $addedRoleDef.AssignableScopes
50
+ Assert-AreEqual $true $addedRoleDef.IsCustom
51
51
52
52
Remove-AzureRmRoleDefinition - Id $addedRoleDef.Id - Force
53
53
Remove-AzureRmRoleDefinition - Id $rd.Id - Force
@@ -59,15 +59,15 @@ Tests verify negative scenarios for RoleDefinitions
59
59
#>
60
60
function Test-RdNegativeScenarios
61
61
{
62
- # Setup
62
+ # Setup
63
63
# Does not throw when getting a non-existing role assignment
64
64
$rdName = ' aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
65
65
$rdNull = Get-AzureRmRoleDefinition - Name $rdName
66
66
Assert-Null $rdNull
67
67
68
68
$rdId = ' 85E460B3-89E9-48BA-9DCD-A8A99D64A674'
69
-
70
- $badIdException = " The specified role definition with ID '" + $rdId + " ' does not exist ."
69
+
70
+ $badIdException = " Cannot find role definition with id '" + $rdId + " '."
71
71
72
72
# Throws on trying to update the a role that does not exist
73
73
Assert-Throws { Set-AzureRmRoleDefinition - InputFile .\Resources\RoleDefinition.json } $badIdException
@@ -88,9 +88,10 @@ function Test-RdNegativeScenarios
88
88
89
89
# TODO add check for valid input file and valid role
90
90
91
+ $removeRoleException = " The specified role definition with ID '" + $rdId + " ' does not exist."
91
92
# Throws on trying to delete a role that does not exist
92
93
$missingSubscription = " MissingSubscription: The request did not have a provided subscription. All requests must have an associated subscription Id."
93
- Assert-Throws { Remove-AzureRmRoleDefinition - Id $rdId - Force} $badIdException
94
+ Assert-Throws { Remove-AzureRmRoleDefinition - Id $rdId - Force} $removeRoleException
94
95
}
95
96
96
97
<#
@@ -126,8 +127,6 @@ Tests verify roledefinition update with interchanged assignablescopes.
126
127
#>
127
128
function Test-RDUpdate
128
129
{
129
- # Setup
130
- Add-Type - Path " .\\Microsoft.Azure.Commands.Resources.dll"
131
130
132
131
# Create a role definition with Name rdNamme.
133
132
$rdName = ' Another tests role'
@@ -138,9 +137,10 @@ function Test-RDUpdate
138
137
# Update the role definition with action that was created in the step above.
139
138
$scopes = $rd.AssignableScopes | foreach { $_ }
140
139
$rd.AssignableScopes.Clear ()
141
- for ($i = $scopes.Count - 1 ; $i -ge 0 ; $i -- ){
142
- $rd.AssignableScopes.Add ($scopes [$i ])
143
- }
140
+ $rd.AssignableScopes.Add (' /subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/resourcegroups/AzureStackSDK' )
141
+ for ($i = $scopes.Count - 1 ; $i -ge 0 ; $i -- ){
142
+ $rd.AssignableScopes.Add ($scopes [$i ])
143
+ }
144
144
$updatedRd = Set-AzureRmRoleDefinition - Role $rd
145
145
Assert-NotNull $updatedRd
146
146
@@ -156,8 +156,6 @@ Tests verify roledefinition create with invalid scope.
156
156
function Test-RDCreateFromFile
157
157
{
158
158
# Setup
159
- Add-Type - Path " .\\Microsoft.Azure.Commands.Resources.dll"
160
-
161
159
# Create a role definition with invalid assignable scopes.
162
160
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 032F61D2-ED09-40C9-8657-26A273DA7BAE" )
163
161
$badScopeException = " Scope '/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups' should have even number of parts."
@@ -173,33 +171,33 @@ function Test-RDRemove
173
171
# Create a role definition at RG Scope.
174
172
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 65E1D983-ECF4-42D4-8C08-5B1FD6E86335" )
175
173
176
- $subscription = Get-AzureRmSubscription
177
- $resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
178
-
179
- $scope = " /subscriptions/" + $subscription [0 ].SubscriptionId
180
- $rgScope = " /subscriptions/" + $subscription [0 ].SubscriptionId + " /resourceGroups/" + $resourceGroups [0 ].ResourceGroupName
174
+ $subscription = Get-AzureRmSubscription
175
+ $resourceGroups = Get-AzureRmResourceGroup | Select-Object - Last 1 - Wait
176
+
177
+ $scope = " /subscriptions/" + $subscription [0 ].SubscriptionId
178
+ $rgScope = " /subscriptions/" + $subscription [0 ].SubscriptionId + " /resourceGroups/" + $resourceGroups [0 ].ResourceGroupName
181
179
182
- $roleDef = Get-AzureRmRoleDefinition - Name " Reader"
183
- $roleDef.Id = $null
184
- $roleDef.Name = " CustomRole123_65E1D983-ECF4-42D4-8C08-5B1FD6E86335"
185
- $roleDef.Description = " Test Remove RD"
180
+ $roleDef = Get-AzureRmRoleDefinition - Name " Reader"
181
+ $roleDef.Id = $null
182
+ $roleDef.Name = " CustomRole123_65E1D983-ECF4-42D4-8C08-5B1FD6E86335"
183
+ $roleDef.Description = " Test Remove RD"
186
184
$roleDef.AssignableScopes [0 ] = $rgScope
187
185
188
186
$Rd = New-AzureRmRoleDefinition - Role $roleDef
189
187
Assert-NotNull $Rd
190
188
191
189
192
190
# try to delete the role definition with subscription scope - should fail
193
- $badIdException = " RoleDefinitionDoesNotExist: The specified role definition with ID '" + $Rd.Id + " ' does not exist."
194
- Assert-Throws { Remove-AzureRmRoleDefinition - Id $Rd.Id - Scope $scope - Force - PassThru} $badIdException
191
+ $badIdException = " RoleDefinitionDoesNotExist: The specified role definition with ID '" + $Rd.Id + " ' does not exist."
192
+ Assert-Throws { Remove-AzureRmRoleDefinition - Id $Rd.Id - Scope $scope - Force - PassThru} $badIdException
195
193
196
- # try to delete the role definition without specifying scope (default to subscription scope) - should fail
197
- $badIdException = " RoleDefinitionDoesNotExist: The specified role definition with ID '" + $Rd.Id + " ' does not exist."
198
- Assert-Throws { Remove-AzureRmRoleDefinition - Id $Rd.Id - Scope $scope - Force - PassThru} $badIdException
194
+ # try to delete the role definition without specifying scope (default to subscription scope) - should fail
195
+ $badIdException = " RoleDefinitionDoesNotExist: The specified role definition with ID '" + $Rd.Id + " ' does not exist."
196
+ Assert-Throws { Remove-AzureRmRoleDefinition - Id $Rd.Id - Scope $scope - Force - PassThru} $badIdException
199
197
200
- # try to delete the role definition with RG scope - should succeed
201
- $deletedRd = Remove-AzureRmRoleDefinition - Id $Rd.Id - Scope $rgScope - Force - PassThru
202
- Assert-AreEqual $Rd.Name $deletedRd.Name
198
+ # try to delete the role definition with RG scope - should succeed
199
+ $deletedRd = Remove-AzureRmRoleDefinition - Id $Rd.Id - Scope $rgScope - Force - PassThru
200
+ Assert-AreEqual $Rd.Name $deletedRd.Name
203
201
}
204
202
205
203
<#
@@ -209,67 +207,67 @@ Verify positive and negative scenarios for RoleDefinition Get.
209
207
function Test-RDGet
210
208
{
211
209
# Setup
212
- $subscription = Get-AzureRmSubscription
210
+ $subscription = Get-AzureRmSubscription
213
211
214
- $resource = Get-AzureRmResource | Select-Object - Last 1 - Wait
212
+ $resource = Get-AzureRmResource | Select-Object - Last 1 - Wait
215
213
Assert-NotNull $resource " Cannot find any resource to continue test execution."
216
-
217
- $subScope = " /subscriptions/" + $subscription [0 ].SubscriptionId
218
- $rgScope = " /subscriptions/" + $subscription [0 ].SubscriptionId + " /resourceGroups/" + $resource.ResourceGroupName
219
- $resourceScope = $resource.ResourceId
220
-
214
+
215
+ $subScope = " /subscriptions/" + $subscription [0 ].SubscriptionId
216
+ $rgScope = " /subscriptions/" + $subscription [0 ].SubscriptionId + " /resourceGroups/" + $resource.ResourceGroupName
217
+ $resourceScope = $resource.ResourceId
218
+
221
219
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 99CC0F56-7395-4097-A31E-CC63874AC5EF" )
222
- $roleDef1 = Get-AzureRmRoleDefinition - Name " Reader"
223
- $roleDef1.Id = $null
224
- $roleDef1.Name = " CustomRole_99CC0F56-7395-4097-A31E-CC63874AC5EF"
225
- $roleDef1.Description = " Test Get RD"
220
+ $roleDef1 = Get-AzureRmRoleDefinition - Name " Reader"
221
+ $roleDef1.Id = $null
222
+ $roleDef1.Name = " CustomRole_99CC0F56-7395-4097-A31E-CC63874AC5EF"
223
+ $roleDef1.Description = " Test Get RD"
226
224
$roleDef1.AssignableScopes [0 ] = $subScope
227
225
228
226
$roleDefSubScope = New-AzureRmRoleDefinition - Role $roleDef1
229
227
Assert-NotNull $roleDefSubScope
230
228
231
- [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" E3CC9CD7-9D0A-47EC-8C75-07C544065220" )
232
- $roleDef1.Id = $null
233
- $roleDef1.Name = " CustomRole_E3CC9CD7-9D0A-47EC-8C75-07C544065220"
234
- $roleDef1.Description = " Test Get RD"
229
+ [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" E3CC9CD7-9D0A-47EC-8C75-07C544065220" )
230
+ $roleDef1.Id = $null
231
+ $roleDef1.Name = " CustomRole_E3CC9CD7-9D0A-47EC-8C75-07C544065220"
232
+ $roleDef1.Description = " Test Get RD"
235
233
$roleDef1.AssignableScopes [0 ] = $rgScope
236
234
237
235
$roleDefRGScope = New-AzureRmRoleDefinition - Role $roleDef1
238
236
Assert-NotNull $roleDefRGScope
239
-
240
- [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 8D2E860C-5640-4B7C-BD3C-80940C715033" )
241
- $roleDef1.Id = $null
242
- $roleDef1.Name = " CustomRole_8D2E860C-5640-4B7C-BD3C-80940C715033"
243
- $roleDef1.Description = " Test Get RD"
237
+
238
+ [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 8D2E860C-5640-4B7C-BD3C-80940C715033" )
239
+ $roleDef1.Id = $null
240
+ $roleDef1.Name = " CustomRole_8D2E860C-5640-4B7C-BD3C-80940C715033"
241
+ $roleDef1.Description = " Test Get RD"
244
242
$roleDef1.AssignableScopes [0 ] = $resourceScope
245
243
246
244
$roleDefResourceScope = New-AzureRmRoleDefinition - Role $roleDef1
247
245
Assert-NotNull $roleDefResourceScope
248
246
249
247
# try to get the role definition with subscription scope
250
- $roles1 = Get-AzureRmRoleDefinition - Scope $subScope
251
- # ## TODO: Check for only sub scope role being present
248
+ $roles1 = Get-AzureRmRoleDefinition - Scope $subScope
249
+ # ## TODO: Check for only sub scope role being present
252
250
253
- # try to get the role definition with subscription scope
254
- $roles2 = Get-AzureRmRoleDefinition - Scope $rgScope
255
- # ## TODO: Check for only sub and RG scope role being present
251
+ # try to get the role definition with subscription scope
252
+ $roles2 = Get-AzureRmRoleDefinition - Scope $rgScope
253
+ # ## TODO: Check for only sub and RG scope role being present
256
254
257
- # try to get the role definition with subscription scope
258
- $roles3 = Get-AzureRmRoleDefinition - Scope $resourceScope
259
- # ## TODO: Check for all sub, RG and resource scope role being present
255
+ # try to get the role definition with subscription scope
256
+ $roles3 = Get-AzureRmRoleDefinition - Scope $resourceScope
257
+ # ## TODO: Check for all sub, RG and resource scope role being present
260
258
261
259
262
- # delete roles
263
- $deletedRd = Remove-AzureRmRoleDefinition - Id $roleDefSubScope.Id - Scope $subScope - Force - PassThru
264
- Assert-AreEqual $roleDefSubScope.Name $deletedRd.Name
260
+ # delete roles
261
+ $deletedRd = Remove-AzureRmRoleDefinition - Id $roleDefSubScope.Id - Scope $subScope - Force - PassThru
262
+ Assert-AreEqual $roleDefSubScope.Name $deletedRd.Name
265
263
266
- # delete roles
267
- $deletedRd = Remove-AzureRmRoleDefinition - Id $roleDefRGScope.Id - Scope $rgScope - Force - PassThru
268
- Assert-AreEqual $roleDefRGScope.Name $deletedRd.Name
264
+ # delete roles
265
+ $deletedRd = Remove-AzureRmRoleDefinition - Id $roleDefRGScope.Id - Scope $rgScope - Force - PassThru
266
+ Assert-AreEqual $roleDefRGScope.Name $deletedRd.Name
269
267
270
- # delete roles
271
- $deletedRd = Remove-AzureRmRoleDefinition - Id $roleDefResourceScope.Id - Scope $resourceScope - Force - PassThru
272
- Assert-AreEqual $roleDefResourceScope.Name $deletedRd.Name
268
+ # delete roles
269
+ $deletedRd = Remove-AzureRmRoleDefinition - Id $roleDefResourceScope.Id - Scope $resourceScope - Force - PassThru
270
+ Assert-AreEqual $roleDefResourceScope.Name $deletedRd.Name
273
271
}
274
272
275
273
<#
@@ -314,9 +312,9 @@ function Test-RdValidateInputParameters2 ($cmdName)
314
312
# Setup
315
313
# Note: All below scenarios are invalid, we'll expect an exception during scope validation so the ID parameter doesn't need to be a valid one.
316
314
317
- $roleDef = Get-AzureRmRoleDefinition - Name " Reader"
318
- $roleDef.Name = " CustomRole_99CC0F56-7395-4097-A31E-CC63874AC5EF"
319
- $roleDef.Description = " Test Get RD"
315
+ $roleDef = Get-AzureRmRoleDefinition - Name " Reader"
316
+ $roleDef.Name = " CustomRole_99CC0F56-7395-4097-A31E-CC63874AC5EF"
317
+ $roleDef.Description = " Test Get RD"
320
318
321
319
# Test
322
320
# Check if Scope is valid.
0 commit comments