Skip to content

Commit f145ccd

Browse files
authored
Merge pull request Azure#4348 from darshanhs90/settoledeffix
update setroledef command
2 parents de1d2b3 + 4429b9f commit f145ccd

File tree

11 files changed

+678
-132
lines changed

11 files changed

+678
-132
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,9 @@
336336
<None Include="Resources\RoleDefinition.json">
337337
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
338338
</None>
339+
<None Include="Resources\InvalidRoleDefinition.json">
340+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
341+
</None>
339342
<None Include="Resources\NewRoleDefinition.json">
340343
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
341344
</None>
@@ -693,6 +696,12 @@
693696
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleDefinitionTests\RoleDefinitionCreateTests.json">
694697
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
695698
</None>
699+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleDefinitionTests\RDCreateFromFile.json">
700+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
701+
</None>
702+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.RoleDefinitionTests\RDUpdate.json">
703+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
704+
</None>
696705
<None Include="sampleTemplate.json">
697706
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
698707
</None>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Name": "Another Invalid test role",
3+
"Id": "85E460B3-89E9-48BA-9DCD-A8A99D64A674",
4+
"Description": "Test role",
5+
"Actions": [
6+
"Microsoft.Authorization/*/read",
7+
"Microsoft.Support/*"
8+
],
9+
"NotActions": [],
10+
"AssignableScopes": ["/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups"]
11+
}

src/ResourceManager/Resources/Commands.Resources.Test/Resources/RoleDefinition.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"Microsoft.Support/*"
88
],
99
"NotActions": [],
10-
"AssignableScopes": ["/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f"]
10+
"AssignableScopes": ["/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f",
11+
"/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups/rbactest"]
1112
}

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleDefinitionTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@ public void RdPositiveScenarios()
4949
ResourcesController.NewInstance.RunPsTest("Test-RDPositiveScenarios");
5050
}
5151

52-
[Fact(Skip = "Unskip after service side change")]
52+
[Fact]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
public void RDUpdate()
55+
{
56+
ResourcesController.NewInstance.RunPsTest("Test-RDUpdate");
57+
}
58+
59+
[Fact]
60+
[Trait(Category.AcceptanceType, Category.CheckIn)]
61+
public void RDCreateFromFile()
62+
{
63+
ResourcesController.NewInstance.RunPsTest("Test-RDCreateFromFile");
64+
}
65+
66+
[Fact(Skip = "Unskip after service side change")]
5367
[Trait(Category.AcceptanceType, Category.CheckIn)]
5468
public void RDRemoveScenario()
5569
{

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/RoleDefinitionTests.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,49 @@ function Test-RDPositiveScenarios
126126
Assert-Null $readRd
127127
}
128128

