Skip to content

Commit

Permalink
Merge pull request #5035 from darshanhs90/preview2
Browse files Browse the repository at this point in the history
add support for valid scopes ending with "/"
  • Loading branch information
maddieclayton authored Nov 29, 2017
2 parents d224327 + 831a5a2 commit 8c6d296
Show file tree
Hide file tree
Showing 22 changed files with 11,062 additions and 4,077 deletions.
2 changes: 2 additions & 0 deletions src/ResourceManager/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
## Current Release
* Fixed issue where Get-AzureRMRoleAssignment would result in a assignments without roledefiniton name for custom roles
- Users can now use Get-AzureRMRoleAssignment with assignments having roledefinition names irrespective of the type of role
* Allow scopes to end with "/"
- Users can now use RoleDefinition and RoleAssignment commandlets with scopes ending with "/" ,consistent with API and CLI

## Version 5.0.0
* Add support for online help
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void VerifyInvalidScopes()
scopeAndErrors.Add("test", "Scope 'test' should begin with '/subscriptions' or '/providers'.");
scopeAndErrors.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/Should be 'ResourceGroups'/any group name", "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/Should be 'ResourceGroups'/any group name' should begin with '/subscriptions/<subid>/resourceGroups'.");
scopeAndErrors.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups", "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups' should have even number of parts.");
scopeAndErrors.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/", "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/' should not have any empty part.");
scopeAndErrors.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/", "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups' should have even number of parts.");
scopeAndErrors.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Should be 'Providers'/any provider name", "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Should be 'Providers'/any provider name' should begin with '/subscriptions/<subid>/resourceGroups/<groupname>/providers'.");
scopeAndErrors.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Providers/providername", "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Providers/providername' should have at least one pair of resource type and resource name. e.g. '/subscriptions/<subid>/resourceGroups/<groupname>/providers/<providername>/<resourcetype>/<resourcename>'.");
foreach (var kvp in scopeAndErrors)
Expand All @@ -52,6 +52,7 @@ public void VerifyValidScopes()
validScopes.Add("/providers/providername");
validScopes.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname");
validScopes.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Providers/providername/type/typename");
validScopes.Add("/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Providers/providername/type/typename/");

foreach (var scope in validScopes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function Test-RaDeleteByPSRoleAssignment
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."

# Test
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f747531e-da33-43b9-b726-04675abf1939")
$newAssignment = New-AzureRmRoleAssignment `
-ObjectId $users[0].Id.Guid `
-RoleDefinitionName $definitionName `
Expand All @@ -95,14 +95,15 @@ function Test-RaByScope
$subscription = Get-AzureRmSubscription
$resourceGroups = Get-AzureRmResourceGroup | Select-Object -Last 1 -Wait
$scope = '/subscriptions/'+ $subscription[0].Id +'/resourceGroups/' + $resourceGroups[0].ResourceGroupName
$assignmentScope = $scope +"/"
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."

# Test
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f747531e-da33-43b9-b726-04675abf1939")
$newAssignment = New-AzureRmRoleAssignment `
-ObjectId $users[0].Id.Guid `
-RoleDefinitionName $definitionName `
-Scope $scope
-Scope $assignmentScope

# cleanup
DeleteRoleAssignment $newAssignment
Expand Down Expand Up @@ -208,7 +209,7 @@ function Test-RaValidateInputParameters ($cmdName)
Assert-Throws { &$cmdName -Scope $scope -ObjectId $groups[0].Id.Guid -RoleDefinitionName $definitionName } $invalidScope

$scope = "/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/"
$invalidScope = "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/' should not have any empty part."
$invalidScope = "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups' should have even number of parts."
Assert-Throws { &$cmdName -Scope $scope -ObjectId $groups[0].Id.Guid -RoleDefinitionName $definitionName } $invalidScope

$scope = "/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Should be 'Providers'/any provider name"
Expand All @@ -220,7 +221,7 @@ function Test-RaValidateInputParameters ($cmdName)
Assert-Throws { &$cmdName -Scope $scope -ObjectId $groups[0].Id.Guid -RoleDefinitionName $definitionName } $invalidScope

# Check if ResourceType is valid
Assert-AreEqual $resource.ResourceType "Microsoft.ServiceBus/namespaces"
Assert-AreEqual $resource.ResourceType "Microsoft.Web/sites"
$subscription = Get-AzureRmSubscription | Select-Object -Last 1 -Wait
# Below invalid resource type should not return 'Not supported api version'.
$resource.ResourceType = "Microsoft.KeyVault/"
Expand Down Expand Up @@ -326,7 +327,7 @@ function Test-RaDeletionByScope
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."

# Test
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f747531e-da33-43b9-b726-04675abf1939")
$newAssignment = New-AzureRmRoleAssignment `
-ObjectId $users[0].Id.Guid `
-RoleDefinitionName $definitionName `
Expand Down Expand Up @@ -360,7 +361,7 @@ function Test-RaDeletionByScopeAtRootScope
Assert-AreEqual 1 $users.Count "There should be at least one user to run the test."

# Test
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("fa1a4d3b-2cca-406b-8956-6b6b32377641")
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleAssignmentNames.Enqueue("f747531e-da33-43b9-b726-04675abf1939")
$newAssignment = New-AzureRmRoleAssignment `
-ObjectId $users[0].Id.Guid `
-RoleDefinitionName $definitionName `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ function Test-RoleDefinitionCreateTests
# Basic positive case - read from object
$roleDef = Get-AzureRmRoleDefinition -Name "Reader"
$roleDef.Id = $null
$roleDef.Name = "Custom Reader"
$roleDef.Name = "New Custom Reader"
$roleDef.Actions.Add("Microsoft.ClassicCompute/virtualMachines/restart/action")
$roleDef.Description = "Read, monitor and restart virtual machines"
$roleDef.AssignableScopes[0] = "/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f"

[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleDefinitionNames.Enqueue("032F61D2-ED09-40C9-8657-26A273DA7BAE")
New-AzureRmRoleDefinition -Role $roleDef
$addedRoleDef = Get-AzureRmRoleDefinition -Name "Custom Reader"
$addedRoleDef = Get-AzureRmRoleDefinition -Name "New Custom Reader"

Assert-NotNull $addedRoleDef.Actions
Assert-AreEqual $roleDef.Description $addedRoleDef.Description
Expand Down Expand Up @@ -292,7 +292,7 @@ function Test-RdValidateInputParameters ($cmdName)
Assert-Throws { &$cmdName -Scope $scope -Id D46245F8-7E18-4499-8E1F-784A6DA5BE25} $invalidScope

$scope = "/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/"
$invalidScope = "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/' should not have any empty part."
$invalidScope = "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups' should have even number of parts."
Assert-Throws { &$cmdName -Scope $scope -Id D46245F8-7E18-4499-8E1F-784A6DA5BE25} $invalidScope

$scope = "/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/groupname/Should be 'Providers'/any provider name"
Expand Down Expand Up @@ -331,7 +331,7 @@ function Test-RdValidateInputParameters2 ($cmdName)
Assert-Throws { &$cmdName -Role $roleDef } $invalidScope

$scope = "/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/"
$invalidScope = "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups/' should not have any empty part."
$invalidScope = "Scope '/subscriptions/e9ee799d-6ab2-4084-b952-e7c86344bbab/ResourceGroups' should have even number of parts."
$roleDef.AssignableScopes[0] = $scope;
Assert-Throws { &$cmdName -Role $roleDef } $invalidScope

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 8c6d296

Please sign in to comment.