@@ -23,7 +23,7 @@ function Test-RoleDefinitionCreateTests
2323 $rdName = ' CustomRole Tests Role'
2424 [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 8D7DD69E-9AE2-44A1-94D8-F7BC8E12645E" )
2525 New-AzureRmRoleDefinition - InputFile .\Resources\NewRoleDefinition.json
26-
26+
2727 $rd = Get-AzureRmRoleDefinition - Name $rdName
2828 Assert-AreEqual " Test role" $rd.Description
2929 Assert-AreEqual $true $rd.IsCustom
@@ -44,10 +44,10 @@ function Test-RoleDefinitionCreateTests
4444 New-AzureRmRoleDefinition - Role $roleDef
4545 $addedRoleDef = Get-AzureRmRoleDefinition - Name " New Custom Reader"
4646
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
5151
5252 Remove-AzureRmRoleDefinition - Id $addedRoleDef.Id - Force
5353 Remove-AzureRmRoleDefinition - Id $rd.Id - Force
@@ -59,15 +59,15 @@ Tests verify negative scenarios for RoleDefinitions
5959#>
6060function Test-RdNegativeScenarios
6161{
62- # Setup
62+ # Setup
6363 # Does not throw when getting a non-existing role assignment
6464 $rdName = ' aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
6565 $rdNull = Get-AzureRmRoleDefinition - Name $rdName
6666 Assert-Null $rdNull
6767
6868 $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 + " '."
7171
7272 # Throws on trying to update the a role that does not exist
7373 Assert-Throws { Set-AzureRmRoleDefinition - InputFile .\Resources\RoleDefinition.json } $badIdException
@@ -88,9 +88,10 @@ function Test-RdNegativeScenarios
8888
8989 # TODO add check for valid input file and valid role
9090
91+ $removeRoleException = " The specified role definition with ID '" + $rdId + " ' does not exist."
9192 # Throws on trying to delete a role that does not exist
9293 $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
9495}
9596
9697<#
@@ -126,8 +127,6 @@ Tests verify roledefinition update with interchanged assignablescopes.
126127#>
127128function Test-RDUpdate
128129{
129- # Setup
130- Add-Type - Path " .\\Microsoft.Azure.Commands.Resources.dll"
131130
132131 # Create a role definition with Name rdNamme.
133132 $rdName = ' Another tests role'
@@ -138,9 +137,10 @@ function Test-RDUpdate
138137 # Update the role definition with action that was created in the step above.
139138 $scopes = $rd.AssignableScopes | foreach { $_ }
140139 $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+ }
144144 $updatedRd = Set-AzureRmRoleDefinition - Role $rd
145145 Assert-NotNull $updatedRd
146146
@@ -156,8 +156,6 @@ Tests verify roledefinition create with invalid scope.
156156function Test-RDCreateFromFile
157157{
158158 # Setup
159- Add-Type - Path " .\\Microsoft.Azure.Commands.Resources.dll"
160-
161159 # Create a role definition with invalid assignable scopes.
162160 [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 032F61D2-ED09-40C9-8657-26A273DA7BAE" )
163161 $badScopeException = " Scope '/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups' should have even number of parts."
@@ -173,33 +171,33 @@ function Test-RDRemove
173171 # Create a role definition at RG Scope.
174172 [Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient ]::RoleDefinitionNames.Enqueue(" 65E1D983-ECF4-42D4-8C08-5B1FD6E86335" )
175173
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
181179
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"
186184 $roleDef.AssignableScopes [0 ] = $rgScope
187185
188186 $Rd = New-AzureRmRoleDefinition - Role $roleDef
189187 Assert-NotNull $Rd
190188
191189
192190 # 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
195193
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
199197
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
203201}
204202
205203<#
@@ -209,67 +207,67 @@ Verify positive and negative scenarios for RoleDefinition Get.
209207function Test-RDGet
210208{
211209 # Setup
212- $subscription = Get-AzureRmSubscription
210+ $subscription = Get-AzureRmSubscription
213211
214- $resource = Get-AzureRmResource | Select-Object - Last 1 - Wait
212+ $resource = Get-AzureRmResource | Select-Object - Last 1 - Wait
215213 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+
221219 [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"
226224 $roleDef1.AssignableScopes [0 ] = $subScope
227225
228226 $roleDefSubScope = New-AzureRmRoleDefinition - Role $roleDef1
229227 Assert-NotNull $roleDefSubScope
230228
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"
235233 $roleDef1.AssignableScopes [0 ] = $rgScope
236234
237235 $roleDefRGScope = New-AzureRmRoleDefinition - Role $roleDef1
238236 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"
244242 $roleDef1.AssignableScopes [0 ] = $resourceScope
245243
246244 $roleDefResourceScope = New-AzureRmRoleDefinition - Role $roleDef1
247245 Assert-NotNull $roleDefResourceScope
248246
249247 # 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
252250
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
256254
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
260258
261259
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
265263
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
269267
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
273271}
274272
275273<#
@@ -314,9 +312,9 @@ function Test-RdValidateInputParameters2 ($cmdName)
314312 # Setup
315313 # 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.
316314
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"
320318
321319 # Test
322320 # Check if Scope is valid.
0 commit comments