129+
<#
130+
.SYNOPSIS
131+
Tests verify roledefinition update with interchanged assignablescopes.
132+
#>
133+
function Test-RDUpdate
134+
{
135+
# Setup
136+
Add-Type -Path ".\\Microsoft.Azure.Commands.Resources.dll"
137+
138+
# Create a role definition with Name rdNamme.
139+
$rdName = 'Another tests role'
140+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleDefinitionNames.Enqueue("032F61D2-ED09-40C9-8657-26A273DA7BAE")
141+
$rd = New-AzureRmRoleDefinition -InputFile .\Resources\RoleDefinition.json
142+
$rd = Get-AzureRmRoleDefinition -Name $rdName
143+
144+
# Update the role definition with action that was created in the step above.
145+
$scopes = $rd.AssignableScopes | foreach { $_ }
146+
$rd.AssignableScopes.Clear()
147+
for($i = $scopes.Count - 1 ; $i -ge 0; $i--){
148+
$rd.AssignableScopes.Add($scopes[$i])
149+
}
150+
$updatedRd = Set-AzureRmRoleDefinition -Role $rd
151+
Assert-NotNull $updatedRd
152+
153+
# Cleanup
154+
$deletedRd = Remove-AzureRmRoleDefinition -Id $rd.Id -Force -PassThru
155+
Assert-AreEqual $rd.Name $deletedRd.Name
156+
}
157+
158+
<#
159+
.SYNOPSIS
160+
Tests verify roledefinition create with invalid scope.
161+
#>
162+
function Test-RDCreateFromFile
163+
{
164+
# Setup
165+
Add-Type -Path ".\\Microsoft.Azure.Commands.Resources.dll"
166+
167+
# Create a role definition with invalid assignable scopes.
168+
[Microsoft.Azure.Commands.Resources.Models.Authorization.AuthorizationClient]::RoleDefinitionNames.Enqueue("032F61D2-ED09-40C9-8657-26A273DA7BAE")
169+
$badScopeException = "Scope '/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups' should have even number of parts."
170+
Assert-Throws { $rd = New-AzureRmRoleDefinition -InputFile .\Resources\InvalidRoleDefinition.json } $badScopeException
171+
}
129172
<#
130173
.SYNOPSIS
131174
Verify positive and negative scenarios for RoleDefinition remove.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "//subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups/rbactest/providers/Microsoft.Authorization/roleDefinitions/032f61d2-ed09-40c9-8657-26a273da7bae?api-version=2015-07-01",
5+
"EncodedRequestUri": "Ly9zdWJzY3JpcHRpb25zLzQwMDRhOWZkLWQ1OGUtNDhkYy1hZWIyLTRhNGFlYzU4NjA2Zi9SZXNvdXJjZUdyb3Vwcy9yYmFjdGVzdC9wcm92aWRlcnMvTWljcm9zb2Z0LkF1dGhvcml6YXRpb24vcm9sZURlZmluaXRpb25zLzAzMmY2MWQyLWVkMDktNDBjOS04NjU3LTI2YTI3M2RhN2JhZT9hcGktdmVyc2lvbj0yMDE1LTA3LTAx",
6+
"RequestMethod": "PUT",
7+
"RequestBody": "{\r\n \"name\": \"032f61d2-ed09-40c9-8657-26a273da7bae\",\r\n \"properties\": {\r\n \"roleName\": \"Another Invalid test role\",\r\n \"description\": \"Test role\",\r\n \"type\": \"CustomRole\",\r\n \"permissions\": [\r\n {\r\n \"actions\": [\r\n \"Microsoft.Authorization/*/read\",\r\n \"Microsoft.Support/*\"\r\n ],\r\n \"notActions\": []\r\n }\r\n ],\r\n \"assignableScopes\": [\r\n \"/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups/rbactest\"\r\n ]\r\n }\r\n}",
8+
"RequestHeaders": {
9+
"Content-Type": [
10+
"application/json; charset=utf-8"
11+
],
12+
"Content-Length": [
13+
"490"
14+
],
15+
"User-Agent": [
16+
"Microsoft.Azure.Management.Authorization.AuthorizationManagementClient/2.0.0.0"
17+
]
18+
},
19+
"ResponseBody": "{\r\n \"properties\": {\r\n \"roleName\": \"Another Invalid test role\",\r\n \"type\": \"CustomRole\",\r\n \"description\": \"Test role\",\r\n \"assignableScopes\": [\r\n \"/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/ResourceGroups/rbactest\"\r\n ],\r\n \"permissions\": [\r\n {\r\n \"actions\": [\r\n \"Microsoft.Authorization/*/read\",\r\n \"Microsoft.Support/*\"\r\n ],\r\n \"notActions\": []\r\n }\r\n ],\r\n \"createdOn\": \"2017-07-26T23:48:33.1112039Z\",\r\n \"updatedOn\": \"2017-07-26T23:48:33.1112039Z\",\r\n \"createdBy\": \"f8d526a0-54eb-4941-ae69-ebf4a334d0f0\",\r\n \"updatedBy\": \"f8d526a0-54eb-4941-ae69-ebf4a334d0f0\"\r\n },\r\n \"id\": \"/subscriptions/4004a9fd-d58e-48dc-aeb2-4a4aec58606f/providers/Microsoft.Authorization/roleDefinitions/032f61d2-ed09-40c9-8657-26a273da7bae\",\r\n \"type\": \"Microsoft.Authorization/roleDefinitions\",\r\n \"name\": \"032f61d2-ed09-40c9-8657-26a273da7bae\"\r\n}",
20+
"ResponseHeaders": {
21+
"Content-Length": [
22+
"730"
23+
],
24+
"Content-Type": [
25+
"application/json; charset=utf-8"
26+
],
27+
"Expires": [
28+
"-1"
29+
],
30+
"Pragma": [
31+
"no-cache"
32+
],
33+
"x-ms-request-id": [
34+
"ff4f5807-a72d-4ea8-8ed5-8f3198f9ceb0"
35+
],
36+
"X-Content-Type-Options": [
37+
"nosniff"
38+
],
39+
"Strict-Transport-Security": [
40+
"max-age=31536000; includeSubDomains"
41+
],
42+
"x-ms-ratelimit-remaining-subscription-writes": [
43+
"1198"
44+
],
45+
"x-ms-correlation-request-id": [
46+
"4b207914-7d7f-4558-b95c-1c62035e0ea0"
47+
],
48+
"x-ms-routing-request-id": [
49+
"WESTUS2:20170726T234835Z:4b207914-7d7f-4558-b95c-1c62035e0ea0"
50+
],
51+
"Cache-Control": [
52+
"no-cache"
53+
],
54+
"Date": [
55+
"Wed, 26 Jul 2017 23:48:34 GMT"
56+
],
57+
"Set-Cookie": [
58+
"x-ms-gateway-slice=productionb; path=/; secure; HttpOnly"
59+
],
60+
"Server": [
61+
"Microsoft-IIS/8.5"
62+
],
63+
"X-Powered-By": [
64+
"ASP.NET"
65+
]
66+
},
67+
"StatusCode": 201
68+
}
69+
],
70+
"Names": {},
71+
"Variables": {
72+
"SubscriptionId": "4004a9fd-d58e-48dc-aeb2-4a4aec58606f",
73+
"TenantId": "1273adef-00a3-4086-a51a-dbcce1857d36",
74+
"Domain": "rbacclitest.onmicrosoft.com"
75+
}
76+
}

0 commit comments

Comments
 (0)